Application¶

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:

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. Add the _cake_routes_ cache definition to config/app.php, if it is not already there.
  5. Update config/bootstrap.php and config/bootstrap_cli.php as per the app_skeleton, being careful to preserve whatever additions and changes are specific to your application. The bootstrap.php updates include
  6. Update the contents of the files in bin. Replace the files with the versions from the app skeleton.
  7. If you are using the CsrfProtectionMiddleware make sure you remove the CsrfComponent from your controllers.

Once those 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.