Skip to content

Instantly share code, notes, and snippets.

@samirreza
Last active November 5, 2020 08:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samirreza/93a506b58b29e9ee6cae7ec7d359dac7 to your computer and use it in GitHub Desktop.
Save samirreza/93a506b58b29e9ee6cae7ec7d359dac7 to your computer and use it in GitHub Desktop.
Laravel Bootstratpping Process
1. set LARAVEL_START global variable
2. check for maintenance mode
3. register composer autoloader
4. create new application instance
1. set some paths in service container as instance
2. define "app" and Container::class instance in service container with current application instance
3. register base service providers : EventServiceProvider - LogServiceProvider - RoutingServiceProvider
1. create service provider instance and path application instance to its constructor
2. call register method on service provider
3. read "bindings" property of service provider if exists and bind its key/value in service container
4. read "singletons" property of service provider if exists and make its key/value as singleton in service container
5. mark these service providers as registered
6. because app is not booted the boot method of these service providers not called
4. register core container aliases. for example : 'events' aliase for \Illuminate\Events\Dispatcher and \Illuminate\Contracts\Events\Dispatcher.
* IN THIS STEP WE JUST DECLARE ALIASES AND THE ACTUAL DEFINITION BIND TO SERVICE CONTAINER IN SERVICE PROVIDERS
* aliases property in config/app.php is far different from this and its for using without declare use statement and just prepend it with back slash
5. set concrete classes for http and console kernel contracts in service container as singleton
6. create request from php super globals variables like $_GET
7. handle request and creating response by kernel
1. define middlewarePriority, middlewareGroups, routeMiddleware(just name alias) for router
2. make current request object as instance in service container
3. bootstrap kernel → bootstrap application with bootstrappers array (LoadEnvironmentVariables - LoadConfiguration - HandleExceptions - RegisterFacades - RegisterProviders - BootProviders)
1. dispatch "bootstrapping: [bootstrapper name]" event
2. make bootstrapper with help of service container and then call bootstrap method of it
3. dispatch "bootstrapped: [bootstrapper name]" event
* RegisterProviders :
1. load all service providers from config
2. call register method on them
3. read "bindings" property of each service provider if exists and bind its key/value in service container
4. read "singletons" property of each service provider if exists and make its key/value as singleton in service container
* BootProviders :
1. fire app's "bootingCallbacks" and path application instance to it
2. for each service provider in app iterate over its "bootingCallbacks" and call it with help of service container
3. for each service provider in app call its boot method if exists
4. for each service provider in app iterate over its "bootedCallbacks" and call it with help of service container
5. set app as booted
6. fire app's "bootedCallbacks" and path application instance to it
* we can add "bootingCallbacks" to app by calling its booting method with callback (maybe in service provider)
* we can add "bootedCallbacks" to app by calling its booted method with callback (maybe in service provider)
4. pass request through middlewares and then dispatch it to router
5. report and then render exception if occur
6. dispatch RequestHandled::class event that has request and response object
8. sending response
9. terminate kernel
1. call the terminate method on any terminable middleware
2. for each "terminatingCallbacks" in app call it with help of service container
* we can add "terminatingCallbacks" to app by calling its terminating method with callback (maybe in service provider)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment