Silex Microframework y camino fácil de aprender Symfony PHP Tutorial Screencasts
Buenos Dias! Lead contributor to the Symfony documentation!! KnpLabs US - Symfony consulting, training, Kumbaya!!! Writer for KnpUniversity.com! screencasts! Husband of the much more talented @leannapelham PHP Tutorial Screencasts knplabs.com github.com/weaverryan
Querétaro Viví en Querétaro en 2003 para cuatro meses Hablé casi 5 palabras en español. Este gringo estaba *sorprendido* por el costumbre de besar para saludar a las mujeres PHP Tutorial Screencasts knplabs.com github.com/weaverryan
Capítulo 1! La anatomía de cualquier web framework
@weaverryan
Una aplicación compleja que nos @weaverryan da saludos!
Configure Apache
O usen al web server nativo de PHP! php -S localhost:8000 @weaverryan
*Se puede usar este web server para Drupal también
Request -> Response Framework Request: GET /hello/drupalmx Routing: determina una función que puede crear esta página (el controller) El Controller: nuestro código: construye la pagina Response: @weaverryan Hello drupalmx!
Una ruta que coincide cuando el URI es @weaverryan /hello/*
Si el URI coincide la ruta, Silex ejecuta esta función (el controller) @weaverryan
El valor de {name} se pasa como argumento al controller @weaverryan
Construimos la pagina y celebrar! @weaverryan
Request -> Response Framework Request: GET /hello/drupalmx Routing: determina una función que puede crear esta página (el controller) El Controller: nuestro código: construye la pagina Response: @weaverryan Hello drupalmx!
Capítulo 2 Request-Response!
Nuestro Trabajo: Entender el request y crear un response @weaverryan
El Request GET /hello/drupalmx?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; El cliente nos da un mensaje sencillo que describe qué quiere @weaverryan
El método HTTP El Request GET /hello/drupalmx?page=5 HTTP/1.1! Host: localhost:8000! El URI 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; El cliente nos da un mensaje sencillo que describe qué quiere @weaverryan
Los Request headers El Request GET /hello/drupalmx?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; El cliente nos da un mensaje sencillo que describe qué quiere @weaverryan
El Response 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 drupalmx @weaverryan
El Response El código del response HTTP/1.1 200 OK! Los Response headers Host: localhost:8000! Cache-Control: no-cache! Date: Wed, 23 Apr 2014 16:25:03 GMT! Content-Type: text/html;!! <h1>hello drupalmx</h1> @weaverryan El cuerpo
En PHP, el request mensaje se deconstruye a los superglobals @weaverryan
Para crear el response, usamos header y echo content @weaverryan
@weaverryan El Request en Silex
@weaverryan El Response en Silex
Capítulo 3 Namespaces & Autoloading! https://www.flickr.com/photos/chrisjeriko/8599248142
El controller puede ser cualquier función
Controller como método en clase @weaverryan
Controller como método en clase @weaverryan
PHP Namespaces Namespaces nos da nombres max largos nombre: Drupal\acme\Controller\DemoController @weaverryan
@weaverryan PHP Namespaces
Autoloading No se necesita usar require/include si:! A. El namespace es igual al directorio! B. La clase es igual al nombre de archivo (+.php) Se llama PSR-0 @weaverryan
Capítulo 4:! Servicios y el container
@weaverryan Servicios: Objetos útiles
El container: el objeto que contiene todos los servicios @weaverryan
En Silex, Symfony y Drupal 8, existe un container. Si lo tienes, puede usar los! servicios (objetos útiles)
Podemos usar el servicio de Twig para render un template?
El servicio twig El container in Silex @weaverryan
Request -> Response Framework Request: GET /hello/drupalmx Routing: determina una función que puede crear esta página (el controller) El Controller: Container (con servicios) nuestro código: construye la pagina Response: @weaverryan Hello drupalmx!
Capítulo 5:! Eventos https://www.flickr.com/photos/bmp_creep/8064779382
Como Drupal hooks, Silex tiene eventos @weaverryan
Puede decir a Silex: Por favor, cuando ocurra el evento XXXXX, ejecute esa función @weaverryan
Request -> Response Framework Request: Evento: kernel.request GET /hello/drupalmx Routing: determina una función que puede crear esta página (el controller) Evento: kernel.controller El Controller: Container (con servicios) nuestro código: construye la pagina Eventos: kernel.view kernel.response @weaverryan Response: Hello drupalmx!
@weaverryan
@weaverryan
Capítulo 6:! El Profiler https://www.flickr.com/photos/fukagawa/415772853
Silex (por Symfony) tiene un profiler @weaverryan
@weaverryan
Contiene muchísimo información, incluyendo el timeline @weaverryan
@weaverryan
1) kernel.request evento 2) Routing 3) Ejecuta el controller 4) Nuestro listener en kernel.view
Capítulo 7: Todo lo mismo en Drupal 8!
Cómo podemos crear esto en Drupal 8?
Gracias a mi amigo Jesus Olivas por ya tener blog posts muy buenos @jmolivas jmolivas.com
http://bit.ly/d8-hello
1) Crear un module acme @jmolivas http://bit.ly/d8-hello
2) Crear routing Nombre del controller @jmolivas http://bit.ly/d8-hello
3) Crear el controller @jmolivas http://bit.ly/d8-hello
Module, Routing, Controller @jmolivas http://bit.ly/d8-hello
@weaverryan
Tiene Drupal 8 un container con servicios?
@weaverryan El Container
Donde se debe encuentra el container puede cambiar antes del fin de Drpual 8 @weaverryan
Pero sí hay un container Y sí continue todos los objetos útiles (servicios) de Drupal! @weaverryan
Hay eventos como Silex?
Sí! Existen los mismos eventos y más @weaverryan
1) Crear una clase listener
Se ejecuta al fin del request! Añadimos JavaScript a cada pagina en el sitio
2) Añadir un nuevo servicio al container
Ahora, el container tiene un servicio que se llama acme.view_subscriber @weaverryan El event_subscriber tag dice al Drupal que este servicio quiere ser un listener para algunos eventos
@weaverryan
Y existe el profiler?
@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
Capítulo 8!, y!
Temas Principales!! Request/Response Routing/Controller PHP Namespaces/Autoloading! Services/Container Events/Listeners Profiler Todos son iguales en Silex, Drupal y Symfony @weaverryan
Se puede usar Silex para aprender Drupal
Se puede usar Silex para aprender Symfony
Se puede usar Symfony para aprender Drupal
Al fin, tienen mas herramientas para cualquier problema
Gracias! Ryan Weaver @weaverryan PHP Tutorial Screencasts
@weaveryan @KnpUniversity