OkAPI meet symfony, symfony meet OkAPI
Upcoming SlideShare
Loading in...5
×
 

OkAPI meet symfony, symfony meet OkAPI

on

  • 7,494 views

The Okapi framework was initially developed by the Liip AG together for use at local.ch as thin layer mainly handling XSLT transformation and request mapping between the Java backend and the PHP based ...

The Okapi framework was initially developed by the Liip AG together for use at local.ch as thin layer mainly handling XSLT transformation and request mapping between the Java backend and the PHP based frontend. It has evolved since then but has stayed true its heritage of being the thinnest possible layer that combines various open source libraries. In this spirit the sfYaml component was integrated in version 1.1 of the framework. Okapi 2 has integrated various additional symfony components to further reduce the amount of code that has to be maintained in house, while at the same time giving Okapi a very modern architecture having adopted the event dispatcher, request handler, service container components. This sessions explains why we choose to integrate these components and how we went about implementing them and more importantly what lessons we learned along the way.

Statistics

Views

Total Views
7,494
Views on SlideShare
6,286
Embed Views
1,208

Actions

Likes
5
Downloads
79
Comments
0

18 Embeds 1,208

http://www.symfony-project.org 371
http://symfony.com 343
http://www.symfonylab.com 304
http://swik.net 126
http://www.phphatesme.com 30
http://www.slideshare.net 14
https://www.linkedin.com 3
http://www.sfexception.com 3
http://feeds.feedburner.com 2
http://www.phpframeworks.com 2
http://webcache.googleusercontent.com 2
http://www.linkedin.com 2
http://twitter.com 1
http://www.techgig.com 1
http://pt.minichiello.name 1
http://www.mefeedia.com 1
http://icy:3000 1
http://translate.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

OkAPI meet symfony, symfony meet OkAPI OkAPI meet symfony, symfony meet OkAPI Presentation Transcript

  • 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 View slide
  • 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 View slide
  • 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