Class BaseApplication
Base class for full-stack applications
This class serves as a base class for applications that are using CakePHP as a full stack framework. If you are only using the Http or Console libraries you should implement the relevant interfaces directly.
The application class is responsible for bootstrapping the application, and ensuring that middleware is attached. It is also invoked as the last piece of middleware, and delegates request/response handling to the correct controller.
Property Summary
- 
        $_eventClass protectedstringDefault class name for new event objects. 
- 
        $_eventManager protectedCake\Event\EventManagerInterface|nullInstance of the Cake\Event\EventManager this object is using to dispatch inner events. 
- 
        $configDir protectedstring
- 
        $container protectedCake\Core\ContainerInterface|nullContainer 
- 
        $controllerFactory protectedCake\Http\ControllerFactoryInterface|nullController factory 
- 
        $plugins protectedCake\Core\PluginCollectionPlugin Collection 
Method Summary
- 
          __construct() publicConstructor 
- 
          addOptionalPlugin() publicAdd an optional plugin 
- 
          addPlugin() publicAdd a plugin to the loaded plugin set. 
- 
          bootstrap() publicLoad all the application configuration and bootstrap logic. 
- 
          buildContainer() protectedBuild the service container 
- 
          console() publicDefine the console commands for an application. 
- 
          dispatchEvent() publicWrapper for creating and dispatching events. 
- 
          getContainer() publicGet the dependency injection container for the application. 
- 
          getEventManager() publicReturns the Cake\Event\EventManager manager instance for this object. 
- 
          getPlugins() publicGet the plugin collection in use. 
- 
          handle() publicInvoke the application. 
- 
          middleware() abstract publicDefine the HTTP middleware layers for an application. 
- 
          pluginBootstrap() publicRun bootstrap logic for loaded plugins. 
- 
          pluginConsole() publicRun console hooks for plugins 
- 
          pluginMiddleware() publicRun middleware hooks for plugins 
- 
          pluginRoutes() publicRun routes hooks for loaded plugins 
- 
          routes() publicDefine the routes for an application. 
- 
          services() publicRegister application container services. 
- 
          setEventManager() publicReturns the Cake\Event\EventManagerInterface instance for this object. 
Method Detail
__construct() ¶ public
__construct(string $configDir, Cake\Event\EventManagerInterface|null $eventManager = null, Cake\Http\ControllerFactoryInterface|null $controllerFactory = null)Constructor
Parameters
- 
                string$configDir
- The directory the bootstrap configuration is held in. 
- 
                Cake\Event\EventManagerInterface|null$eventManager optional
- Application event manager instance. 
- 
                Cake\Http\ControllerFactoryInterface|null$controllerFactory optional
- Controller factory. 
addOptionalPlugin() ¶ public
addOptionalPlugin(Cake\Core\PluginInterface|string $name, array<string, mixed> $config = []): $thisAdd an optional plugin
If it isn't available, ignore it.
Parameters
- 
                Cake\Core\PluginInterface|string$name
- The plugin name or plugin object. 
- 
                array<string, mixed>$config optional
- The configuration data for the plugin if using a string for $name 
Returns
$thisaddPlugin() ¶ public
addPlugin(Cake\Core\PluginInterface|string $name, array<string, mixed> $config = []): $thisAdd a plugin to the loaded plugin set.
If the named plugin does not exist, or does not define a Plugin class, an
instance of Cake\Core\BasePlugin will be used. This generated class will have
all plugin hooks enabled.
Parameters
- 
                Cake\Core\PluginInterface|string$name
- 
                array<string, mixed>$config optional
Returns
$thisbootstrap() ¶ public
bootstrap(): voidLoad all the application configuration and bootstrap logic.
Override this method to add additional bootstrap logic for your application.
Returns
voidbuildContainer() ¶ protected
buildContainer(): Cake\Core\ContainerInterfaceBuild the service container
Override this method if you need to use a custom container or want to change how the container is built.
Returns
Cake\Core\ContainerInterfaceconsole() ¶ public
console(Cake\Console\CommandCollection $commands): Cake\Console\CommandCollectionDefine the console commands for an application.
By default, all commands in CakePHP, plugins and the application will be loaded using conventions based names.
Parameters
- 
                Cake\Console\CommandCollection$commands
- The CommandCollection to add commands into. 
Returns
Cake\Console\CommandCollectionThe updated collection.
dispatchEvent() ¶ public
dispatchEvent(string $name, array|null $data = null, object|null $subject = null): Cake\Event\EventInterfaceWrapper for creating and dispatching events.
Returns a dispatched event.
Parameters
- 
                string$name
- Name of the event. 
- 
                array|null$data optional
- Any value you wish to be transported with this event to it can be read by listeners. 
- 
                object|null$subject optional
- The object that this event applies to ($this by default). 
Returns
Cake\Event\EventInterfacegetContainer() ¶ public
getContainer(): Cake\Core\ContainerInterfaceGet the dependency injection container for the application.
The first time the container is fetched it will be constructed and stored for future calls.
Returns
Cake\Core\ContainerInterfacegetEventManager() ¶ public
getEventManager(): Cake\Event\EventManagerInterfaceReturns the Cake\Event\EventManager manager instance for this object.
You can use this instance to register any new listeners or callbacks to the object events, or create your own events and trigger them at will.
Returns
Cake\Event\EventManagerInterfacegetPlugins() ¶ public
getPlugins(): Cake\Core\PluginCollectionGet the plugin collection in use.
Returns
Cake\Core\PluginCollectionhandle() ¶ public
handle(ServerRequestInterface $request): Psr\Http\Message\ResponseInterfaceInvoke the application.
- Add the request to the container, enabling its injection into other services.
- Create the controller that will handle this request.
- Invoke the controller.
Parameters
- 
                ServerRequestInterface$request
- The request 
Returns
Psr\Http\Message\ResponseInterfacemiddleware() ¶ abstract public
middleware(Cake\Http\MiddlewareQueue $middlewareQueue): Cake\Http\MiddlewareQueueDefine the HTTP middleware layers for an application.
Parameters
- 
                Cake\Http\MiddlewareQueue$middlewareQueue
- The middleware queue to set in your App Class 
Returns
Cake\Http\MiddlewareQueuepluginBootstrap() ¶ public
pluginBootstrap(): voidRun bootstrap logic for loaded plugins.
Returns
voidpluginConsole() ¶ public
pluginConsole(Cake\Console\CommandCollection $commands): Cake\Console\CommandCollectionRun console hooks for plugins
Parameters
- 
                Cake\Console\CommandCollection$commands
Returns
Cake\Console\CommandCollectionpluginMiddleware() ¶ public
pluginMiddleware(Cake\Http\MiddlewareQueue $middleware): Cake\Http\MiddlewareQueueRun middleware hooks for plugins
Parameters
- 
                Cake\Http\MiddlewareQueue$middleware
Returns
Cake\Http\MiddlewareQueuepluginRoutes() ¶ public
pluginRoutes(Cake\Routing\RouteBuilder $routes): Cake\Routing\RouteBuilderRun routes hooks for loaded plugins
Parameters
- 
                Cake\Routing\RouteBuilder$routes
Returns
Cake\Routing\RouteBuilderroutes() ¶ public
routes(Cake\Routing\RouteBuilder $routes): voidDefine the routes for an application.
By default, this will load config/routes.php for ease of use and backwards compatibility.
Parameters
- 
                Cake\Routing\RouteBuilder$routes
- A route builder to add routes into. 
Returns
voidservices() ¶ public
services(Cake\Core\ContainerInterface $container): voidRegister application container services.
Registered services can have instances fetched out of the container
using get(). Dependencies and parameters will be resolved based
on service definitions.
Parameters
- 
                Cake\Core\ContainerInterface$container
- The Container to update. 
Returns
voidsetEventManager() ¶ public
setEventManager(Cake\Event\EventManagerInterface $eventManager): $thisReturns the Cake\Event\EventManagerInterface instance for this object.
You can use this instance to register any new listeners or callbacks to the object events, or create your own events and trigger them at will.
Parameters
- 
                Cake\Event\EventManagerInterface$eventManager
- the eventManager to set 
Returns
$thisProperty Detail
$_eventManager ¶ protected
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
Type
Cake\Event\EventManagerInterface|null