Date post: | 10-May-2015 |
Category: |
Technology |
Upload: | fabrice-bernhard |
View: | 6,141 times |
Download: | 0 times |
THEODO20/09/2013 1
Wrapping PHP in Symfony2Integrating Drupal8 into Symfony2
THEODO20/09/2013 2
When Drupal8 started rocking the PHP world
The technical challenges of PHP wrapping
Integrating Drupal8 into Symfony2, step by step
THEODO20/09/2013 3
Drupal usage is growing 2x faster than WordpressDrupal’s position in the CMS landscape
• Drupal is used by 2% of the top 1 million websites, according to W3Techs.com
• +21% growth last year!To compare with Joomla: +0% and Wordpress:
+11%
• Acquia expects $68 million revenue in 2013 with +50% growth
THEODO20/09/2013 4
Drupal powers many influential websitesDrupal’s position in the CMS landscape
THEODO20/09/2013 5
Drupal powers many influential websitesDrupal’s position in the CMS landscape
THEODO20/09/2013 6
Drupal 8 is due this year after two years of hard workThe new Drupal version
THEODO20/09/2013 7
Drupal 8 is due this year after two years of hard workThe new Drupal version
• 7 core initiatives organized in a Scrum-ish way• Mobile• Multilingual• Layouts• Views in core• HTML5• Web Services• Configuration Management
• The last phase « API completion » started on July 1st
THEODO20/09/2013 8
Drupal 8 wants to become a content management platformThe 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 initiative…The introduction of the HttpKernel
THEODO20/09/2013 10
…and that is when Stof changed the PHP worldHow Drupal chose Symfony2
« And then this French guy Stof spent hours on IRC with me, convincing me step by step how all my problems would be solved by the HttpKernel. I realised afterwards it was nighttime in France »
THEODO20/09/2013 11
Since then Symfony2 is taking over Drupal 8Symfony2 components adopted by Drupal 8
THEODO20/09/2013 12
Since then Symfony2 is taking over Drupal 8Drufony
THEODO20/09/2013 13
16 000 additional contributors to Symfony2!The power of the Drupal community
THEODO20/09/2013 14
When Drupal8 started rocking the PHP world
The technical challenges of PHP wrapping
Integrating Drupal8 into Symfony2, step by step
THEODO20/09/2013 15
Why is wrapping not as easy as include?Challenges behind PHP wrapping
THEODO20/09/2013 16
PHP is designed around « one request <-> one process »Challenges behind PHP wrapping
The consequences of this simple design are obvious:
• Want to output something? echo to STDOUT• Want to end the request? => exit()• Want to share something inside the process? => $GLOBAL• Want to call two classes with the same name? => who needs that?
PHP is everything but Stateless
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 function conflictsHistory of PHP applications
• Write a custom autoloader for classes• And for functions…
THEODO20/09/2013 21
Handling session already startedHistory of PHP applications
THEODO20/09/2013 22
When Drupal8 started rocking the PHP world
The technical challenges of PHP wrapping
Integrating Drupal8 into Symfony2, step by step
THEODO20/09/2013 23
A big picture of how a request is handled by Drupal 8Drupal 8 architecture
The start is (almost) like Symfony
THEODO20/09/2013 24
A big picture of how a request is handled by Drupal 8Drupal 8 architecture
Authentication
• is handled by AuthenticationSubscriber started by the onKernelRequestAuthenticate event
• Depends on the AuthenticationManager service
• That choses between the Cookie or HTTPBasic provider
• In the end the Cookie provider just wraps the legacy drupal_session_initialize()
THEODO20/09/2013 25
A big picture of how a request is handled by Drupal 8Drupal 8 architecture
THEODO20/09/2013 26
A big picture of how a request is handled by Drupal 8Drupal 8 architecture
Routing• Is handled by the CMFChainRouter• Which looks first in the DynamicRouter and then the
LegacyUrlMatcher• LegacyUrlMatcher just wraps menu_get_item()
HTMLPageController• Wraps drupal_render_page
THEODO20/09/2013 27
A big picture of how a request is handled by Drupal 8Drupal 8 architecture
THEODO20/09/2013 28
Let’s start to hack! Integration plan
Goals
• #1: Wrap Drupal in Symfony2
• #2: Access Drupal nodes and session from a Symfony2 controller
THEODO20/09/2013 29
Routing between Symfony2 and DrupalTheodoDrupal8Bundle\RouterListener
THEODO20/09/2013 30
Routing between Symfony2 and DrupalTheodoDrupal8Bundle\RouterListener
THEODO20/09/2013 31
Routing between Symfony2 and DrupalTheodoDrupal8Bundle\RouterListener
THEODO20/09/2013 32
Buffering the kernelTheodoDrupal8Bundle\RouterListener
THEODO20/09/2013 33
Cannot redeclare assetic_init()Class loading issues
THEODO20/09/2013 34
Cannot redeclare assetic_init()Class loading issues
THEODO20/09/2013 35
Cannot redeclare assetic_init()Class loading issues
THEODO20/09/2013 36
Symlinks to what Drupal expects to be in web rootAssets and symlinks
Symbolic links to modules, profiles, sites and themes
Symbolic links to the same folders (and just these) in core
THEODO20/09/2013 37
Change Drupal settings accordinglyAssets and symlinks
THEODO20/09/2013 38
http://sf2drupal/app_dev.php/user works!Routing demo
Symfony’s debug toolbar!
Drupal’s new responsive theme
THEODO20/09/2013 39
There is still a bug in the Symfony profiler…RequestDataCollector bug
THEODO20/09/2013 40
Corrected in a PULL REQUEST!RequestDataCollector bug
THEODO20/09/2013 41
Access every service from core.services.ymlDrupal Service Container
THEODO20/09/2013 42
For example: accessing node contentgetNode
THEODO20/09/2013 43
Getting the Drupal connected usergetCurrentUser
THEODO20/09/2013 44
Integrating Drupal 8 into Symfony2DemoController
THEODO20/09/2013 45
Integrating Drupal 8 into Symfony2!DemoController
Node content!
Current user name!
THEODO20/09/2013 46
How to do this at homeTheodoDrupal8bundle
https://github.com/theodo/TheodoDrupal8Bundle
THEODO20/09/2013 47
Tips to help you continue integratingPHP integration
• Good IDE + Xdebug to follow the code
• Put a breakpoint at error handling functions, to read the error inside the code
• Compare the same functionality/page with and without wrapping
• Other interesting bundle: https://github.com/theodo/TheodoEvolutionSessionBundle
THEODO20/09/2013 48
What are the next prioritiesNext steps
• Integration must bring ease of adding custom logic in Symfony controllers => like RogerCMS
• See how Symfony2 can improve Drupal 8 performances…• Session and permission sharing
THEODO20/09/2013 49
Questions [email protected]
@theodowww.theodo.fr
Feedback: https://joind.in/9329