Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Great Framework Kumbaya

weaverryan
October 31, 2014

The Great Framework Kumbaya

Time to gather our frameworks around a warm camp fire and see just how much we have in common In this presentation, we take a flat PHP4-style application and gently migrate it into our own "framework", that uses components from Symfony2, Zend Framework 2, Aura and a library called Pimple. By the end, you'll see how any ugly application can take advantage of the many wonderful tools available to PHP developers. You'll also learn exactly how *any* framework actually works under the hood by hooking up routing, controllers, services and events.

weaverryan

October 31, 2014
Tweet

More Decks by weaverryan

Other Decks in Technology

Transcript

  1. KnpUniversity.com github.com/weaverryan Who is this Happy Camper? > Lead for

    the Symfony documentation
 > KnpLabs US - Symfony Consulting, training, Kumbaya ! > Writer for KnpUniversity.com Tutorials > Husband of the much more talented @leannapelham
  2. > The United Nations of PHP ! > Equally Important

    ! > Equally dysfunctional (like any happy family) @weaverryan
  3. A) Reading request info could be better ! B) can’t

    set headers later on ! C) front controller ! D) little URL control ! E) all objects are global ! F) 1 giant file (no separation) ! G) HTML and PHP is mixed! Problems @weaverryan
  4. if ($uri == '/' || $uri == '') { //

    ... } elseif ($uri == '/attendees') { // ... } else { // ... } @weaverryan Our app is a giant gross “if” statement Problems Grabbing a piece from the URL like /blog/my-blog-post will take some work
  5. 1. Request cleans the URI 2. Router matches the URI

    to a route, returns a 
 “controller” string 3. We execute the controller function 4. The controller creates a Response object 5. We send the Response headers and content The Big Picture @weaverryan
  6. A) Reading request info could be better ! B) can’t

    set headers later on ! C) front controller ! D) little URL control ! E) all objects are global ! F) 1 giant file (no separation) ! G) HTML and PHP is mixed! Problems @weaverryan
  7. > We’ve got lots of random, disorganized objects floating around

    and some depend on others Problems > And we can’t easily access them from within our controllers @weaverryan
  8. We have 1 file with everything mixed ! ! 1)

    Creation of container & objects 2) Definition of routes 3) Definition of controllers 4) The “framework” code that executes everything Problems @weaverryan
  9. We have 1 file with everything mixed ! 1) services.php

    2) routes.php 3) controllers.php 4) bootstrap.php (framework code) Basic Solution @weaverryan
  10. … but don’t limit yourself to one “world”… Symfony Developer

    Laravel Developer Drupal Developer Silex Developer