SlideShare a Scribd company logo
1 of 21
Download to read offline
OkAPI meets Symfony




                   OkAPI meet symfony, symfony meet OkAPI
                   Lukas (lukas@liip.ch) | Jordi (jordi@liip.ch)
                   Symfony Live 2010 - Paris Feburary 15-17




Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Who are we?
                     We have been doing PHP quite some time
                     Involved in PEAR, Doctrine, Dwoo, Phergie,
                     Arbit, core PHP development and a bit of
                     symfony .. and a few other things
                     Liip founded 3 years ago, winning awards
                     doing SOTA PHP/Flash apps ever since
                     Don’t worry we are happy staying in
                     Switzerland :-)


Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Why OkAPI?
                     Developed internally at Liip, released as
                     OSS, but never tried to grow a community
                     Original code is quite old, written before
                     current crop of frameworks were mature
                     Designed for fat Java backend, lightweight
                     PHP/XSLT frontend architectures
                     Slowly turned into a lightweight PHP
                     framework glueing together all sorts of libs


Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   What is this about?
                     We are not here to sell OkAPI. It works for
                     us, but its not ready for the world in general
                     OkAPI2 uses most symfony components (*)
                     and we want to share our experience
                     Symfony benefits by someone testing the
                     concepts behind all the new shiny code



                     (*) OkAPI even uses a “non” component “ripped” from symfony,
                     but currently we are not using the Templating component
Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Yaml
                     First component we added as a replacement
                     for spyc into OkAPI 1.1
                     Faster, much better error reporting, but
                     missing a key feature: merge key
                     So we submitted patches, Fabien rewrote
                     them, but we now have merge key :-)




Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Merge-key rocks!
                     parameters:
                       # declare &arguments as a source
                       arguments: &arguments
                         routing: @routing
                         request: @request
                         response: @response
                         params: &params
                           debug: true
                     services:
                       api_command_hello:
                         class:     api_command_hello
                         # merge default parameters and change on the fly
                         arguments:
                           <<: *arguments
                           routing: @overrides_work
                           extra: "extra values are also allowed"
                         shared:    true



Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Step out, get burned
                     Someone did a OkAPI branch with
                     dependency injection support
                     We decided it would be better to reduce the
                     LOC to maintain/document ourselves
                     After a quick prototype integrating the
                     Service Container we were happy
                     Fabien announced the jump to 5.3, great
                     idea, but we still wanted pre 5.3 support
                     So we are back to maintaining the code :-/
Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Service Container
                     A “service” layer to assist in implementing
                     dependency injection
                     Services and their dependencies can be
                     configured via Yaml (or XML) config files
                     Service Container generates a PHP class that
                     can make instances of any of the services
                     Big question:
                     How does the controller get
                     access to the services?
Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   General comments
                     Object creation needs to be cheap, lazy load
                     resources as much as possible
                     Get rid of the idea of a “flat config file”,
                     instead pass everything to the constructor
                     Use parameters to reuse settings across
                     multiple services
                     Use import to structure configs
                     Do not pass around the SC,
                     if necessary use multiple SC’s
Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   DI Frontcontroller
                     <?php

                     // load the init routine
                     require_once dirname(__FILE__).'/../inc/api/init.php';
                     $sc = api_init::createServiceContainer();

                     // load the controller
                     $ctrl = $sc->controller;
                     $ctrl->setServiceContainer($sc);

                     // let the controller load the modules
                     // which in turn load the model and view
                     $ctrl->run()->send();




Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Command (“action”)
                     abstract class api_command {
                         public function __construct($routing, $request, $response, $params) {
                             $this->routing = $routing;
                             $this->route = $routing->getRoute();
                             $this->request = $request;
                             $this->response = $response;
                             $this->params = $params;
                             $this->response->command = $this;
                             $this->response->getDataCallback = array($this, 'getData');
                             $this->command = api_helpers_class::getBaseName($this);
                         }
                         public function process() {
                             $route = $this->route->getParams();
                             $method = isset($route['method'])
                                 ? $method = 'execute'.ucfirst($route['method']) : null;

                             if (empty($method)
                                  || !is_callable(array($this, $method))
                             ) {
                                 throw new api_exception('Incorrect method name’);
                             }

                             $this->$method();
                             return $this->response;
Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Development Config
                     imports:
                       - { resource: default.yml, class: sfServiceContainerLoaderFileYaml }
                     parameters:
                       outputCaching: false
                       debug: true
                     services:
                       writer:
                         class:      Zend_Log_Writer_apiFirebug
                         arguments: []
                         shared:     true
                       logger:
                         class:      Zend_Log
                         arguments: [@writer]
                         shared:     true
                       log:
                         class:      api_log
                         arguments: [@logger, DEBUG, true]
                         shared:     true
                       solrClientSearch:
                         class:      api_solrClient
                         arguments:
                            options:
                              hostname: localhost
                              port: 8983
                              path: %solrPathSearch%
                     #      optional dependencies not yet supported in pre 5.3
                            log: @log
                         shared:     true
Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Request Handler
                     100 LOC class using the Event component
                     Fires request, controller, view events to
                     structure your request handling
                     Featured in some of Fabien’s slide sets, it
                     has not yet been officially released
                     Obviously Event component can
                     also be used inside filters and
                     commands to handle custom events


Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Filters using Event
                     services:
                       filter_language:
                         class:     api_filter_language
                         arguments: [@request, @response]
                         shared:    true
                       controller:
                         class:     api_controller
                         arguments:
                           # [...]
                           events:
                             application.request:
                                controller:
                                  service: controller
                                  method: request
                                language:
                                  service: @filter_language
                                  method: request

Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Example filter
                     class api_filter_language {
                         public function __construct($request, $response) {
                             $this->request = $request;
                             $this->response = $response;
                         }

                             public function request(sfEvent $event) {
                                 if ($this->request->getLangDefaultUsed()
                                     || $this->request->getParam('lang')
                                 ) {
                                     $url = $this->request->getUrl();
                                     $host = $this->request->getHost();
                                     $languages = $this->request->getLanguages();
                                     // [...]
                                     $this->response->setCookie('lang', $lang, $_SERVER
                                                       ['REQUEST_TIME'] + 86400*365*5, '/');
                                     // [...]
                                     $this->response->redirect($url);
                                 }
                                 return true;
                             }
                     }

Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Routing
                     Our own routing component didn't have
                     route generation
                     Integrating sfRouting took a couple hours
                     More features, less maintenance, some docs
                     Wrapping it means our route definition
                     didn't change much




Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Routing
                     // before
                     $m->route('/api/chk/*url')->config(
                         array(
                             'command'=>'liipto',
                             'method' => 'checkCode',
                             'view' => array('class' => 'json')
                         )
                     );

                     // after
                     $routing->route('chk', '/api/chk/:url',
                         array(
                              'command'=>'liipto',
                              'method' => 'checkCode',
                              'view' => array('class' => 'json')
                         )
                     );

Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Classes loaded
                     Example command:       Symfony classes:
                     api_command_hello      sfEventDispatcher
                                            sfPatternRouting
                     OkAPI classes:         sfRequestHandler
                     api_command            sfRoute
                     api_controller         sfRouting
                     api_helpers_class      sfServiceContainer
                     api_helpers_string     sfServiceContainerBuilder
                     api_init               sfServiceContainerDumper
                     api_request            sfServiceContainerDumperInterface
                     api_response           sfServiceContainerDumperPhp
                     api_routing            sfServiceContainerInterface
                     api_routing_route      sfServiceContainerLoader
                     api_routingcontainer   sfServiceContainerLoaderFile
                     api_views_common       sfServiceContainerLoaderFileYaml
                     api_views_php          sfServiceContainerLoaderInterface
                                            sfServiceDefinition
                                            sfServiceReference
                                            sfYaml

Mittwoch, 17. Februar 2010
OkAPI meets Symfony




                   Merci! Questions?
                   Thank you for listening.



                   Lukas (lukas@liip.ch) | Jordi (jordi@liip.ch)

                   http://joind.in/talk/view/1410




Mittwoch, 17. Februar 2010
OkAPI meets Symfony




                   While you are listening
                   Structured database of UN resolutions:
                   http://code.google.com/p/uninformed/

                   Google map app for DJ’s around the world:
                   http://code.google.com/p/djtt/wiki/worldmap

                   Dwoo (at least as good as Twig):
                   http://dwoo.org/

                   PHP Issue tracker with Continuous Integration:
                   http://arbitracker.org
Mittwoch, 17. Februar 2010
OkAPI meets Symfony

                   Resources
                     http://okapi.liip.ch/
                     http://svn.liip.ch/repos/public/okapi2/
                     http://components.symfony-project.org/




Mittwoch, 17. Februar 2010

More Related Content

What's hot

Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHPNick Belhomme
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?Nick Belhomme
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Componentsguest0de7c2
 
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...frank2
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
Learning Puppet Chapter 1
Learning Puppet Chapter 1Learning Puppet Chapter 1
Learning Puppet Chapter 1Vishal Biyani
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)Win Yu
 
PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer. Haim Michael
 
Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)Vyacheslav Matyukhin
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Jesus Manuel Olivas
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction PresentationNerd Tzanetopoulos
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiJérémy Derussé
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012rivierarb
 
Import this, that, and the other thing: custom importers
Import this, that, and the other thing: custom importersImport this, that, and the other thing: custom importers
Import this, that, and the other thing: custom importersZoom Quiet
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package developmentTihomir Opačić
 
eZ publish 5[-alpha1] Introduction & Architecture
eZ publish 5[-alpha1] Introduction & ArchitectureeZ publish 5[-alpha1] Introduction & Architecture
eZ publish 5[-alpha1] Introduction & ArchitectureAndré Rømcke
 
An Introduction to SPL, the Standard PHP Library
An Introduction to SPL, the Standard PHP LibraryAn Introduction to SPL, the Standard PHP Library
An Introduction to SPL, the Standard PHP LibraryRobin Fernandes
 

What's hot (18)

Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
 
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...
Binary Obfuscation from the Top Down: Obfuscation Executables without Writing...
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Learning Puppet Chapter 1
Learning Puppet Chapter 1Learning Puppet Chapter 1
Learning Puppet Chapter 1
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)
 
PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer.
 
Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
 
Import this, that, and the other thing: custom importers
Import this, that, and the other thing: custom importersImport this, that, and the other thing: custom importers
Import this, that, and the other thing: custom importers
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package development
 
eZ publish 5[-alpha1] Introduction & Architecture
eZ publish 5[-alpha1] Introduction & ArchitectureeZ publish 5[-alpha1] Introduction & Architecture
eZ publish 5[-alpha1] Introduction & Architecture
 
An Introduction to SPL, the Standard PHP Library
An Introduction to SPL, the Standard PHP LibraryAn Introduction to SPL, the Standard PHP Library
An Introduction to SPL, the Standard PHP Library
 

Viewers also liked

Plugins And Making Your Own
Plugins And Making Your OwnPlugins And Making Your Own
Plugins And Making Your OwnLambert Beekhuis
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2Hugo Hamon
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010Fabien Potencier
 
What Symfony Has To Do With My Garage - Home Automation With PHP
What Symfony Has To Do With My Garage - Home Automation With PHPWhat Symfony Has To Do With My Garage - Home Automation With PHP
What Symfony Has To Do With My Garage - Home Automation With PHPJan Unger
 
PHP, Cloud And Microsoft Symfony Live 2010
PHP,  Cloud And  Microsoft    Symfony  Live 2010PHP,  Cloud And  Microsoft    Symfony  Live 2010
PHP, Cloud And Microsoft Symfony Live 2010guest5a7126
 
Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)Fabien Potencier
 
Decoupling Content Management with Create.js and PHPCR
Decoupling Content Management with Create.js and PHPCRDecoupling Content Management with Create.js and PHPCR
Decoupling Content Management with Create.js and PHPCRHenri Bergius
 
How to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross ApplicationHow to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross ApplicationMike Taylor
 
Apostrophe
ApostropheApostrophe
Apostrophetompunk
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationJonathan Wage
 
Doctrine in the Real World
Doctrine in the Real WorldDoctrine in the Real World
Doctrine in the Real WorldJonathan Wage
 
Doctrine Php Object Relational Mapper
Doctrine Php Object Relational MapperDoctrine Php Object Relational Mapper
Doctrine Php Object Relational Mapperguesta3af58
 

Viewers also liked (20)

Plugins And Making Your Own
Plugins And Making Your OwnPlugins And Making Your Own
Plugins And Making Your Own
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010
 
Debugging With Symfony
Debugging With SymfonyDebugging With Symfony
Debugging With Symfony
 
What Symfony Has To Do With My Garage - Home Automation With PHP
What Symfony Has To Do With My Garage - Home Automation With PHPWhat Symfony Has To Do With My Garage - Home Automation With PHP
What Symfony Has To Do With My Garage - Home Automation With PHP
 
The new form framework
The new form frameworkThe new form framework
The new form framework
 
PHP, Cloud And Microsoft Symfony Live 2010
PHP,  Cloud And  Microsoft    Symfony  Live 2010PHP,  Cloud And  Microsoft    Symfony  Live 2010
PHP, Cloud And Microsoft Symfony Live 2010
 
Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)
 
Decoupling Content Management with Create.js and PHPCR
Decoupling Content Management with Create.js and PHPCRDecoupling Content Management with Create.js and PHPCR
Decoupling Content Management with Create.js and PHPCR
 
Symfony Internals
Symfony InternalsSymfony Internals
Symfony Internals
 
Symfony in the Cloud
Symfony in the CloudSymfony in the Cloud
Symfony in the Cloud
 
How to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross ApplicationHow to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross Application
 
Apostrophe
ApostropheApostrophe
Apostrophe
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
 
Doctrine in the Real World
Doctrine in the Real WorldDoctrine in the Real World
Doctrine in the Real World
 
Developing for Developers
Developing for DevelopersDeveloping for Developers
Developing for Developers
 
Doctrine Php Object Relational Mapper
Doctrine Php Object Relational MapperDoctrine Php Object Relational Mapper
Doctrine Php Object Relational Mapper
 
Symfony and eZ Publish
Symfony and eZ PublishSymfony and eZ Publish
Symfony and eZ Publish
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
Symfony2 your way
Symfony2   your waySymfony2   your way
Symfony2 your way
 

Similar to OkAPI meet symfony, symfony meet OkAPI

How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)Matthias Noback
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My LifeMatthias Noback
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkRyan Weaver
 
Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fwdays
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Fabien Potencier
 
25 Intro to Symfony #burningkeyboards
25 Intro to Symfony #burningkeyboards25 Intro to Symfony #burningkeyboards
25 Intro to Symfony #burningkeyboardsDenis Ristic
 
Symfony Nano Framework
Symfony Nano FrameworkSymfony Nano Framework
Symfony Nano FrameworkLoïc Faugeron
 
The use of Symfony2 @ Overblog
The use of Symfony2 @ OverblogThe use of Symfony2 @ Overblog
The use of Symfony2 @ OverblogXavier Hausherr
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7Wim Godden
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016Codemotion
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureCloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureHabeeb Rahman
 
Welcome to the Symfony2 World - FOSDEM 2013
 Welcome to the Symfony2 World - FOSDEM 2013 Welcome to the Symfony2 World - FOSDEM 2013
Welcome to the Symfony2 World - FOSDEM 2013Lukas Smith
 
Posh Devcon2009
Posh Devcon2009Posh Devcon2009
Posh Devcon2009db82407
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterHaehnchen
 

Similar to OkAPI meet symfony, symfony meet OkAPI (20)

Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3
 
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My Life
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 Framework
 
Symfony 4 & Flex news
Symfony 4 & Flex newsSymfony 4 & Flex news
Symfony 4 & Flex news
 
Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009
 
25 Intro to Symfony #burningkeyboards
25 Intro to Symfony #burningkeyboards25 Intro to Symfony #burningkeyboards
25 Intro to Symfony #burningkeyboards
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Symfony Nano Framework
Symfony Nano FrameworkSymfony Nano Framework
Symfony Nano Framework
 
Sf2 wtf
Sf2 wtfSf2 wtf
Sf2 wtf
 
Concurrency in ruby
Concurrency in rubyConcurrency in ruby
Concurrency in ruby
 
The use of Symfony2 @ Overblog
The use of Symfony2 @ OverblogThe use of Symfony2 @ Overblog
The use of Symfony2 @ Overblog
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureCloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
 
Welcome to the Symfony2 World - FOSDEM 2013
 Welcome to the Symfony2 World - FOSDEM 2013 Welcome to the Symfony2 World - FOSDEM 2013
Welcome to the Symfony2 World - FOSDEM 2013
 
Posh Devcon2009
Posh Devcon2009Posh Devcon2009
Posh Devcon2009
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 

OkAPI meet symfony, symfony meet OkAPI

  • 1. OkAPI meets Symfony OkAPI meet symfony, symfony meet OkAPI Lukas (lukas@liip.ch) | Jordi (jordi@liip.ch) Symfony Live 2010 - Paris Feburary 15-17 Mittwoch, 17. Februar 2010
  • 2. OkAPI meets Symfony Who are we? We have been doing PHP quite some time Involved in PEAR, Doctrine, Dwoo, Phergie, Arbit, core PHP development and a bit of symfony .. and a few other things Liip founded 3 years ago, winning awards doing SOTA PHP/Flash apps ever since Don’t worry we are happy staying in Switzerland :-) Mittwoch, 17. Februar 2010
  • 3. OkAPI meets Symfony Why OkAPI? Developed internally at Liip, released as OSS, but never tried to grow a community Original code is quite old, written before current crop of frameworks were mature Designed for fat Java backend, lightweight PHP/XSLT frontend architectures Slowly turned into a lightweight PHP framework glueing together all sorts of libs Mittwoch, 17. Februar 2010
  • 4. OkAPI meets Symfony What is this about? We are not here to sell OkAPI. It works for us, but its not ready for the world in general OkAPI2 uses most symfony components (*) and we want to share our experience Symfony benefits by someone testing the concepts behind all the new shiny code (*) OkAPI even uses a “non” component “ripped” from symfony, but currently we are not using the Templating component Mittwoch, 17. Februar 2010
  • 5. OkAPI meets Symfony Yaml First component we added as a replacement for spyc into OkAPI 1.1 Faster, much better error reporting, but missing a key feature: merge key So we submitted patches, Fabien rewrote them, but we now have merge key :-) Mittwoch, 17. Februar 2010
  • 6. OkAPI meets Symfony Merge-key rocks! parameters: # declare &arguments as a source arguments: &arguments routing: @routing request: @request response: @response params: &params debug: true services: api_command_hello: class: api_command_hello # merge default parameters and change on the fly arguments: <<: *arguments routing: @overrides_work extra: "extra values are also allowed" shared: true Mittwoch, 17. Februar 2010
  • 7. OkAPI meets Symfony Step out, get burned Someone did a OkAPI branch with dependency injection support We decided it would be better to reduce the LOC to maintain/document ourselves After a quick prototype integrating the Service Container we were happy Fabien announced the jump to 5.3, great idea, but we still wanted pre 5.3 support So we are back to maintaining the code :-/ Mittwoch, 17. Februar 2010
  • 8. OkAPI meets Symfony Service Container A “service” layer to assist in implementing dependency injection Services and their dependencies can be configured via Yaml (or XML) config files Service Container generates a PHP class that can make instances of any of the services Big question: How does the controller get access to the services? Mittwoch, 17. Februar 2010
  • 9. OkAPI meets Symfony General comments Object creation needs to be cheap, lazy load resources as much as possible Get rid of the idea of a “flat config file”, instead pass everything to the constructor Use parameters to reuse settings across multiple services Use import to structure configs Do not pass around the SC, if necessary use multiple SC’s Mittwoch, 17. Februar 2010
  • 10. OkAPI meets Symfony DI Frontcontroller <?php // load the init routine require_once dirname(__FILE__).'/../inc/api/init.php'; $sc = api_init::createServiceContainer(); // load the controller $ctrl = $sc->controller; $ctrl->setServiceContainer($sc); // let the controller load the modules // which in turn load the model and view $ctrl->run()->send(); Mittwoch, 17. Februar 2010
  • 11. OkAPI meets Symfony Command (“action”) abstract class api_command { public function __construct($routing, $request, $response, $params) { $this->routing = $routing; $this->route = $routing->getRoute(); $this->request = $request; $this->response = $response; $this->params = $params; $this->response->command = $this; $this->response->getDataCallback = array($this, 'getData'); $this->command = api_helpers_class::getBaseName($this); } public function process() { $route = $this->route->getParams(); $method = isset($route['method']) ? $method = 'execute'.ucfirst($route['method']) : null; if (empty($method) || !is_callable(array($this, $method)) ) { throw new api_exception('Incorrect method name’); } $this->$method(); return $this->response; Mittwoch, 17. Februar 2010
  • 12. OkAPI meets Symfony Development Config imports: - { resource: default.yml, class: sfServiceContainerLoaderFileYaml } parameters: outputCaching: false debug: true services: writer: class: Zend_Log_Writer_apiFirebug arguments: [] shared: true logger: class: Zend_Log arguments: [@writer] shared: true log: class: api_log arguments: [@logger, DEBUG, true] shared: true solrClientSearch: class: api_solrClient arguments: options: hostname: localhost port: 8983 path: %solrPathSearch% # optional dependencies not yet supported in pre 5.3 log: @log shared: true Mittwoch, 17. Februar 2010
  • 13. OkAPI meets Symfony Request Handler 100 LOC class using the Event component Fires request, controller, view events to structure your request handling Featured in some of Fabien’s slide sets, it has not yet been officially released Obviously Event component can also be used inside filters and commands to handle custom events Mittwoch, 17. Februar 2010
  • 14. OkAPI meets Symfony Filters using Event services: filter_language: class: api_filter_language arguments: [@request, @response] shared: true controller: class: api_controller arguments: # [...] events: application.request: controller: service: controller method: request language: service: @filter_language method: request Mittwoch, 17. Februar 2010
  • 15. OkAPI meets Symfony Example filter class api_filter_language { public function __construct($request, $response) { $this->request = $request; $this->response = $response; } public function request(sfEvent $event) { if ($this->request->getLangDefaultUsed() || $this->request->getParam('lang') ) { $url = $this->request->getUrl(); $host = $this->request->getHost(); $languages = $this->request->getLanguages(); // [...] $this->response->setCookie('lang', $lang, $_SERVER ['REQUEST_TIME'] + 86400*365*5, '/'); // [...] $this->response->redirect($url); } return true; } } Mittwoch, 17. Februar 2010
  • 16. OkAPI meets Symfony Routing Our own routing component didn't have route generation Integrating sfRouting took a couple hours More features, less maintenance, some docs Wrapping it means our route definition didn't change much Mittwoch, 17. Februar 2010
  • 17. OkAPI meets Symfony Routing // before $m->route('/api/chk/*url')->config( array( 'command'=>'liipto', 'method' => 'checkCode', 'view' => array('class' => 'json') ) ); // after $routing->route('chk', '/api/chk/:url', array( 'command'=>'liipto', 'method' => 'checkCode', 'view' => array('class' => 'json') ) ); Mittwoch, 17. Februar 2010
  • 18. OkAPI meets Symfony Classes loaded Example command: Symfony classes: api_command_hello sfEventDispatcher sfPatternRouting OkAPI classes: sfRequestHandler api_command sfRoute api_controller sfRouting api_helpers_class sfServiceContainer api_helpers_string sfServiceContainerBuilder api_init sfServiceContainerDumper api_request sfServiceContainerDumperInterface api_response sfServiceContainerDumperPhp api_routing sfServiceContainerInterface api_routing_route sfServiceContainerLoader api_routingcontainer sfServiceContainerLoaderFile api_views_common sfServiceContainerLoaderFileYaml api_views_php sfServiceContainerLoaderInterface sfServiceDefinition sfServiceReference sfYaml Mittwoch, 17. Februar 2010
  • 19. OkAPI meets Symfony Merci! Questions? Thank you for listening. Lukas (lukas@liip.ch) | Jordi (jordi@liip.ch) http://joind.in/talk/view/1410 Mittwoch, 17. Februar 2010
  • 20. OkAPI meets Symfony While you are listening Structured database of UN resolutions: http://code.google.com/p/uninformed/ Google map app for DJ’s around the world: http://code.google.com/p/djtt/wiki/worldmap Dwoo (at least as good as Twig): http://dwoo.org/ PHP Issue tracker with Continuous Integration: http://arbitracker.org Mittwoch, 17. Februar 2010
  • 21. OkAPI meets Symfony Resources http://okapi.liip.ch/ http://svn.liip.ch/repos/public/okapi2/ http://components.symfony-project.org/ Mittwoch, 17. Februar 2010