类 BasePlugin
基本插件类
每个插件都应该扩展此类或实现接口,并在其 src 根文件夹中包含一个插件类。
        
    命名空间: Cake\Core
    
    
    
      
        常量
- 
          
          list<string>VALID_HOOKS ¶['bootstrap', 'console', 'middleware', 'routes', 'services', 'events']有效的钩子列表。 
属性概要
- 
        $bootstrapEnabled protectedbool是否执行引导 
- 
        $classPath protectedstring|null此插件的类路径。 
- 
        $configPath protectedstring|null此插件的配置路径。 
- 
        $consoleEnabled protectedbool控制台中间件 
- 
        $eventsEnabled protectedbool是否加载事件 
- 
        $middlewareEnabled protectedbool启用中间件 
- 
        $name protectedstring|null此插件的名称 
- 
        $path protectedstring|null此插件的路径。 
- 
        $routesEnabled protectedbool是否加载路由 
- 
        $servicesEnabled protectedbool注册容器服务 
- 
        $templatePath protectedstring|null此插件的模板路径。 
方法概要
- 
          __construct() public构造函数 
- 
          bootstrap() public加载所有应用程序配置和引导逻辑。 
- 
          checkHook() protected检查钩子名称是否有效 
- 
          console() public为插件添加控制台命令。 
- 
          disable() public禁用指定的钩子 
- 
          enable() public启用指定的钩子 
- 
          events() public注册应用程序事件。 
- 
          getClassPath() public获取此插件的配置的系统路径 
- 
          getConfigPath() public获取此插件的配置的系统路径 
- 
          getName() public获取此插件的名称。 
- 
          getPath() public获取此插件的系统路径 
- 
          getTemplatePath() public获取此插件的模板的系统路径 
- 
          initialize() public从构造函数调用的初始化钩子。 
- 
          isEnabled() public检查指定的钩子是否已启用 
- 
          middleware() public为插件添加中间件。 
- 
          routes() public为插件添加路由。 
- 
          services() public为该插件注册容器服务。 
方法详情
__construct() ¶ public
__construct(array<string, mixed> $options = [])构造函数
参数
- 
                array<string, mixed>$options optional
- 选项 
bootstrap() ¶ public
bootstrap(Cake\Core\PluginApplicationInterface $app): void加载所有应用程序配置和引导逻辑。
此方法的默认实现将在插件中包含 config/bootstrap.php(如果存在)。您可以覆盖此方法来替换该行为。
主机应用程序作为参数提供。这允许您加载其他插件依赖项或附加事件。
参数
- 
                Cake\Core\PluginApplicationInterface$app
返回值
voidcheckHook() ¶ protected
checkHook(string $hook): void检查钩子名称是否有效
参数
- 
                string$hook
- 要检查的钩子名称 
返回值
void抛出
InvalidArgumentException针对无效的钩子
console() ¶ public
console(Cake\Console\CommandCollection $commands): Cake\Console\CommandCollection为插件添加控制台命令。
参数
- 
                Cake\Console\CommandCollection$commands
返回值
Cake\Console\CommandCollectionevents() ¶ public
events(Cake\Event\EventManagerInterface $eventManager): Cake\Event\EventManagerInterface注册应用程序事件。
参数
- 
                Cake\Event\EventManagerInterface$eventManager
- 用于注册监听器的全局事件管理器 
返回值
Cake\Event\EventManagerInterfacemiddleware() ¶ public
middleware(Cake\Http\MiddlewareQueue $middlewareQueue): Cake\Http\MiddlewareQueue为插件添加中间件。
参数
- 
                Cake\Http\MiddlewareQueue$middlewareQueue
返回值
Cake\Http\MiddlewareQueueroutes() ¶ public
routes(Cake\Routing\RouteBuilder $routes): void为插件添加路由。
此方法的默认实现将在插件中包含 config/routes.php(如果存在)。您可以覆盖此方法来替换该行为。
参数
- 
                Cake\Routing\RouteBuilder$routes
返回值
voidservices() ¶ public
services(Cake\Core\ContainerInterface $container): void为该插件注册容器服务。
参数
- 
                Cake\Core\ContainerInterface$container
- 要添加服务的容器。 
返回值
void