Class Plugin
Plugin class for CakePHP.
Constants
-
array<string>VALID_HOOKS ¶['bootstrap', 'console', 'middleware', 'routes', 'services', 'events']List of valid hooks.
Property Summary
-
$bootstrapEnabled protected
boolDo bootstrapping or not
-
$classPath protected
string|nullThe class path for this plugin.
-
$configPath protected
string|nullThe config path for this plugin.
-
$consoleEnabled protected
boolConsole middleware
-
$eventsEnabled protected
boolLoad events or not
-
$middlewareEnabled protected
boolEnable middleware
-
$name protected
string|nullThe name of this plugin
-
$path protected
string|nullThe path to this plugin.
-
$routesEnabled protected
boolLoad routes or not
-
$servicesEnabled protected
boolRegister container services
-
$templatePath protected
string|nullThe templates path for this plugin.
Method Summary
-
__construct() public
Constructor
-
bootstrap() public
Load all the application configuration and bootstrap logic.
-
checkHook() protected
Check if a hook name is valid
-
console() public
Add console commands for the plugin.
-
disable() public
Disables the named hook
-
enable() public
Enables the named hook
-
events() public
Register application events.
-
getClassPath() public
Get the filesystem path to configuration for this plugin
-
getConfigPath() public
Get the filesystem path to configuration for this plugin
-
getName() public
Get the name of this plugin.
-
getPath() public
Get the filesystem path to this plugin
-
getTemplatePath() public
Get the filesystem path to templates for this plugin
-
initialize() public
Initialization hook called from constructor.
-
isEnabled() public
Check if the named hook is enabled
-
middleware() public
Add middleware for the plugin.
-
routes() public
Add routes for the plugin.
-
services() public
Register container services for this plugin.
Method Detail
__construct() ¶ public
__construct(array<string, mixed> $options = [])
Constructor
Parameters
-
array<string, mixed>$options optional Options
bootstrap() ¶ public
bootstrap(Cake\Core\PluginApplicationInterface $app): void
Load all the application configuration and bootstrap logic.
The default implementation of this method will include the config/bootstrap.php in the plugin if it exist. You
can override this method to replace that behavior.
The host application is provided as an argument. This allows you to load additional plugin dependencies, or attach events.
Parameters
-
Cake\Core\PluginApplicationInterface$app
Returns
voidcheckHook() ¶ protected
checkHook(string $hook): void
Check if a hook name is valid
Parameters
-
string$hook The hook name to check
Returns
voidThrows
InvalidArgumentExceptionon invalid hooks
console() ¶ public
console(Cake\Console\CommandCollection $commands): Cake\Console\CommandCollection
Add console commands for the plugin.
Parameters
-
Cake\Console\CommandCollection$commands
Returns
Cake\Console\CommandCollectiondisable() ¶ public
disable(string $hook): $this
Disables the named hook
Parameters
-
string$hook
Returns
$thisenable() ¶ public
enable(string $hook): $this
Enables the named hook
Parameters
-
string$hook
Returns
$thisevents() ¶ public
events(Cake\Event\EventManagerInterface $eventManager): Cake\Event\EventManagerInterface
Register application events.
Parameters
-
Cake\Event\EventManagerInterface$eventManager The global event manager to register listeners on
Returns
Cake\Event\EventManagerInterfacegetClassPath() ¶ public
getClassPath(): string
Get the filesystem path to configuration for this plugin
Returns
stringgetConfigPath() ¶ public
getConfigPath(): string
Get the filesystem path to configuration for this plugin
Returns
stringgetTemplatePath() ¶ public
getTemplatePath(): string
Get the filesystem path to templates for this plugin
Returns
stringisEnabled() ¶ public
isEnabled(string $hook): bool
Check if the named hook is enabled
Parameters
-
string$hook
Returns
boolmiddleware() ¶ public
middleware(Cake\Http\MiddlewareQueue $middlewareQueue): Cake\Http\MiddlewareQueue
Add middleware for the plugin.
Parameters
-
Cake\Http\MiddlewareQueue$middlewareQueue
Returns
Cake\Http\MiddlewareQueueroutes() ¶ public
routes(Cake\Routing\RouteBuilder $routes): void
Add routes for the plugin.
The default implementation of this method will include the config/routes.php in the plugin if it exists. You
can override this method to replace that behavior.
Parameters
-
Cake\Routing\RouteBuilder$routes
Returns
voidservices() ¶ public
services(Cake\Core\ContainerInterface $container): void
Register container services for this plugin.
Parameters
-
Cake\Core\ContainerInterface$container The container to add services to.
Returns
void