The Application is the heart of your application. It controls how your application is configured, and what plugins, middleware, console commands and routes are included.

You can find your Application class at src/Application.php. By default it will be pretty slim and only define a few default Middleware. Applications can define the following hook methods:

  • bootstrap Used to load configuration files, define constants and other global functions. By default this will include config/bootstrap.php. This is the ideal place to load Plugins and global event listeners.
  • routes Used to load routes. By default this will include config/routes.php.
  • middleware Used to add middleware to your application.
  • console Used to add console commands to your application. By default this will automatically discover shells & commands in your application and all plugins.

Adding the new HTTP Stack to an Existing Application

Using the Application class and HTTP Middleware in an existing application requires a few changes to your code.

  1. First update your webroot/index.php. Copy the file contents from the app skeleton.
  2. Create an Application class. See the Using Middleware section above for how to do that. Or copy the example in the app skeleton.
  3. Create config/requirements.php if it doesn’t exist and add the contents from the app skeleton.
  4. If you are using the CsrfProtectionMiddleware make sure you remove the CsrfComponent from your controllers.

Once those three steps are complete, you are ready to start re-implementing any application/plugin dispatch filters as HTTP middleware.

If you are running tests you will also need to update your tests/bootstrap.php by copying the file contents from the app skeleton.