Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/flow-flo.../libs/cakephp/core
File: Plugin.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
[2] Fix | Delete
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
[3] Fix | Delete
*
[4] Fix | Delete
* Licensed under The MIT License
[5] Fix | Delete
* For full copyright and license information, please see the LICENSE.txt
[6] Fix | Delete
* Redistributions of files must retain the above copyright notice.
[7] Fix | Delete
*
[8] Fix | Delete
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
[9] Fix | Delete
* @link https://cakephp.org CakePHP(tm) Project
[10] Fix | Delete
* @since 2.0.0
[11] Fix | Delete
* @license https://opensource.org/licenses/mit-license.php MIT License
[12] Fix | Delete
*/
[13] Fix | Delete
namespace Cake\Core;
[14] Fix | Delete
[15] Fix | Delete
use Cake\Core\Exception\MissingPluginException;
[16] Fix | Delete
use DirectoryIterator;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Plugin is used to load and locate plugins.
[20] Fix | Delete
*
[21] Fix | Delete
* It also can retrieve plugin paths and load their bootstrap and routes files.
[22] Fix | Delete
*
[23] Fix | Delete
* @link https://book.cakephp.org/3/en/plugins.html
[24] Fix | Delete
*/
[25] Fix | Delete
class Plugin
[26] Fix | Delete
{
[27] Fix | Delete
/**
[28] Fix | Delete
* Holds a list of all loaded plugins and their configuration
[29] Fix | Delete
*
[30] Fix | Delete
* @var \Cake\Core\PluginCollection|null
[31] Fix | Delete
*/
[32] Fix | Delete
protected static $plugins;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Class loader instance
[36] Fix | Delete
*
[37] Fix | Delete
* @var \Cake\Core\ClassLoader
[38] Fix | Delete
*/
[39] Fix | Delete
protected static $_loader;
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Loads a plugin and optionally loads bootstrapping,
[43] Fix | Delete
* routing files or runs an initialization function.
[44] Fix | Delete
*
[45] Fix | Delete
* Plugins only need to be loaded if you want bootstrapping/routes/cli commands to
[46] Fix | Delete
* be exposed. If your plugin does not expose any of these features you do not need
[47] Fix | Delete
* to load them.
[48] Fix | Delete
*
[49] Fix | Delete
* This method does not configure any autoloaders. That must be done separately either
[50] Fix | Delete
* through composer, or your own code during config/bootstrap.php.
[51] Fix | Delete
*
[52] Fix | Delete
* ### Examples:
[53] Fix | Delete
*
[54] Fix | Delete
* `Plugin::load('DebugKit')`
[55] Fix | Delete
*
[56] Fix | Delete
* Will load the DebugKit plugin and will not load any bootstrap nor route files.
[57] Fix | Delete
* However, the plugin will be part of the framework default routes, and have its
[58] Fix | Delete
* CLI tools (if any) available for use.
[59] Fix | Delete
*
[60] Fix | Delete
* `Plugin::load('DebugKit', ['bootstrap' => true, 'routes' => true])`
[61] Fix | Delete
*
[62] Fix | Delete
* Will load the bootstrap.php and routes.php files.
[63] Fix | Delete
*
[64] Fix | Delete
* `Plugin::load('DebugKit', ['bootstrap' => false, 'routes' => true])`
[65] Fix | Delete
*
[66] Fix | Delete
* Will load routes.php file but not bootstrap.php
[67] Fix | Delete
*
[68] Fix | Delete
* `Plugin::load('FOC/Authenticate')`
[69] Fix | Delete
*
[70] Fix | Delete
* Will load plugin from `plugins/FOC/Authenticate`.
[71] Fix | Delete
*
[72] Fix | Delete
* It is also possible to load multiple plugins at once. Examples:
[73] Fix | Delete
*
[74] Fix | Delete
* `Plugin::load(['DebugKit', 'ApiGenerator'])`
[75] Fix | Delete
*
[76] Fix | Delete
* Will load the DebugKit and ApiGenerator plugins.
[77] Fix | Delete
*
[78] Fix | Delete
* `Plugin::load(['DebugKit', 'ApiGenerator'], ['bootstrap' => true])`
[79] Fix | Delete
*
[80] Fix | Delete
* Will load bootstrap file for both plugins
[81] Fix | Delete
*
[82] Fix | Delete
* ```
[83] Fix | Delete
* Plugin::load([
[84] Fix | Delete
* 'DebugKit' => ['routes' => true],
[85] Fix | Delete
* 'ApiGenerator'
[86] Fix | Delete
* ],
[87] Fix | Delete
* ['bootstrap' => true])
[88] Fix | Delete
* ```
[89] Fix | Delete
*
[90] Fix | Delete
* Will only load the bootstrap for ApiGenerator and only the routes for DebugKit
[91] Fix | Delete
*
[92] Fix | Delete
* ### Configuration options
[93] Fix | Delete
*
[94] Fix | Delete
* - `bootstrap` - array - Whether or not you want the $plugin/config/bootstrap.php file loaded.
[95] Fix | Delete
* - `routes` - boolean - Whether or not you want to load the $plugin/config/routes.php file.
[96] Fix | Delete
* - `ignoreMissing` - boolean - Set to true to ignore missing bootstrap/routes files.
[97] Fix | Delete
* - `path` - string - The path the plugin can be found on. If empty the default plugin path (App.pluginPaths) will be used.
[98] Fix | Delete
* - `classBase` - The path relative to `path` which contains the folders with class files.
[99] Fix | Delete
* Defaults to "src".
[100] Fix | Delete
* - `autoload` - boolean - Whether or not you want an autoloader registered. This defaults to false. The framework
[101] Fix | Delete
* assumes you have configured autoloaders using composer. However, if your application source tree is made up of
[102] Fix | Delete
* plugins, this can be a useful option.
[103] Fix | Delete
*
[104] Fix | Delete
* @param string|array $plugin name of the plugin to be loaded in CamelCase format or array or plugins to load
[105] Fix | Delete
* @param array $config configuration options for the plugin
[106] Fix | Delete
* @throws \Cake\Core\Exception\MissingPluginException if the folder for the plugin to be loaded is not found
[107] Fix | Delete
* @return void
[108] Fix | Delete
* @deprecated 3.7.0 This method will be removed in 4.0.0. Use Application::addPlugin() instead.
[109] Fix | Delete
*/
[110] Fix | Delete
public static function load($plugin, array $config = [])
[111] Fix | Delete
{
[112] Fix | Delete
deprecationWarning(
[113] Fix | Delete
'Plugin::load() is deprecated. ' .
[114] Fix | Delete
'Use Application::addPlugin() instead. ' .
[115] Fix | Delete
'This method will be removed in 4.0.0.'
[116] Fix | Delete
);
[117] Fix | Delete
[118] Fix | Delete
if (is_array($plugin)) {
[119] Fix | Delete
foreach ($plugin as $name => $conf) {
[120] Fix | Delete
list($name, $conf) = is_numeric($name) ? [$conf, $config] : [$name, $conf];
[121] Fix | Delete
static::load($name, $conf);
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
return;
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
$config += [
[128] Fix | Delete
'autoload' => false,
[129] Fix | Delete
'bootstrap' => false,
[130] Fix | Delete
'routes' => false,
[131] Fix | Delete
'console' => true,
[132] Fix | Delete
'classBase' => 'src',
[133] Fix | Delete
'ignoreMissing' => false,
[134] Fix | Delete
'name' => $plugin,
[135] Fix | Delete
];
[136] Fix | Delete
[137] Fix | Delete
if (!isset($config['path'])) {
[138] Fix | Delete
$config['path'] = static::getCollection()->findPath($plugin);
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
$config['classPath'] = $config['path'] . $config['classBase'] . DIRECTORY_SEPARATOR;
[142] Fix | Delete
if (!isset($config['configPath'])) {
[143] Fix | Delete
$config['configPath'] = $config['path'] . 'config' . DIRECTORY_SEPARATOR;
[144] Fix | Delete
}
[145] Fix | Delete
$pluginClass = str_replace('/', '\\', $plugin) . '\\Plugin';
[146] Fix | Delete
if (class_exists($pluginClass)) {
[147] Fix | Delete
$instance = new $pluginClass($config);
[148] Fix | Delete
} else {
[149] Fix | Delete
// Use stub plugin as this method will be removed long term.
[150] Fix | Delete
$instance = new BasePlugin($config);
[151] Fix | Delete
}
[152] Fix | Delete
static::getCollection()->add($instance);
[153] Fix | Delete
[154] Fix | Delete
if ($config['autoload'] === true) {
[155] Fix | Delete
if (empty(static::$_loader)) {
[156] Fix | Delete
static::$_loader = new ClassLoader();
[157] Fix | Delete
static::$_loader->register();
[158] Fix | Delete
}
[159] Fix | Delete
static::$_loader->addNamespace(
[160] Fix | Delete
str_replace('/', '\\', $plugin),
[161] Fix | Delete
$config['path'] . $config['classBase'] . DIRECTORY_SEPARATOR
[162] Fix | Delete
);
[163] Fix | Delete
static::$_loader->addNamespace(
[164] Fix | Delete
str_replace('/', '\\', $plugin) . '\Test',
[165] Fix | Delete
$config['path'] . 'tests' . DIRECTORY_SEPARATOR
[166] Fix | Delete
);
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
if ($config['bootstrap'] === true) {
[170] Fix | Delete
static::bootstrap($plugin);
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Will load all the plugins located in the default plugin folder.
[176] Fix | Delete
*
[177] Fix | Delete
* If passed an options array, it will be used as a common default for all plugins to be loaded
[178] Fix | Delete
* It is possible to set specific defaults for each plugins in the options array. Examples:
[179] Fix | Delete
*
[180] Fix | Delete
* ```
[181] Fix | Delete
* Plugin::loadAll([
[182] Fix | Delete
* ['bootstrap' => true],
[183] Fix | Delete
* 'DebugKit' => ['routes' => true],
[184] Fix | Delete
* ]);
[185] Fix | Delete
* ```
[186] Fix | Delete
*
[187] Fix | Delete
* The above example will load the bootstrap file for all plugins, but for DebugKit it will only load the routes file
[188] Fix | Delete
* and will not look for any bootstrap script.
[189] Fix | Delete
*
[190] Fix | Delete
* If a plugin has been loaded already, it will not be reloaded by loadAll().
[191] Fix | Delete
*
[192] Fix | Delete
* @param array $options Options.
[193] Fix | Delete
* @return void
[194] Fix | Delete
* @throws \Cake\Core\Exception\MissingPluginException
[195] Fix | Delete
* @deprecated 3.7.0 This method will be removed in 4.0.0.
[196] Fix | Delete
*/
[197] Fix | Delete
public static function loadAll(array $options = [])
[198] Fix | Delete
{
[199] Fix | Delete
$plugins = [];
[200] Fix | Delete
foreach (App::path('Plugin') as $path) {
[201] Fix | Delete
if (!is_dir($path)) {
[202] Fix | Delete
continue;
[203] Fix | Delete
}
[204] Fix | Delete
$dir = new DirectoryIterator($path);
[205] Fix | Delete
foreach ($dir as $dirPath) {
[206] Fix | Delete
if ($dirPath->isDir() && !$dirPath->isDot()) {
[207] Fix | Delete
$plugins[] = $dirPath->getBasename();
[208] Fix | Delete
}
[209] Fix | Delete
}
[210] Fix | Delete
}
[211] Fix | Delete
if (Configure::check('plugins')) {
[212] Fix | Delete
$plugins = array_merge($plugins, array_keys(Configure::read('plugins')));
[213] Fix | Delete
$plugins = array_unique($plugins);
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
$collection = static::getCollection();
[217] Fix | Delete
foreach ($plugins as $p) {
[218] Fix | Delete
$opts = isset($options[$p]) ? $options[$p] : null;
[219] Fix | Delete
if ($opts === null && isset($options[0])) {
[220] Fix | Delete
$opts = $options[0];
[221] Fix | Delete
}
[222] Fix | Delete
if ($collection->has($p)) {
[223] Fix | Delete
continue;
[224] Fix | Delete
}
[225] Fix | Delete
static::load($p, (array)$opts);
[226] Fix | Delete
}
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
/**
[230] Fix | Delete
* Returns the filesystem path for a plugin
[231] Fix | Delete
*
[232] Fix | Delete
* @param string $name name of the plugin in CamelCase format
[233] Fix | Delete
* @return string path to the plugin folder
[234] Fix | Delete
* @throws \Cake\Core\Exception\MissingPluginException if the folder for plugin was not found or plugin has not been loaded
[235] Fix | Delete
*/
[236] Fix | Delete
public static function path($name)
[237] Fix | Delete
{
[238] Fix | Delete
$plugin = static::getCollection()->get($name);
[239] Fix | Delete
[240] Fix | Delete
return $plugin->getPath();
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
/**
[244] Fix | Delete
* Returns the filesystem path for plugin's folder containing class folders.
[245] Fix | Delete
*
[246] Fix | Delete
* @param string $name name of the plugin in CamelCase format.
[247] Fix | Delete
* @return string Path to the plugin folder containing class files.
[248] Fix | Delete
* @throws \Cake\Core\Exception\MissingPluginException If plugin has not been loaded.
[249] Fix | Delete
*/
[250] Fix | Delete
public static function classPath($name)
[251] Fix | Delete
{
[252] Fix | Delete
$plugin = static::getCollection()->get($name);
[253] Fix | Delete
[254] Fix | Delete
return $plugin->getClassPath();
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
/**
[258] Fix | Delete
* Returns the filesystem path for plugin's folder containing config files.
[259] Fix | Delete
*
[260] Fix | Delete
* @param string $name name of the plugin in CamelCase format.
[261] Fix | Delete
* @return string Path to the plugin folder containing config files.
[262] Fix | Delete
* @throws \Cake\Core\Exception\MissingPluginException If plugin has not been loaded.
[263] Fix | Delete
*/
[264] Fix | Delete
public static function configPath($name)
[265] Fix | Delete
{
[266] Fix | Delete
$plugin = static::getCollection()->get($name);
[267] Fix | Delete
[268] Fix | Delete
return $plugin->getConfigPath();
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
/**
[272] Fix | Delete
* Loads the bootstrapping files for a plugin, or calls the initialization setup in the configuration
[273] Fix | Delete
*
[274] Fix | Delete
* @param string $name name of the plugin
[275] Fix | Delete
* @return mixed
[276] Fix | Delete
* @see \Cake\Core\Plugin::load() for examples of bootstrap configuration
[277] Fix | Delete
* @deprecated 3.7.0 This method will be removed in 4.0.0.
[278] Fix | Delete
*/
[279] Fix | Delete
public static function bootstrap($name)
[280] Fix | Delete
{
[281] Fix | Delete
deprecationWarning(
[282] Fix | Delete
'Plugin::bootstrap() is deprecated. ' .
[283] Fix | Delete
'This method will be removed in 4.0.0.'
[284] Fix | Delete
);
[285] Fix | Delete
$plugin = static::getCollection()->get($name);
[286] Fix | Delete
if (!$plugin->isEnabled('bootstrap')) {
[287] Fix | Delete
return false;
[288] Fix | Delete
}
[289] Fix | Delete
// Disable bootstrapping for this plugin as it will have
[290] Fix | Delete
// been bootstrapped.
[291] Fix | Delete
$plugin->disable('bootstrap');
[292] Fix | Delete
[293] Fix | Delete
return static::_includeFile(
[294] Fix | Delete
$plugin->getConfigPath() . 'bootstrap.php',
[295] Fix | Delete
true
[296] Fix | Delete
);
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
/**
[300] Fix | Delete
* Loads the routes file for a plugin, or all plugins configured to load their respective routes file.
[301] Fix | Delete
*
[302] Fix | Delete
* If you need fine grained control over how routes are loaded for plugins, you
[303] Fix | Delete
* can use {@see \Cake\Routing\RouteBuilder::loadPlugin()}
[304] Fix | Delete
*
[305] Fix | Delete
* @param string|null $name name of the plugin, if null will operate on all
[306] Fix | Delete
* plugins having enabled the loading of routes files.
[307] Fix | Delete
* @return bool
[308] Fix | Delete
* @deprecated 3.6.5 This method is no longer needed when using HttpApplicationInterface based applications.
[309] Fix | Delete
* This method will be removed in 4.0.0
[310] Fix | Delete
*/
[311] Fix | Delete
public static function routes($name = null)
[312] Fix | Delete
{
[313] Fix | Delete
deprecationWarning(
[314] Fix | Delete
'You no longer need to call `Plugin::routes()` after upgrading to use Http\Server. ' .
[315] Fix | Delete
'See https://book.cakephp.org/3/en/development/application.html#adding-the-new-http-stack-to-an-existing-application ' .
[316] Fix | Delete
'for upgrade information.'
[317] Fix | Delete
);
[318] Fix | Delete
if ($name === null) {
[319] Fix | Delete
foreach (static::loaded() as $p) {
[320] Fix | Delete
static::routes($p);
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
return true;
[324] Fix | Delete
}
[325] Fix | Delete
$plugin = static::getCollection()->get($name);
[326] Fix | Delete
if (!$plugin->isEnabled('routes')) {
[327] Fix | Delete
return false;
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
return (bool)static::_includeFile(
[331] Fix | Delete
$plugin->getConfigPath() . 'routes.php',
[332] Fix | Delete
true
[333] Fix | Delete
);
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
/**
[337] Fix | Delete
* Check whether or not a plugin is loaded.
[338] Fix | Delete
*
[339] Fix | Delete
* @param string $plugin The name of the plugin to check.
[340] Fix | Delete
* @return bool
[341] Fix | Delete
* @since 3.7.0
[342] Fix | Delete
*/
[343] Fix | Delete
public static function isLoaded($plugin)
[344] Fix | Delete
{
[345] Fix | Delete
return static::getCollection()->has($plugin);
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
/**
[349] Fix | Delete
* Return a list of loaded plugins.
[350] Fix | Delete
*
[351] Fix | Delete
* If a plugin name is provided, the return value will be a bool
[352] Fix | Delete
* indicating whether or not the named plugin is loaded. This usage
[353] Fix | Delete
* is deprecated. Instead you should use Plugin::isLoaded($name)
[354] Fix | Delete
*
[355] Fix | Delete
* @param string|null $plugin Plugin name.
[356] Fix | Delete
* @return bool|array Boolean true if $plugin is already loaded.
[357] Fix | Delete
* If $plugin is null, returns a list of plugins that have been loaded
[358] Fix | Delete
*/
[359] Fix | Delete
public static function loaded($plugin = null)
[360] Fix | Delete
{
[361] Fix | Delete
if ($plugin !== null) {
[362] Fix | Delete
deprecationWarning(
[363] Fix | Delete
'Checking a single plugin with Plugin::loaded() is deprecated. ' .
[364] Fix | Delete
'Use Plugin::isLoaded() instead.'
[365] Fix | Delete
);
[366] Fix | Delete
[367] Fix | Delete
return static::getCollection()->has($plugin);
[368] Fix | Delete
}
[369] Fix | Delete
$names = [];
[370] Fix | Delete
foreach (static::getCollection() as $plugin) {
[371] Fix | Delete
$names[] = $plugin->getName();
[372] Fix | Delete
}
[373] Fix | Delete
sort($names);
[374] Fix | Delete
[375] Fix | Delete
return $names;
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
/**
[379] Fix | Delete
* Forgets a loaded plugin or all of them if first parameter is null
[380] Fix | Delete
*
[381] Fix | Delete
* @param string|null $plugin name of the plugin to forget
[382] Fix | Delete
* @deprecated 3.7.0 This method will be removed in 4.0.0. Use PluginCollection::remove() or clear() instead.
[383] Fix | Delete
* @return void
[384] Fix | Delete
*/
[385] Fix | Delete
public static function unload($plugin = null)
[386] Fix | Delete
{
[387] Fix | Delete
deprecationWarning('Plugin::unload() will be removed in 4.0. Use PluginCollection::remove() or clear()');
[388] Fix | Delete
if ($plugin === null) {
[389] Fix | Delete
static::getCollection()->clear();
[390] Fix | Delete
} else {
[391] Fix | Delete
static::getCollection()->remove($plugin);
[392] Fix | Delete
}
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
/**
[396] Fix | Delete
* Include file, ignoring include error if needed if file is missing
[397] Fix | Delete
*
[398] Fix | Delete
* @param string $file File to include
[399] Fix | Delete
* @param bool $ignoreMissing Whether to ignore include error for missing files
[400] Fix | Delete
* @return mixed
[401] Fix | Delete
*/
[402] Fix | Delete
protected static function _includeFile($file, $ignoreMissing = false)
[403] Fix | Delete
{
[404] Fix | Delete
if ($ignoreMissing && !is_file($file)) {
[405] Fix | Delete
return false;
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
return include $file;
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
/**
[412] Fix | Delete
* Get the shared plugin collection.
[413] Fix | Delete
*
[414] Fix | Delete
* This method should generally not be used during application
[415] Fix | Delete
* runtime as plugins should be set during Application startup.
[416] Fix | Delete
*
[417] Fix | Delete
* @return \Cake\Core\PluginCollection
[418] Fix | Delete
*/
[419] Fix | Delete
public static function getCollection()
[420] Fix | Delete
{
[421] Fix | Delete
if (!isset(static::$plugins)) {
[422] Fix | Delete
static::$plugins = new PluginCollection();
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
return static::$plugins;
[426] Fix | Delete
}
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function