diff --git a/lifecycle.md b/lifecycle.md index f569505da9a..99458ad267e 100644 --- a/lifecycle.md +++ b/lifecycle.md @@ -2,13 +2,13 @@ - [Overview](#overview) - [Request Lifecycle](#request-lifecycle) -- [Start Files](#start-files) +- [Service Providers](#service-providers) - [Application Events](#application-events) ## Overview -When using any tool in the "real world", you feel more confidence if you understand how that tool works. Application development is no different. When you understand how your development tools function, you feel more comfortable and confident using them. The goal of this document is to give you a good, high-level overview of how the Laravel framework "works". By getting to know the overall framework better, everything feels less "magical" and you will be more confident building your applications. In addition to a high-level overview of the request lifecycle, we'll cover "start" files and application events. +When using any tool in the "real world", you feel more confidence if you understand how that tool works. Application development is no different. When you understand how your development tools function, you feel more comfortable and confident using them. The goal of this document is to give you a good, high-level overview of how the Laravel framework "works". By getting to know the overall framework better, everything feels less "magical" and you will be more confident building your applications. In addition to a high-level overview of the request lifecycle, we'll cover service providers and application events. If you don't understand all of the terms right away, don't lose heart! Just try to get a basic grasp of what is going on, and your knowledge will grow as you explore other sections of the documentation. @@ -30,25 +30,24 @@ So, let's summarize: 1. Request enters `public/index.php` file. 2. `bootstrap/start.php` file creates Application and detects environment. 3. Internal `framework/start.php` file configures settings and loads service providers. -4. Application `app/start` files are loaded. -5. Application `app/routes.php` file is loaded. -6. Request object sent to Application, which returns Response object. -7. Response object sent back to client. +4. Application `app/routes.php` file is loaded. +5. Request object sent to Application, which returns Response object. +6. Response object sent back to client. -Now that you have a good idea of how a request to a Laravel application is handled, let's take a closer look at "start" files! +Now that you have a good idea of how a request to a Laravel application is handled, let's take a closer look at service providers! - -## Start Files + +## Service Providers -Your application's start files are stored at `app/start`. By default, three are included with your application: `global.php`, `local.php`, and `artisan.php`. For more information about `artisan.php`, refer to the documentation on the [Artisan command line](/docs/commands#registering-commands). +Your application's default service providers are stored at `app/src/Providers`. By default, several are shipped with your application, and handle things like setting up error handling, logging, etc. For more information about the `ArtisanServiceProvider`, refer to the documentation on the [Artisan command line](/docs/commands#registering-commands). -The `global.php` start file contains a few basic items by default, such as the registration of the [Logger](/docs/errors) and the inclusion of your `app/filters.php` file. However, you are free to add anything to this file that you wish. It will be automatically included on _every_ request to your application, regardless of environment. The `local.php` file, on the other hand, is only called when the application is executing in the `local` environment. For more information on environments, check out the [configuration](/docs/configuration) documentation. +By default, the `AppServiceProvider` is blank. This provider is a great place to add your application's own bootstrapping and IoC registrations. Of course, for large applications, you may wish to create several service providers, each with a more granular type of bootstrapping. For example, you might create an `EventsServiceProvider` that only registers event listeners. -Of course, if you have other environments in addition to `local`, you may create start files for those environments as well. They will be automatically included when your application is running in that environment. So, for example, if you have a `development` environment configured in your `bootstrap/environment.php` file, you may create a `app/start/development.php` file, which will be included when any requests enter the application in that environment. +> **Note:** Within a service provider, the Laravel application instance / IoC container may be accessed via `$this->app` or through the `App` [facade](/docs/facades). -### What To Place In Start Files +### What To Place In Service Providers -Start files serve as a simple place to place any "bootstrapping" code. For example, you could register a View composer, configure your logging preferences, set some PHP settings, etc. It's totally up to you. Of course, throwing all of your bootstrapping code into your start files can get messy. For large applications, or if you feel your start files are getting messy, consider moving some bootstrapping code into [service providers](/docs/ioc#service-providers). +Service providers serve as a simple place to place any "bootstrapping" code and [IoC container](/docs/ioc) bindings. For example, you could register a View composer, configure your logging preferences, set some PHP settings, etc. It's totally up to you. ## Application Events