Class BaseApplication
Base class for application classes.
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 protected
string
Default class name for new event objects.
-
$_eventManager protected
Cake\Event\EventManagerInterface|Cake\Event\EventManager
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
-
$configDir protected
string
-
$plugins protected
Cake\Core\PluginCollection
Plugin Collection
Method Summary
-
__construct() public
Constructor
-
__invoke() public
Invoke the application.
-
addOptionalPlugin() public
Add an optional plugin
-
addPlugin() public
Add a plugin to the loaded plugin set.
-
bootstrap() public
Load all the application configuration and bootstrap logic.
-
console() public
Define the console commands for an application.
-
dispatchEvent() public
Wrapper for creating and dispatching events.
-
eventManager() public deprecated
Returns the Cake\Event\EventManager manager instance for this object.
-
getDispatcher() protected
Get the ActionDispatcher.
-
getEventManager() public
Returns the Cake\Event\EventManager manager instance for this object.
-
getPlugins() public
Get the plugin collection in use.
-
makePlugin() protected
Create a plugin instance from a classname and configuration
-
middleware() abstract public
Define the HTTP middleware layers for an application.
-
pluginBootstrap() public
Run bootstrap logic for loaded plugins.
-
pluginConsole() public
Run console hooks for plugins
-
pluginMiddleware() public
Run middleware hooks for plugins
-
pluginRoutes() public
Run routes hooks for loaded plugins
-
routes() public
Define the routes for an application.
-
setEventManager() public
Returns the Cake\Event\EventManager manager instance for this object.
Method Detail
__construct() ¶ public
__construct(string $configDir, Cake\Event\EventManagerInterface $eventManager = null)
Constructor
Parameters
-
string
$configDir The directory the bootstrap configuration is held in.
-
Cake\Event\EventManagerInterface
$eventManager optional Application event manager instance.
__invoke() ¶ public
__invoke(Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next): Psr\Http\Message\ResponseInterface
Invoke the application.
- Convert the PSR response into CakePHP equivalents.
- Create the controller that will handle this request.
- Invoke the controller.
Parameters
-
Psr\Http\Message\ServerRequestInterface
$request The request
-
Psr\Http\Message\ResponseInterface
$response The response
-
callable
$next The next middleware
Returns
Psr\Http\Message\ResponseInterface
addOptionalPlugin() ¶ public
addOptionalPlugin(string|Cake\Core\PluginInterface $name, array $config = []): $this
Add an optional plugin
If it isn't available, ignore it.
Parameters
-
string|Cake\Core\PluginInterface
$name The plugin name or plugin object.
-
array
$config optional The configuration data for the plugin if using a string for $name
Returns
$this
addPlugin() ¶ public
addPlugin(string|Cake\Core\PluginInterface $name, array $config = []): $this
Add 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
-
string|Cake\Core\PluginInterface
$name -
array
$config optional
Returns
$this
bootstrap() ¶ public
bootstrap(): void
Load all the application configuration and bootstrap logic.
Override this method to add additional bootstrap logic for your application.
Returns
void
console() ¶ public
console(Cake\Console\CommandCollection $commands): Cake\Console\CommandCollection
Define 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\CommandCollection
dispatchEvent() ¶ public
dispatchEvent(string $name, array|null $data = null, object|null $subject = null): Cake\Event\Event
Wrapper 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\Event
eventManager() ¶ public
eventManager(Cake\Event\EventManager|null $eventManager = null): Cake\Event\EventManager
Returns 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.
Parameters
-
Cake\Event\EventManager|null
$eventManager optional the eventManager to set
Returns
Cake\Event\EventManager
getDispatcher() ¶ protected
getDispatcher(): Cake\Http\ActionDispatcher
Get the ActionDispatcher.
Returns
Cake\Http\ActionDispatcher
getEventManager() ¶ public
getEventManager(): Cake\Event\EventManager
Returns 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\EventManager
getPlugins() ¶ public
getPlugins(): Cake\Core\PluginCollection
Get the plugin collection in use.
Returns
Cake\Core\PluginCollection
makePlugin() ¶ protected
makePlugin(string $name, array $config): Cake\Core\PluginInterface
Create a plugin instance from a classname and configuration
Parameters
-
string
$name The plugin classname
-
array
$config Configuration options for the plugin
Returns
Cake\Core\PluginInterface
middleware() ¶ abstract public
middleware(Cake\Http\MiddlewareQueue $middleware): Cake\Http\MiddlewareQueue
Define the HTTP middleware layers for an application.
Parameters
-
Cake\Http\MiddlewareQueue
$middleware The middleware queue to set in your App Class
Returns
Cake\Http\MiddlewareQueue
pluginBootstrap() ¶ public
pluginBootstrap(): void
Run bootstrap logic for loaded plugins.
Returns
void
pluginConsole() ¶ public
pluginConsole(Cake\Console\CommandCollection $commands): Cake\Console\CommandCollection
Run console hooks for plugins
Parameters
-
Cake\Console\CommandCollection
$commands
Returns
Cake\Console\CommandCollection
pluginMiddleware() ¶ public
pluginMiddleware(Cake\Http\MiddlewareQueue $middleware): Cake\Http\MiddlewareQueue
Run middleware hooks for plugins
Parameters
-
Cake\Http\MiddlewareQueue
$middleware
Returns
Cake\Http\MiddlewareQueue
pluginRoutes() ¶ public
pluginRoutes(Cake\Routing\RouteBuilder $routes): Cake\Routing\RouteBuilder
Run routes hooks for loaded plugins
Parameters
-
Cake\Routing\RouteBuilder
$routes
Returns
Cake\Routing\RouteBuilder
routes() ¶ public
routes(Cake\Routing\RouteBuilder $routes): void
Define 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
void
setEventManager() ¶ public
setEventManager(Cake\Event\EventManager $eventManager): $this
Returns 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.
Parameters
-
Cake\Event\EventManager
$eventManager the eventManager to set
Returns
$this
Property Detail
$_eventManager ¶ protected
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
Type
Cake\Event\EventManagerInterface|Cake\Event\EventManager