Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Drupal 8 and Symfony 2

Drupal 8 and Symfony 2

About Symfony 2 components being integrated into Drupal 8 core. What this means for Drupal and Symfony.

Mark Shropshire

October 03, 2012
Tweet

More Decks by Mark Shropshire

Other Decks in Technology

Transcript

  1. About Symfony2 • A PHP framework • OOP • MVC

    • Growing to a strong a community
  2. Why Symfony2 • Tools to build a framework • Embrace

    PIE (proudly invented elsewhere) instead of NIH (not invented here) • Drupal needs to become a REST services based system • Some Drupal devs preferred the structure of Symfony • Lead Symfony devs helped directly in the Drupal issue queues
  3. Components included HTTPFoundation
 In PHP, the request is represented by

    some global variables ($_GET, $_POST, $_FILE, $_COOKIE,$_SESSION, ...) and the response is generated by some functions (echo, header, setcookie, ...). The Symfony2 HttpFoundation component replaces these default PHP global variables and functions by an Object-Oriented layer. Ref: http://symfony.com/doc/current/components/index.html
  4. Components included HTTPKernel
 On top of HttpFoundation is the HttpKernel

    component. HttpKernel handles the dynamic part of HTTP; it is a thin wrapper on top of the Request and Response classes to standardize the way requests are handled. It also provides extension points and tools that makes it the ideal starting point to create a Web framework without too much overhead. It also optionally adds configurability and extensibility, thanks to the Dependency Injection component and a powerful plugin system (bundles). Ref: http://symfony.com/doc/current/components/index.html
  5. Components included Event Dispatcher
 Objected Oriented code has gone a

    long way to ensuring code extensibility. By creating classes that have well defined responsibilities, your code becomes more flexible and a developer can extend them with subclasses to modify their behaviors. But if he wants to share his changes with other developers who have also made their own subclasses, code inheritance is no longer the answer. Consider the real-world example where you want to provide a plugin system for your project. A plugin should be able to add methods, or do something before or after a method is executed, without interfering with other plugins. This is not an easy problem to solve with single inheritance, and multiple inheritance (were it possible with PHP) has its own drawbacks. Ref: http://symfony.com/doc/current/components/index.html
  6. Components included Routing
 The Routing Component maps an HTTP request

    to a set of configuration variables. Ref: http://symfony.com/doc/current/components/index.html
  7. Twig • Twig is a modern template engine for PHP

    • Fast: Twig compiles templates down to plain optimized PHP code. The overhead compared to regular PHP code was reduced to the very minimum. • Secure: Twig has a sandbox mode to evaluate untrusted template code. This allows Twig to be used as a template language for applications where users may modify the template design. • Flexible: Twig is powered by a flexible lexer and parser. This allows the developer to define its own custom tags and filters, and create its own DSL. • Ref: http://twig.sensiolabs.org/
  8. Future • Drupal devs to continue contributing back to Symfony

    • Continue to consider more components which may work well in Drupal • More OOP and less procedural • Composer (http://getcomposer.org/)