Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
THEODO20/09/2013 1
Wrapping PHP in Symfony2
Integrating Drupal8 into Symfony2
THEODO20/09/2013 2
When Drupal8startedrockingthe PHP world
The technical challenges of PHP wrapping
Integrating Drupal8 in...
THEODO20/09/2013 3
Drupal usage isgrowing 2x fasterthanWordpress
Drupal’s position in the CMS landscape
• Drupalisused by ...
THEODO20/09/2013 4
Drupalpowersmanyinfluentialwebsites
Drupal’s position in the CMS landscape
THEODO20/09/2013 5
Drupalpowersmanyinfluentialwebsites
Drupal’s position in the CMS landscape
THEODO20/09/2013 6
Drupal 8 is due thisyearaftertwoyears of hard work
The new Drupal version
THEODO20/09/2013 7
Drupal 8 is due thisyearaftertwoyears of hard work
The new Drupal version
• 7 core initiatives organize...
THEODO20/09/2013 8
Drupal 8 wants to become a content management platform
The web service core initiative
THEODO20/09/2013 9
So Larry started looking for a good Request/Response library
to include in the Web Services core initia...
THEODO20/09/2013 10
…and thatiswhenStofchanged the PHP world
How Drupal chose Symfony2
« And thenthis French guyStofspenth...
THEODO20/09/2013 11
Sincethen Symfony2 istakingover Drupal 8
Symfony2 components adopted by Drupal 8
THEODO20/09/2013 12
Sincethen Symfony2 istakingover Drupal 8
Drufony
THEODO20/09/2013 13
16 000 additionalcontributors to Symfony2!
The power of the Drupalcommunity
THEODO20/09/2013 14
When Drupal8startedrocking the PHP world
The technical challenges of PHP wrapping
Integrating Drupal8 ...
THEODO20/09/2013 15
Why is wrapping not as easy as include?
Challenges behindPHP wrapping
THEODO20/09/2013 16
PHP is designed around « one request <-> one process »
Challenges behindPHP wrapping
The consequences ...
THEODO20/09/2013 17
Catching the output
THEODO20/09/2013 18
Catching the exits
THEODO20/09/2013 19
Handling globals
THEODO20/09/2013 20
Class and functionconflicts
History of PHP applications
• Write a custom autoloader for classes
• And ...
THEODO20/09/2013 21
Handling session alreadystarted
History of PHP applications
THEODO20/09/2013 22
When Drupal8startedrocking the PHP world
The technical challenges of PHP wrapping
Integrating Drupal8 ...
THEODO20/09/2013 23
A big picture of how a request is handled by Drupal 8
Drupal 8 architecture
The startis (almost) likeS...
THEODO20/09/2013 24
A big picture of how a request is handled by Drupal 8
Drupal 8 architecture
Authentication
• ishandled...
THEODO20/09/2013 25
A big picture of how a request is handled by Drupal 8
Drupal 8 architecture
THEODO20/09/2013 26
A big picture of how a request is handled by Drupal 8
Drupal 8 architecture
Routing
• Is handled by th...
THEODO20/09/2013 27
A big picture of how a request is handled by Drupal 8
Drupal 8 architecture
THEODO20/09/2013 28
Let’s start to hack!
Integration plan
Goals
• #1: WrapDrupal in Symfony2
• #2: Access Drupalnodes and ...
THEODO20/09/2013 29
Routingbetween Symfony2 and Drupal
TheodoDrupal8BundleRouterListener
THEODO20/09/2013 30
Routingbetween Symfony2 and Drupal
TheodoDrupal8BundleRouterListener
THEODO20/09/2013 31
Routingbetween Symfony2 and Drupal
TheodoDrupal8BundleRouterListener
THEODO20/09/2013 32
Buffering the kernel
TheodoDrupal8BundleRouterListener
THEODO20/09/2013 33
Cannotredeclareassetic_init()
Class loading issues
THEODO20/09/2013 34
Cannotredeclareassetic_init()
Class loading issues
THEODO20/09/2013 35
Cannotredeclareassetic_init()
Class loading issues
THEODO20/09/2013 36
Symlinks to whatDrupalexpects to be in web root
Assets and symlinks
Symbolic links to modules, profile...
THEODO20/09/2013 37
Change Drupal settings accordingly
Assets and symlinks
THEODO20/09/2013 38
http://sf2drupal/app_dev.php/user works!
Routingdemo
Symfony’s debug toolbar!
Drupal’s new responsive ...
THEODO20/09/2013 39
There isstill a bug in the Symfony profiler…
RequestDataCollector bug
THEODO20/09/2013 40
Corrected in a PULL REQUEST!
RequestDataCollector bug
THEODO20/09/2013 41
Accessevery service fromcore.services.yml
Drupal Service Container
THEODO20/09/2013 42
For example: accessing node content
getNode
THEODO20/09/2013 43
Getting the Drupal connected user
getCurrentUser
THEODO20/09/2013 44
Integrating Drupal 8 into Symfony2
DemoController
THEODO20/09/2013 45
Integrating Drupal 8 into Symfony2!
DemoController
Node content!
Current user name!
THEODO20/09/2013 46
How to do this at home
TheodoDrupal8bundle
https://github.com/theodo/TheodoDrupal8Bundle
THEODO20/09/2013 47
Tips to help you continue integrating
PHP integration
• Good IDE + Xdebug to follow the code
• Put a b...
THEODO20/09/2013 48
What are the next priorities
Nextsteps
• Integration must bringease of adding custom logic in
Symfonyc...
THEODO20/09/2013 49
Questions ?
fabriceb@theodo.fr
@theodo
www.theodo.fr
Feedback: https://joind.in/9329
Upcoming SlideShare
Loading in …5
×

Integrating Drupal 8 into Symfony 2

9,993 views

Published on

Drupal 8 is now introducing more and more Symfony2 components into its architecture. This will make it possible to use Symfony2 paradigms when building custom modules in Drupal 8. But what if you want to go further and include a standard Drupal 8 inside a Symfony2 project? This presentation shows how to do it in a step-by-step approach and gives more generic advice on how to wrap php application inside a Symfony2 application.

Published in: Technology

Integrating Drupal 8 into Symfony 2

  1. 1. THEODO20/09/2013 1 Wrapping PHP in Symfony2 Integrating Drupal8 into Symfony2
  2. 2. THEODO20/09/2013 2 When Drupal8startedrockingthe PHP world The technical challenges of PHP wrapping Integrating Drupal8 into Symfony2, step by step
  3. 3. THEODO20/09/2013 3 Drupal usage isgrowing 2x fasterthanWordpress Drupal’s position in the CMS landscape • Drupalisused by 2% of the top 1 million websites, according to W3Techs.com • +21% growth last year! To compare withJoomla: +0% and Wordpress: +11% • Acquiaexpects$68 million revenue in 2013 with +50% growth
  4. 4. THEODO20/09/2013 4 Drupalpowersmanyinfluentialwebsites Drupal’s position in the CMS landscape
  5. 5. THEODO20/09/2013 5 Drupalpowersmanyinfluentialwebsites Drupal’s position in the CMS landscape
  6. 6. THEODO20/09/2013 6 Drupal 8 is due thisyearaftertwoyears of hard work The new Drupal version
  7. 7. THEODO20/09/2013 7 Drupal 8 is due thisyearaftertwoyears of hard work The new Drupal version • 7 core initiatives organized in a Scrum-ishway • Mobile • Multilingual • Layouts • Views in core • HTML5 • Web Services • Configuration Management • The last phase « API completion » started on July 1st
  8. 8. THEODO20/09/2013 8 Drupal 8 wants to become a content management platform The web service core initiative
  9. 9. THEODO20/09/2013 9 So Larry started looking for a good Request/Response library to include in the Web Services core initiative… The introduction of the HttpKernel
  10. 10. THEODO20/09/2013 10 …and thatiswhenStofchanged the PHP world How Drupal chose Symfony2 « And thenthis French guyStofspenthours on IRC with me, convincing me step by stephow all myproblemswouldbesolved by the HttpKernel. I realisedafterwardsitwasnighttime in France »
  11. 11. THEODO20/09/2013 11 Sincethen Symfony2 istakingover Drupal 8 Symfony2 components adopted by Drupal 8
  12. 12. THEODO20/09/2013 12 Sincethen Symfony2 istakingover Drupal 8 Drufony
  13. 13. THEODO20/09/2013 13 16 000 additionalcontributors to Symfony2! The power of the Drupalcommunity
  14. 14. THEODO20/09/2013 14 When Drupal8startedrocking the PHP world The technical challenges of PHP wrapping Integrating Drupal8 into Symfony2, step by step
  15. 15. THEODO20/09/2013 15 Why is wrapping not as easy as include? Challenges behindPHP wrapping
  16. 16. THEODO20/09/2013 16 PHP is designed around « one request <-> one process » Challenges behindPHP wrapping The consequences of this simple design are obvious: • Want to output something? echo to STDOUT • Want to end the request? => exit() • Want to sharesomethinginside the process? => $GLOBAL • Want to call two classes with the samename? =>whoneedsthat? PHP iseverything but Stateless
  17. 17. THEODO20/09/2013 17 Catching the output
  18. 18. THEODO20/09/2013 18 Catching the exits
  19. 19. THEODO20/09/2013 19 Handling globals
  20. 20. THEODO20/09/2013 20 Class and functionconflicts History of PHP applications • Write a custom autoloader for classes • And for functions…
  21. 21. THEODO20/09/2013 21 Handling session alreadystarted History of PHP applications
  22. 22. THEODO20/09/2013 22 When Drupal8startedrocking the PHP world The technical challenges of PHP wrapping Integrating Drupal8 into Symfony2, step by step
  23. 23. THEODO20/09/2013 23 A big picture of how a request is handled by Drupal 8 Drupal 8 architecture The startis (almost) likeSymfony
  24. 24. THEODO20/09/2013 24 A big picture of how a request is handled by Drupal 8 Drupal 8 architecture Authentication • ishandled by AuthenticationSubscriberstartedby the onKernelRequestAuthenticateevent • Depends on the AuthenticationManager service • That choses between the Cookie or HTTPBasic provider • In the end the Cookie provider justwraps the legacydrupal_session_initialize()
  25. 25. THEODO20/09/2013 25 A big picture of how a request is handled by Drupal 8 Drupal 8 architecture
  26. 26. THEODO20/09/2013 26 A big picture of how a request is handled by Drupal 8 Drupal 8 architecture Routing • Is handled by the CMFChainRouter • Which looks first in the DynamicRouter and then the LegacyUrlMatcher • LegacyUrlMatcherjustwrapsmenu_get_item() HTMLPageController • Wrapsdrupal_render_page
  27. 27. THEODO20/09/2013 27 A big picture of how a request is handled by Drupal 8 Drupal 8 architecture
  28. 28. THEODO20/09/2013 28 Let’s start to hack! Integration plan Goals • #1: WrapDrupal in Symfony2 • #2: Access Drupalnodes and session from a Symfony2 controller
  29. 29. THEODO20/09/2013 29 Routingbetween Symfony2 and Drupal TheodoDrupal8BundleRouterListener
  30. 30. THEODO20/09/2013 30 Routingbetween Symfony2 and Drupal TheodoDrupal8BundleRouterListener
  31. 31. THEODO20/09/2013 31 Routingbetween Symfony2 and Drupal TheodoDrupal8BundleRouterListener
  32. 32. THEODO20/09/2013 32 Buffering the kernel TheodoDrupal8BundleRouterListener
  33. 33. THEODO20/09/2013 33 Cannotredeclareassetic_init() Class loading issues
  34. 34. THEODO20/09/2013 34 Cannotredeclareassetic_init() Class loading issues
  35. 35. THEODO20/09/2013 35 Cannotredeclareassetic_init() Class loading issues
  36. 36. THEODO20/09/2013 36 Symlinks to whatDrupalexpects to be in web root Assets and symlinks Symbolic links to modules, profiles, sites and themes Symbolic links to the samefolders (and justthese) in core
  37. 37. THEODO20/09/2013 37 Change Drupal settings accordingly Assets and symlinks
  38. 38. THEODO20/09/2013 38 http://sf2drupal/app_dev.php/user works! Routingdemo Symfony’s debug toolbar! Drupal’s new responsive theme
  39. 39. THEODO20/09/2013 39 There isstill a bug in the Symfony profiler… RequestDataCollector bug
  40. 40. THEODO20/09/2013 40 Corrected in a PULL REQUEST! RequestDataCollector bug
  41. 41. THEODO20/09/2013 41 Accessevery service fromcore.services.yml Drupal Service Container
  42. 42. THEODO20/09/2013 42 For example: accessing node content getNode
  43. 43. THEODO20/09/2013 43 Getting the Drupal connected user getCurrentUser
  44. 44. THEODO20/09/2013 44 Integrating Drupal 8 into Symfony2 DemoController
  45. 45. THEODO20/09/2013 45 Integrating Drupal 8 into Symfony2! DemoController Node content! Current user name!
  46. 46. THEODO20/09/2013 46 How to do this at home TheodoDrupal8bundle https://github.com/theodo/TheodoDrupal8Bundle
  47. 47. THEODO20/09/2013 47 Tips to help you continue integrating PHP integration • Good IDE + Xdebug to follow the code • Put a breakpointaterrorhandlingfunctions, to read the errorinside the code • Compare the samefunctionality/page with and withoutwrapping • Otherinteresting bundle: https://github.com/theodo/TheodoEvolutionSessionBundle
  48. 48. THEODO20/09/2013 48 What are the next priorities Nextsteps • Integration must bringease of adding custom logic in Symfonycontrollers =>likeRogerCMS • See how Symfony2 canimproveDrupal 8 performances… • Session and permission sharing
  49. 49. THEODO20/09/2013 49 Questions ? fabriceb@theodo.fr @theodo www.theodo.fr Feedback: https://joind.in/9329

×