PHP Tutorial Screencasts


MASTER THE NEW CORE
OF DRUPAL 8 NOW: WITH
SYMFONY AND SILEX
!
!
!
!
!
!
• Husband of the much more
talented @leannapelham
PHP Tutorial Screencasts
knplabs.com
github.com/weaverryan
•...
Act 1
!
The anatomy of any
web framework
@weaverryan
@weaverryan
An entire application
that says hallo!
Configure Apache
Or use the built-in PHP
web server o/
php -S localhost:8000
@weaverryan
* The built-in PHP web server can be
used with Drupal too!
Request -> Response Framework
Response:
Hello Texas!@weaverryan
Routing:
Determine a function that can
create this page (t...
The route is matched
when the URI is
/hello/*@weaverryan
If the URI matches the route,
Silex executes this
function (the controller)
@weaverryan
The value of {name} is
passed as an argument
to the controller
@weaverryan
We construct the page
and celebrate!
@weaverryan
Request -> Response Framework
The Controller:
Our code: constructs the page
Response:
Hello Texas!@weaverryan
Routing:
Det...
Act 2
!
Request-Response
Our Mission:
(should we choose to accept it)
!
!
Understand the “request” and
create a “response”
@weaverryan
The Request
@weaverryan
GET /hello/Texas?page=5 HTTP/1.1!
Host: localhost:8000!
Connection: keep-alive!
Cache-Control: max...
The Request
@weaverryan
GET /hello/Texas?page=5 HTTP/1.1!
Host: localhost:8000!
Connection: keep-alive!
Cache-Control: max...
The Request
@weaverryan
The Request headers
GET /hello/Texas?page=5 HTTP/1.1!
Host: localhost:8000!
Connection: keep-alive...
The Response
@weaverryan
HTTP/1.1 200 OK!
Host: localhost:8000!
Cache-Control: no-cache!
Date: Wed, 23 Apr 2014 16:25:03 G...
HTTP/1.1 200 OK!
Host: localhost:8000!
Cache-Control: no-cache!
Date: Wed, 23 Apr 2014 16:25:03 GMT!
Content-Type: text/ht...
In PHP, the “request” message
*explodes* into the “superglobals”
@weaverryan
To create the response, we use
“header” and echo content
@weaverryan
@weaverryan
The Request in Silex
@weaverryan
The Response in Silex
Act 3
!
Namespaces & Autoloading
https://www.flickr.com/photos/chrisjeriko/8599248142
The controller can be
any ol’ function
Controller as a method in a class
@weaverryan
Controller as a method in a class
@weaverryan
PHP Namespaces
@weaverryan
Namespaces give us longer class names:	

DrupalacmeControllerDemoController
PHP Namespaces
@weaverryan
Autoloading
@weaverryan
You don’t need to use
require/include if:
!
A. The namespace is the
same as the directory
!
B. The...
Act 4:
!
Services and the
“container”
Services == Useful Objects
@weaverryan
The container == the object that
contains all the services
@weaverryan
In Silex, Symfony and Drupal 8,
there is a “container”.
!
If you have it, you can use any
service (useful object)
Can we use the
Twig service to
render a template?
@weaverryan
The “container” in SilexThe service “twig”
Request -> Response Framework
The Controller:
Our code: constructs the page
Response:
Hello Texas!@weaverryan
Container	

...
Act 5:
!
Events
https://www.flickr.com/photos/bmp_creep/8064779382
Just like Drupal “hooks”,
Silex has events
@weaverryan
“Hi! When event XXXXX
happens, execute this
function. kthxbai”
@weaverryan
You can tell Silex:

Request -> Response Framework
The Controller:
Our code: constructs the page
@weaverryan
Container	

(with services)
Event:...
@weaverryan
@weaverryan
Act 6:
!
The Profiler
https://www.flickr.com/photos/fukagawa/415772853
Silex (because of Symfony)
has a “profiler”
@weaverryan
@weaverryan
It has a lot of
information, including
the “timeline”
@weaverryan https://www.flickr.com/photos/42andpointless/8062417131
@weaverryan
1) kernel.request event
2) Routing
3) Executes the controller
4) Our “listener” in kernel.view
Act 7:
!
Everything is the same
in Drupal 8
How can we create this
in Drupal 8?
Thank you to my amigo
Jesus Olivas for writing
awesome blog posts
@jmolivas
jmolivas.com
http://bit.ly/d8-hello
1) Create module “acme”
@jmolivas http://bit.ly/d8-hello
2) Create routing
@jmolivas http://bit.ly/d8-hello
Name of the controller
acme.routing.yml
3) Create the controller
@jmolivas http://bit.ly/d8-hello
Module, Routing, Controller
@jmolivas http://bit.ly/d8-hello
These extra directories are	

going away soon o/
@weaverryan
And there’s even a code generator
already for all of this (and more)
Drupal 8 Console
https://drupal.org/project/console@jmolivas
Does Drupal 8 have a
service container?
@weaverryan
The Container
Where you find the
container could change
before Drupal 8 is finished
@weaverryan
@weaverryan
Yes there is a container
!
And yes, it has all of the
useful objects (services)
of Drupal
Are there events
like in Silex?
@weaverryan
Yes! The same events
exist and more!
1) Create a “listener” class
This is executed at 	

the end of the request	

!
We add JavaScript to 	

each page on the site
2) Add a new service
to the container
@weaverryan
Now, the container has a service	

called “acme.view_subscriber”
The event_subscriber tag says to Drupal	

tha...
@weaverryan
And does the
profiler exist?
@weaverryan
https://drupal.org/project/webprofiler
@weaverryan
https://drupal.org/project/webprofiler
@weaverryan
https://drupal.org/project/webprofiler
@weaverryan
https://drupal.org/project/webprofiler
@weaverryan
https://drupal.org/project/webprofiler
@weaverryan
https://drupal.org/project/webprofiler
Act 8
!
!
, &
Principal Themes
• Request/Response	

!
• Routing/Controller	

!
• PHP Namespaces/Autoloading	

!
• Services/Container

• ...
You can use Silex
to learn Drupal!
You can use Silex
to learn Symfony!
You can use Symfony
to learn Drupal!
https://www.flickr.com/photos/zzpza/3269784239
Finally, We have more
tools to solve problems
PHP Tutorial Screencasts
Ryan Weaver
@weaverryan
Thank you!
Master the New Core of Drupal 8 Now: with Symfony and Silex
Upcoming SlideShare
Loading in...5
×

Master the New Core of Drupal 8 Now: with Symfony and Silex

3,003

Published on

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.

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,003
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
19
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Master the New Core of Drupal 8 Now: with Symfony and Silex

  1. 1. PHP Tutorial Screencasts 
 MASTER THE NEW CORE OF DRUPAL 8 NOW: WITH SYMFONY AND SILEX
  2. 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!
  3. 3. Act 1 ! The anatomy of any web framework
  4. 4. @weaverryan
  5. 5. @weaverryan An entire application that says hallo!
  6. 6. Configure Apache
  7. 7. Or use the built-in PHP web server o/ php -S localhost:8000 @weaverryan
  8. 8. * The built-in PHP web server can be used with Drupal too!
  9. 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. 10. The route is matched when the URI is /hello/*@weaverryan
  11. 11. If the URI matches the route, Silex executes this function (the controller) @weaverryan
  12. 12. The value of {name} is passed as an argument to the controller @weaverryan
  13. 13. We construct the page and celebrate! @weaverryan
  14. 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!
  15. 15. Act 2 ! Request-Response
  16. 16. Our Mission: (should we choose to accept it) ! ! Understand the “request” and create a “response” @weaverryan
  17. 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. 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. 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
  20. 20. The Response @weaverryan HTTP/1.1 200 OK! Host: localhost:8000! Cache-Control: no-cache! Date: Wed, 23 Apr 2014 16:25:03 GMT! Content-Type: text/html;! ! Hello Texas
  21. 21. HTTP/1.1 200 OK! Host: localhost:8000! Cache-Control: no-cache! Date: Wed, 23 Apr 2014 16:25:03 GMT! Content-Type: text/html;! ! Hello Texas The Response @weaverryan Response status code The Response headers The body
  22. 22. In PHP, the “request” message *explodes* into the “superglobals” @weaverryan
  23. 23. To create the response, we use “header” and echo content @weaverryan
  24. 24. @weaverryan The Request in Silex
  25. 25. @weaverryan The Response in Silex
  26. 26. Act 3 ! Namespaces & Autoloading https://www.flickr.com/photos/chrisjeriko/8599248142
  27. 27. The controller can be any ol’ function
  28. 28. Controller as a method in a class @weaverryan
  29. 29. Controller as a method in a class @weaverryan
  30. 30. PHP Namespaces @weaverryan Namespaces give us longer class names: DrupalacmeControllerDemoController
  31. 31. PHP Namespaces @weaverryan
  32. 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
  33. 33. Act 4: ! Services and the “container”
  34. 34. Services == Useful Objects @weaverryan
  35. 35. The container == the object that contains all the services @weaverryan
  36. 36. In Silex, Symfony and Drupal 8, there is a “container”. ! If you have it, you can use any service (useful object)
  37. 37. Can we use the Twig service to render a template?
  38. 38. @weaverryan The “container” in SilexThe service “twig”
  39. 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!
  40. 40. Act 5: ! Events https://www.flickr.com/photos/bmp_creep/8064779382
  41. 41. Just like Drupal “hooks”, Silex has events @weaverryan
  42. 42. “Hi! When event XXXXX happens, execute this function. kthxbai” @weaverryan You can tell Silex:

  43. 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
  44. 44. @weaverryan
  45. 45. @weaverryan
  46. 46. Act 6: ! The Profiler https://www.flickr.com/photos/fukagawa/415772853
  47. 47. Silex (because of Symfony) has a “profiler” @weaverryan
  48. 48. @weaverryan
  49. 49. It has a lot of information, including the “timeline” @weaverryan https://www.flickr.com/photos/42andpointless/8062417131
  50. 50. @weaverryan
  51. 51. 1) kernel.request event 2) Routing 3) Executes the controller 4) Our “listener” in kernel.view
  52. 52. Act 7: ! Everything is the same in Drupal 8
  53. 53. How can we create this in Drupal 8?
  54. 54. Thank you to my amigo Jesus Olivas for writing awesome blog posts @jmolivas jmolivas.com
  55. 55. http://bit.ly/d8-hello
  56. 56. 1) Create module “acme” @jmolivas http://bit.ly/d8-hello
  57. 57. 2) Create routing @jmolivas http://bit.ly/d8-hello Name of the controller acme.routing.yml
  58. 58. 3) Create the controller @jmolivas http://bit.ly/d8-hello
  59. 59. Module, Routing, Controller @jmolivas http://bit.ly/d8-hello These extra directories are going away soon o/
  60. 60. @weaverryan
  61. 61. And there’s even a code generator already for all of this (and more)
  62. 62. Drupal 8 Console https://drupal.org/project/console@jmolivas
  63. 63. Does Drupal 8 have a service container?
  64. 64. @weaverryan The Container
  65. 65. Where you find the container could change before Drupal 8 is finished @weaverryan
  66. 66. @weaverryan Yes there is a container ! And yes, it has all of the useful objects (services) of Drupal
  67. 67. Are there events like in Silex?
  68. 68. @weaverryan Yes! The same events exist and more!
  69. 69. 1) Create a “listener” class
  70. 70. This is executed at the end of the request ! We add JavaScript to each page on the site
  71. 71. 2) Add a new service to the container
  72. 72. @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
  73. 73. @weaverryan
  74. 74. And does the profiler exist?
  75. 75. @weaverryan https://drupal.org/project/webprofiler
  76. 76. @weaverryan https://drupal.org/project/webprofiler
  77. 77. @weaverryan https://drupal.org/project/webprofiler
  78. 78. @weaverryan https://drupal.org/project/webprofiler
  79. 79. @weaverryan https://drupal.org/project/webprofiler
  80. 80. @weaverryan https://drupal.org/project/webprofiler
  81. 81. Act 8 ! ! , &
  82. 82. Principal Themes • Request/Response ! • Routing/Controller ! • PHP Namespaces/Autoloading ! • Services/Container
 • Events/Listeners
 • Profiler @weaverryan All are the same in Silex, Drupal & Symfony
  83. 83. You can use Silex to learn Drupal!
  84. 84. You can use Silex to learn Symfony!
  85. 85. You can use Symfony to learn Drupal!
  86. 86. https://www.flickr.com/photos/zzpza/3269784239 Finally, We have more tools to solve problems
  87. 87. PHP Tutorial Screencasts Ryan Weaver @weaverryan Thank you!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×