Class CakePlugin
CakePlugin is responsible for loading and unloading plugins. It also can retrieve plugin paths and load their bootstrap and routes files.
Link: http://book.cakephp.org/2.0/en/plugins.html
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Core/CakePlugin.php
Properties summary
-
$_plugins
protected staticarray
Holds a list of all loaded plugins and their configuration
Method Summary
-
_includeFile() protected static
Include file, ignoring include error if needed if file is missing -
bootstrap() public static
Loads the bootstrapping files for a plugin, or calls the initialization setup in the configuration -
load() public static
Loads a plugin and optionally loads bootstrapping, routing files or loads a initialization function -
loadAll() public static
Will load all the plugins located in the configured plugins folders 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:
-
loaded() public static
Returns true if the plugin $plugin is already loaded If plugin is null, it will return a list of all loaded plugins
-
path() public static
Returns the filesystem path for a plugin -
routes() public static
Loads the routes file for a plugin, or all plugins configured to load their respective routes file -
unload() public static
Forgets a loaded plugin or all of them if first parameter is null
Method Detail
_includeFile() protected static ¶
_includeFile( string $file , boolean $ignoreMissing = false )
Include file, ignoring include error if needed if file is missing
Parameters
- string $file
- File to include
- boolean $ignoreMissing optional false
- Whether to ignore include error for missing files
Returns
bootstrap() public static ¶
bootstrap( string $plugin )
Loads the bootstrapping files for a plugin, or calls the initialization setup in the configuration
Parameters
- string $plugin
- name of the plugin
Returns
See
load() public static ¶
load( string|array $plugin , array $config = array() )
Loads a plugin and optionally loads bootstrapping, routing files or loads a initialization function
Examples:
`CakePlugin::load('DebugKit')` will load the DebugKit plugin and will not load any bootstrap nor route files
CakePlugin::load('DebugKit', array('bootstrap' => true, 'routes' => true))
will load the bootstrap.php and routes.php files
CakePlugin::load('DebugKit', array('bootstrap' => false, 'routes' => true))
will load routes.php file but not bootstrap.php
CakePlugin::load('DebugKit', array('bootstrap' => array('config1', 'config2')))
will load config1.php and config2.php files
CakePlugin::load('DebugKit', array('bootstrap' => 'aCallableMethod'))
will run the aCallableMethod function to initialize it
Bootstrap initialization functions can be expressed as a PHP callback type, including closures. Callbacks will receive two parameters (plugin name, plugin configuration)
It is also possible to load multiple plugins at once. Examples:
CakePlugin::load(array('DebugKit', 'ApiGenerator'))
will load the DebugKit and ApiGenerator plugins
CakePlugin::load(array('DebugKit', 'ApiGenerator'), array('bootstrap' => true))
will load bootstrap file for both plugins
{{{ CakePlugin::load(array( 'DebugKit' => array('routes' => true), 'ApiGenerator' ), array('bootstrap' => true)) }}}
Will only load the bootstrap for ApiGenerator and only the routes for DebugKit
Parameters
- string|array $plugin
- name of the plugin to be loaded in CamelCase format or array or plugins to load
- array $config optional array()
- configuration options for the plugin
Throws
loadAll() public static ¶
loadAll( array $options = array() )
Will load all the plugins located in the configured plugins folders 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:
{{{ CakePlugin::loadAll(array( array('bootstrap' => true), 'DebugKit' => array('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.
Parameters
- array $options optional array()
loaded() public static ¶
loaded( string $plugin = null )
Returns 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 null
Returns
boolean 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 )
Returns the filesystem path for a plugin
Parameters
- string $plugin
- name of the plugin in CamelCase format
Returns
path to the plugin folder
Throws
routes() public static ¶
routes( string $plugin = null )
Loads the routes file for a plugin, or all plugins configured to load their respective routes file
Parameters
- string $plugin optional null
name of the plugin, if null will operate on all plugins having enabled the loading of routes files