Class Plugin
Plugin is used to load and locate plugins.
It also can retrieve plugin paths and load their bootstrap and routes files.
Property Summary
Method Summary
- 
          _includeFile() protected staticInclude file, ignoring include error if needed if file is missing 
- 
          _loadConfig() protected staticLoad the plugin path configuration file. 
- 
          bootstrap() public staticLoads the bootstrapping files for a plugin, or calls the initialization setup in the configuration 
- 
          classPath() public staticReturns the filesystem path for plugin's folder containing class folders. 
- 
          configPath() public staticReturns the filesystem path for plugin's folder containing config files. 
- 
          load() public staticLoads a plugin and optionally loads bootstrapping, routing files or runs an initialization function. 
- 
          loadAll() public staticWill load all the plugins located in the default plugin folder. 
- 
          loaded() public staticReturns true if the plugin $plugin is already loaded If plugin is null, it will return a list of all loaded plugins 
- 
          path() public staticReturns the filesystem path for a plugin 
- 
          routes() public staticLoads the routes file for a plugin, or all plugins configured to load their respective routes file 
- 
          unload() public staticForgets a loaded plugin or all of them if first parameter is null 
Method Detail
_includeFile() ¶ protected static
_includeFile(string $file, bool $ignoreMissing = false): mixedInclude file, ignoring include error if needed if file is missing
Parameters
- 
                string$file
- File to include 
- 
                bool$ignoreMissing optional
- Whether to ignore include error for missing files 
Returns
mixed_loadConfig() ¶ protected static
_loadConfig(): voidLoad the plugin path configuration file.
Returns
voidbootstrap() ¶ public static
bootstrap(string $plugin): mixedLoads the bootstrapping files for a plugin, or calls the initialization setup in the configuration
Parameters
- 
                string$plugin
- name of the plugin 
Returns
mixedSee Also
classPath() ¶ public static
classPath(string $plugin): stringReturns the filesystem path for plugin's folder containing class folders.
Parameters
- 
                string$plugin
- name of the plugin in CamelCase format. 
Returns
stringPath to the plugin folder container class folders.
Throws
Cake\Core\Exception\MissingPluginExceptionIf plugin has not been loaded.
configPath() ¶ public static
configPath(string $plugin): stringReturns the filesystem path for plugin's folder containing config files.
Parameters
- 
                string$plugin
- name of the plugin in CamelCase format. 
Returns
stringPath to the plugin folder container config files.
Throws
Cake\Core\Exception\MissingPluginExceptionIf plugin has not been loaded.
load() ¶ public static
load(string|array $plugin, array $config = []): voidLoads a plugin and optionally loads bootstrapping, routing files or runs an initialization function.
Plugins only need to be loaded if you want bootstrapping/routes/cli commands to be exposed. If your plugin does not expose any of these features you do not need to load them.
This method does not configure any autoloaders. That must be done separately either through composer, or your own code during config/bootstrap.php.
Examples:
Plugin::load('DebugKit')
Will load the DebugKit plugin and will not load any bootstrap nor route files. However, the plugin will be part of the framework default routes, and have its CLI tools (if any) available for use.
Plugin::load('DebugKit', ['bootstrap' => true, 'routes' => true])
Will load the bootstrap.php and routes.php files.
Plugin::load('DebugKit', ['bootstrap' => false, 'routes' => true])
Will load routes.php file but not bootstrap.php
Plugin::load('FOC/Authenticate')
Will load plugin from plugins/FOC/Authenticate.
It is also possible to load multiple plugins at once. Examples:
Plugin::load(['DebugKit', 'ApiGenerator'])
Will load the DebugKit and ApiGenerator plugins.
Plugin::load(['DebugKit', 'ApiGenerator'], ['bootstrap' => true])
Will load bootstrap file for both plugins
  Plugin::load([
    'DebugKit' => ['routes' => true],
    'ApiGenerator'
    ],
    ['bootstrap' => true])Will only load the bootstrap for ApiGenerator and only the routes for DebugKit
Configuration options
- bootstrap- array - Whether or not you want the $plugin/config/bootstrap.php file loaded.
- routes- boolean - Whether or not you want to load the $plugin/config/routes.php file.
- ignoreMissing- boolean - Set to true to ignore missing bootstrap/routes files.
- path- string - The path the plugin can be found on. If empty the default plugin path (App.pluginPaths) will be used.
- classBase- The path relative to- pathwhich contains the folders with class files. Defaults to "src".
- autoload- boolean - Whether or not you want an autoloader registered. This defaults to false. The framework assumes you have configured autoloaders using composer. However, if your application source tree is made up of plugins, this can be a useful option.
Parameters
- 
                string|array$plugin
- name of the plugin to be loaded in CamelCase format or array or plugins to load 
- 
                array$config optional
- configuration options for the plugin 
Returns
voidThrows
Cake\Core\Exception\MissingPluginExceptionif the folder for the plugin to be loaded is not found
loadAll() ¶ public static
loadAll(array $options = []): voidWill load all the plugins located in the default plugin folder.
If passed an options array, it will be used as a common default for all plugins to be loaded It is possible to set specific defaults for each plugins in the options array. Examples:
 Plugin::loadAll([
     ['bootstrap' => true],
     'DebugKit' => ['routes' => true],
 ]);The above example will load the bootstrap file for all plugins, but for DebugKit it will only load the routes file and will not look for any bootstrap script.
If a plugin has been loaded already, it will not be reloaded by loadAll().
Parameters
- 
                array$options optional
- Options. 
Returns
voidloaded() ¶ public static
loaded(string $plugin = null): bool|arrayReturns true if the plugin $plugin is already loaded If plugin is null, it will return a list of all loaded plugins
Parameters
- 
                string$plugin optional
- Plugin name. 
Returns
bool|arrayBoolean true if $plugin is already loaded. If $plugin is null, returns a list of plugins that have been loaded
path() ¶ public static
path(string $plugin): stringReturns the filesystem path for a plugin
Parameters
- 
                string$plugin
- name of the plugin in CamelCase format 
Returns
stringpath to the plugin folder
Throws
Cake\Core\Exception\MissingPluginExceptionif the folder for plugin was not found or plugin has not been loaded
routes() ¶ public static
routes(string $plugin = null): boolLoads the routes file for a plugin, or all plugins configured to load their respective routes file
Parameters
- 
                string$plugin optional
- name of the plugin, if null will operate on all plugins having enabled the loading of routes files 
Returns
boolunload() ¶ public static
unload(string $plugin = null): voidForgets a loaded plugin or all of them if first parameter is null
Parameters
- 
                string$plugin optional
- name of the plugin to forget 
Returns
void