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

Per Your Request

Per Your Request

How does Laravel 4 work? What precisely happens when a user loads index.php? Per Your Request walks through Laravel's entire request cycle, and shows you what happens when.

Kenny Meyers

February 22, 2013
Tweet

Other Decks in Programming

Transcript

  1. Autoloadin‘ Application Bootstrapped Run 1. LARAVEL_START constant is set 2.

    index.php requires /bootstrap/autoload.php 3. bootstrap.php requires composer’s /vendor/ autoload file 4. Register Laravel’s custom ClassLoader 5. Register the workbench’s autoload files Phase I Commence
  2. All classes are ultimately loaded via The worst named function

    since [Java or C joke] Autoloadin‘ Application Bootstrapped Run
  3. Finder Class Symfony\Component\Finder Implements Countable, IteratorAggregate Traverses a given directory

    and returns an array of objects with some lovely file metadata Autoloadin‘ Application Bootstrapped Run
  4. Phase I Complete Autoloadin‘ Application Bootstrapped Run 1. LARAVEL_START constant

    is set 2. index.php requires /bootstrap/autoload.php 3. bootstrap requires composer’s /vendor/autoload file 4. Register Laravel’s custom ClassLoader 5. Register the workbench’s autoload files
  5. Autoloadin‘ Application Bootstrapped Run 1. Require /bootstrap/start.php 2.Create a new

    instance of Illuminate\Foundation \Application 3. This creates the request object and registers 3 ServiceProviders 4. Detect and set the environment 5. Bind our application filepaths to the Application object 6. Require the Foundation start.php file via Application::getBootstrapFile() Phase 2 Commence
  6. Autoloadin‘ Application Bootstrapped Run Phase 2 Complete 1. Require /bootstrap/start.php

    2.Create a new instance of Illuminate\Foundation \Application 3. This creates the request object and registers 3 ServiceProviders 4. Detect and set the environment 5. Bind our application filepaths to the Application object 6. Require the Foundation start.php file via Application::getBootstrapFile()
  7. 1. Set the $env var if we’re running tests 2.

    Setup the Facade 3. Load the config files 4. Set the default timezone 5. Register the alias loader 6. Allow for PUT and DELETE requests with forms 7. Create the provider repository 8. Boot ServiceProviders with Application::boot() 9. Require the /app/start/global.php file 10. Require the /app/start/$env.php file 11. Require the /app/routes.php file Phase 3 Commence Autoloadin‘ Application Bootstrapped Run
  8. First, let’s turn off error handling and report all errors

    Autoloadin‘ Application Bootstrapped Run
  9. Next, let’s lie to people about the classnames they’re using.

    Autoloadin‘ Application Bootstrapped Run
  10. After that, let’s make sure we can load config files,

    maybe with some sort of callback Autoloadin‘ Application Bootstrapped Run
  11. Oh $#@*! Let’s turn on exception handling, we may start

    causing them. Autoloadin‘ Application Bootstrapped Run /vendor/laravel/framework/src/Illuminate/Foundation/start.php
  12. ...and please stop showing that warning PHP, you jerk. Autoloadin‘

    Application Bootstrapped Run /vendor/laravel/framework/src/Illuminate/Foundation/start.php
  13. QUICK! We need a place to store ALL our service

    providers! Autoloadin‘ Application Bootstrapped Run /vendor/laravel/framework/src/Illuminate/Foundation/start.php
  14. Now, iterate through our registered service providers Calling the boot()

    method on each Autoloadin‘ Application Bootstrapped Run /vendor/laravel/framework/src/Illuminate/Foundation/start.php
  15. The Application will also fire any registered call backs upon

    boot completion Autoloadin‘ Application Bootstrapped Run Illuminate\Foundation\Application
  16. 1. Set the $env var if we’re running tests 2.

    Setup the Facade 3. Load the config files 4. Set the default timezone 5. Register the alias loader 6. Allow for PUT and DELETE requests with forms 7. Create the provider repository 8. Boot ServiceProviders with Application::boot() 9. Require the /app/start/global.php file 10. Require the /app/start/$env.php file 11. Require the /app/routes.php file Phase 3 Complete Autoloadin‘ Application Bootstrapped Run
  17. 1. Run the app 2. Set the session store if

    it exists 3. Find the route 4. Run the route code, calling filters where applicable (ex: before and after) 5. Generate a Response object 6. Send the response 7. Call the after filter Autoloadin‘ Application Bootstrapped Run Phase 4 Commence
  18. Finds the route and runs it Autoloadin‘ Application Bootstrapped Run

    Illuminate\Routing\Router Router::dispatch() (Calls the global before filter right before this)
  19. Sends the response to the browser Autoloadin‘ Application Bootstrapped Run

    Illuminate\Foundation\Application Application::run()
  20. Autoloadin‘ Application Bootstrapped Run Illuminate\Routing\Router Phase 4 Complete 1. Run

    the app 2. Set the session store if it exists 3. Find the route 4. Run the route code, calling filters where applicable (ex: before and after) 5. Generate a Response object 6. Send the response 7. Call the after filter