CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.6 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.6
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
      • Client
      • Cookie
      • Exception
      • Middleware
      • Session
      • TestSuite
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

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.

Abstract
Namespace: Cake\Http

Property Summary

  • $_eventClass protected
    string

    Default class name for new event objects.

  • $_eventManager protected
    Cake\Event\EventManagerInterface|null

    Instance of the Cake\Event\EventManager this object is using to dispatch inner events.

  • $configDir protected
    string
  • $container protected
    Cake\Core\ContainerInterface|null

    Container

  • $controllerFactory protected
    Cake\Http\ControllerFactoryInterface|null

    Controller factory

  • $plugins protected
    Cake\Core\PluginCollection

    Plugin Collection

Method Summary

  • __construct() public

    Constructor

  • 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.

  • buildContainer() protected

    Build the service container

  • console() public

    Define the console commands for an application.

  • dispatchEvent() public

    Wrapper for creating and dispatching events.

  • getContainer() public

    Get the dependency injection container for the application.

  • getEventManager() public

    Returns the Cake\Event\EventManager manager instance for this object.

  • getPlugins() public

    Get the plugin collection in use.

  • handle() public

    Invoke the application.

  • 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.

  • services() public

    Register application container services.

  • setEventManager() public

    Returns 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 = []): $this

Add 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
$this

addPlugin() ¶ public

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.

Parameters
Cake\Core\PluginInterface|string $name
array<string, mixed> $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

buildContainer() ¶ protected

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.

Returns
Cake\Core\ContainerInterface

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\EventInterface

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\EventInterface

getContainer() ¶ public

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.

Returns
Cake\Core\ContainerInterface

getEventManager() ¶ public

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.

Returns
Cake\Event\EventManagerInterface

getPlugins() ¶ public

getPlugins(): Cake\Core\PluginCollection

Get the plugin collection in use.

Returns
Cake\Core\PluginCollection

handle() ¶ public

handle(ServerRequestInterface $request): Psr\Http\Message\ResponseInterface

Invoke 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\ResponseInterface

middleware() ¶ abstract public

middleware(Cake\Http\MiddlewareQueue $middlewareQueue): Cake\Http\MiddlewareQueue

Define the HTTP middleware layers for an application.

Parameters
Cake\Http\MiddlewareQueue $middlewareQueue

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

services() ¶ public

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.

Parameters
Cake\Core\ContainerInterface $container

The Container to update.

Returns
void

setEventManager() ¶ public

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.

Parameters
Cake\Event\EventManagerInterface $eventManager

the eventManager to set

Returns
$this

Property Detail

$_eventClass ¶ protected

Default class name for new event objects.

Type
string

$_eventManager ¶ protected

Instance of the Cake\Event\EventManager this object is using to dispatch inner events.

Type
Cake\Event\EventManagerInterface|null

$configDir ¶ protected

Type
string

$container ¶ protected

Container

Type
Cake\Core\ContainerInterface|null

$controllerFactory ¶ protected

Controller factory

Type
Cake\Http\ControllerFactoryInterface|null

$plugins ¶ protected

Plugin Collection

Type
Cake\Core\PluginCollection
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs