I'm not a Drupal developer, but I do already know *a lot* about Drupal 8, like how the event system works, what a service is, how it relates to a dependency injection container and how the deepest and darkest of Drupal’s request-response workflow looks.
How? Because I use Symfony. And if you want to get a jumpstart on Drupal 8, you should to. In this talk, we'll double the number of tools you have to solve problems (Drupal + Symfony) and start to unlock all the new important concepts. We'll start with Silex (a microframework based on Symfony), graduate to Symfony, and focus on the pieces that are most interesting to a Drupal 8 developer.
2. !
!
!
!
!
!
• Husband of the much more
talented @leannapelham
PHP Tutorial Screencasts
knplabs.com
github.com/weaverryan
• Lead contributor to the Symfony documentation
!
• KnpLabs US - Symfony consulting, training, Kumbaya
!
• Writer for KnpUniversity.com
awesome amazing screencasts!!*!
Hallo!
7. Or use the built-in PHP
web server o/
php -S localhost:8000
@weaverryan
8. * The built-in PHP web server can be
used with Drupal too!
9. Request -> Response Framework
Response:
Hello Texas!@weaverryan
Routing:
Determine a function that can
create this page (the controller)
Request:
GET /hello/Texas!
The Controller:
Our code: constructs the page
10. The route is matched
when the URI is
/hello/*@weaverryan
11. If the URI matches the route,
Silex executes this
function (the controller)
@weaverryan
12. The value of {name} is
passed as an argument
to the controller
@weaverryan
14. Request -> Response Framework
The Controller:
Our code: constructs the page
Response:
Hello Texas!@weaverryan
Routing:
Determine a function that can
create this page (the controller)
Request:
GET /hello/Texas!
16. Our Mission:
(should we choose to accept it)
!
!
Understand the “request” and
create a “response”
@weaverryan
17. The Request
@weaverryan
GET /hello/Texas?page=5 HTTP/1.1!
Host: localhost:8000!
Connection: keep-alive!
Cache-Control: max-age=0!
Accept: text/html,application/xhtml+xml!
User-Agent: Mozilla/5.0!
Cookie: PHPSESSID=abcdefg; has_js=1;
The client sends us a simple message
that describes what they want
18. The Request
@weaverryan
GET /hello/Texas?page=5 HTTP/1.1!
Host: localhost:8000!
Connection: keep-alive!
Cache-Control: max-age=0!
Accept: text/html,application/xhtml+xml!
User-Agent: Mozilla/5.0!
Cookie: PHPSESSID=abcdefg; has_js=1;
The HTTP method
The URI
The client sends us a simple message
that describes what they want
19. The Request
@weaverryan
The Request headers
GET /hello/Texas?page=5 HTTP/1.1!
Host: localhost:8000!
Connection: keep-alive!
Cache-Control: max-age=0!
Accept: text/html,application/xhtml+xml!
User-Agent: Mozilla/5.0!
Cookie: PHPSESSID=abcdefg; has_js=1;
The client sends us a simple message
that describes what they want
32. Autoloading
@weaverryan
You don’t need to use
require/include if:
!
A. The namespace is the
same as the directory
!
B. The class has the
same name as the
folder (+.php)
It’s called PSR-0
39. Request -> Response Framework
The Controller:
Our code: constructs the page
Response:
Hello Texas!@weaverryan
Container
(with services)
Routing:
Determine a function that can
create this page (the controller)
Request:
GET /hello/Texas!
42. “Hi! When event XXXXX
happens, execute this
function. kthxbai”
@weaverryan
You can tell Silex:
43. Request -> Response Framework
The Controller:
Our code: constructs the page
@weaverryan
Container
(with services)
Event:
kernel.controller
Events:
kernel.view
kernel.response Response:
Hello Texas!
Routing:
Determine a function that can
create this page (the controller)
Request:
GET /hello/Texas!
Event:
kernel.request
73. @weaverryan
Now, the container has a service
called “acme.view_subscriber”
The event_subscriber tag says to Drupal
that this service wants to be a “listener”
for some events
83. Principal Themes
• Request/Response
!
• Routing/Controller
!
• PHP Namespaces/Autoloading
!
• Services/Container
• Events/Listeners
• Profiler
@weaverryan
All are the same in Silex, Drupal & Symfony