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.
string
Default class name for new event objects.
Cake\Event\EventManagerInterface|null
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
string
Cake\Core\ContainerInterface|null
Container
Cake\Http\ControllerFactoryInterface|null
Controller factory
Cake\Core\PluginCollection
Plugin Collection
Constructor
Add an optional plugin
Add a plugin to the loaded plugin set.
Load all the application configuration and bootstrap logic.
Build the service container
Define the console commands for an application.
Wrapper for creating and dispatching events.
Get the dependency injection container for the application.
Returns the Cake\Event\EventManager manager instance for this object.
Get the plugin collection in use.
Invoke the application.
Define the HTTP middleware layers for an application.
Run bootstrap logic for loaded plugins.
Run console hooks for plugins
Run middleware hooks for plugins
Run routes hooks for loaded plugins
Define the routes for an application.
Register application container services.
Returns the Cake\Event\EventManagerInterface instance for this object.
__construct(string $configDir, Cake\Event\EventManagerInterface|null $eventManager = null, Cake\Http\ControllerFactoryInterface|null $controllerFactory = null)
Constructor
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(Cake\Core\PluginInterface|string $name, array<string, mixed> $config = []): $this
Add an optional plugin
If it isn't available, ignore it.
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
$this
addPlugin(Cake\Core\PluginInterface|string $name, array<string, mixed> $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.
Cake\Core\PluginInterface|string
$name array<string, mixed>
$config optional $this
bootstrap(): void
Load all the application configuration and bootstrap logic.
Override this method to add additional bootstrap logic for your application.
void
buildContainer(): Cake\Core\ContainerInterface
Build the service container
Override this method if you need to use a custom container or want to change how the container is built.
Cake\Core\ContainerInterface
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.
Cake\Console\CommandCollection
$commands The CommandCollection to add commands into.
Cake\Console\CommandCollection
dispatchEvent(string $name, array|null $data = null, object|null $subject = null): Cake\Event\EventInterface
Wrapper for creating and dispatching events.
Returns a dispatched event.
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).
Cake\Event\EventInterface
getContainer(): Cake\Core\ContainerInterface
Get the dependency injection container for the application.
The first time the container is fetched it will be constructed and stored for future calls.
Cake\Core\ContainerInterface
getEventManager(): Cake\Event\EventManagerInterface
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.
Cake\Event\EventManagerInterface
getPlugins(): Cake\Core\PluginCollection
Get the plugin collection in use.
Cake\Core\PluginCollection
handle(ServerRequestInterface $request): Psr\Http\Message\ResponseInterface
Invoke the application.
ServerRequestInterface
$request The request
Psr\Http\Message\ResponseInterface
middleware(Cake\Http\MiddlewareQueue $middlewareQueue): Cake\Http\MiddlewareQueue
Define the HTTP middleware layers for an application.
Cake\Http\MiddlewareQueue
$middlewareQueue The middleware queue to set in your App Class
Cake\Http\MiddlewareQueue
pluginBootstrap(): void
Run bootstrap logic for loaded plugins.
void
pluginConsole(Cake\Console\CommandCollection $commands): Cake\Console\CommandCollection
Run console hooks for plugins
Cake\Console\CommandCollection
$commands Cake\Console\CommandCollection
pluginMiddleware(Cake\Http\MiddlewareQueue $middleware): Cake\Http\MiddlewareQueue
Run middleware hooks for plugins
Cake\Http\MiddlewareQueue
$middleware Cake\Http\MiddlewareQueue
pluginRoutes(Cake\Routing\RouteBuilder $routes): Cake\Routing\RouteBuilder
Run routes hooks for loaded plugins
Cake\Routing\RouteBuilder
$routes Cake\Routing\RouteBuilder
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.
Cake\Routing\RouteBuilder
$routes A route builder to add routes into.
void
services(Cake\Core\ContainerInterface $container): void
Register 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.
Cake\Core\ContainerInterface
$container The Container to update.
void
setEventManager(Cake\Event\EventManagerInterface $eventManager): $this
Returns 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.
Cake\Event\EventManagerInterface
$eventManager the eventManager to set
$this
Default class name for new event objects.
string
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
Cake\Event\EventManagerInterface|null
string
Container
Cake\Core\ContainerInterface|null
Controller factory
Cake\Http\ControllerFactoryInterface|null
Plugin Collection
Cake\Core\PluginCollection
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.Http.BaseApplication.html