Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,19 +2,18 @@
/**
* CakePlugin class
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Core
* @since CakePHP(tm) v 2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
@ -34,32 +33,54 @@ class CakePlugin {
protected static $_plugins = array();
/**
* Loads a plugin and optionally loads bootstrapping, routing files or loads a initialization function
* Loads a plugin and optionally loads bootstrapping, routing files or loads an 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
* `CakePlugin::load('DebugKit')`
*
* Bootstrap initialization functions can be expressed as a PHP callback type, including closures. Callbacks will receive two
* parameters (plugin name, plugin configuration)
* 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', '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
* Will only load the bootstrap for ApiGenerator and only the routes for DebugKit.
* By using the `path` option you can specify an absolute path to the plugin. Make
* sure that the path is slash terminated or your plugin will not be located properly.
*
* @param string|array $plugin name of the plugin to be loaded in CamelCase format or array or plugins to load
* @param array $config configuration options for the plugin
@ -70,34 +91,34 @@ class CakePlugin {
if (is_array($plugin)) {
foreach ($plugin as $name => $conf) {
list($name, $conf) = (is_numeric($name)) ? array($conf, $config) : array($name, $conf);
self::load($name, $conf);
static::load($name, $conf);
}
return;
}
$config += array('bootstrap' => false, 'routes' => false);
$config += array('bootstrap' => false, 'routes' => false, 'ignoreMissing' => false);
if (empty($config['path'])) {
foreach (App::path('plugins') as $path) {
if (is_dir($path . $plugin)) {
self::$_plugins[$plugin] = $config + array('path' => $path . $plugin . DS);
static::$_plugins[$plugin] = $config + array('path' => $path . $plugin . DS);
break;
}
//Backwards compatibility to make easier to migrate to 2.0
$underscored = Inflector::underscore($plugin);
if (is_dir($path . $underscored)) {
self::$_plugins[$plugin] = $config + array('path' => $path . $underscored . DS);
static::$_plugins[$plugin] = $config + array('path' => $path . $underscored . DS);
break;
}
}
} else {
self::$_plugins[$plugin] = $config;
static::$_plugins[$plugin] = $config;
}
if (empty(self::$_plugins[$plugin]['path'])) {
if (empty(static::$_plugins[$plugin]['path'])) {
throw new MissingPluginException(array('plugin' => $plugin));
}
if (!empty(self::$_plugins[$plugin]['bootstrap'])) {
self::bootstrap($plugin);
if (!empty(static::$_plugins[$plugin]['bootstrap'])) {
static::bootstrap($plugin);
}
}
@ -106,27 +127,40 @@ class CakePlugin {
* 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),
* array('bootstrap' => true),
* 'DebugKit' => array('routes' => true, 'bootstrap' => false),
* ))
* }}}
* ```
*
* 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.
* 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 you are loading
* many plugins that inconsistently support routes/bootstrap files, instead of detailing
* each plugin you can use the `ignoreMissing` option:
*
* @param array $options
* ```
* CakePlugin::loadAll(array(
* 'ignoreMissing' => true,
* 'bootstrap' => true,
* 'routes' => true,
* ));
* ```
*
* The ignoreMissing option will do additional file_exists() calls but is simpler
* to use.
*
* @param array $options Options list. See CakePlugin::load() for valid options.
* @return void
*/
public static function loadAll($options = array()) {
$plugins = App::objects('plugins');
foreach ($plugins as $p) {
$opts = isset($options[$p]) ? $options[$p] : null;
if ($opts === null && isset($options[0])) {
$opts = $options[0];
$opts = isset($options[$p]) ? (array)$options[$p] : array();
if (isset($options[0])) {
$opts += $options[0];
}
self::load($p, (array)$opts);
static::load($p, $opts);
}
}
@ -138,10 +172,10 @@ class CakePlugin {
* @throws MissingPluginException if the folder for plugin was not found or plugin has not been loaded
*/
public static function path($plugin) {
if (empty(self::$_plugins[$plugin])) {
if (empty(static::$_plugins[$plugin])) {
throw new MissingPluginException(array('plugin' => $plugin));
}
return self::$_plugins[$plugin]['path'];
return static::$_plugins[$plugin]['path'];
}
/**
@ -152,7 +186,7 @@ class CakePlugin {
* @see CakePlugin::load() for examples of bootstrap configuration
*/
public static function bootstrap($plugin) {
$config = self::$_plugins[$plugin];
$config = static::$_plugins[$plugin];
if ($config['bootstrap'] === false) {
return false;
}
@ -160,14 +194,20 @@ class CakePlugin {
return call_user_func_array($config['bootstrap'], array($plugin, $config));
}
$path = self::path($plugin);
$path = static::path($plugin);
if ($config['bootstrap'] === true) {
return include $path . 'Config' . DS . 'bootstrap.php';
return static::_includeFile(
$path . 'Config' . DS . 'bootstrap.php',
$config['ignoreMissing']
);
}
$bootstrap = (array)$config['bootstrap'];
foreach ($bootstrap as $file) {
include $path . 'Config' . DS . $file . '.php';
static::_includeFile(
$path . 'Config' . DS . $file . '.php',
$config['ignoreMissing']
);
}
return true;
@ -178,35 +218,38 @@ class CakePlugin {
*
* @param string $plugin name of the plugin, if null will operate on all plugins having enabled the
* loading of routes files
* @return boolean
* @return bool
*/
public static function routes($plugin = null) {
if ($plugin === null) {
foreach (self::loaded() as $p) {
self::routes($p);
foreach (static::loaded() as $p) {
static::routes($p);
}
return true;
}
$config = self::$_plugins[$plugin];
$config = static::$_plugins[$plugin];
if ($config['routes'] === false) {
return false;
}
return (bool)include self::path($plugin) . 'Config' . DS . 'routes.php';
return (bool)static::_includeFile(
static::path($plugin) . 'Config' . DS . 'routes.php',
$config['ignoreMissing']
);
}
/**
* Returns true if the plugin $plugin is already loaded
* If plugin is null, it will return a list of all loaded plugins
*
* @param string $plugin
* @param string $plugin Plugin name to check.
* @return mixed boolean true if $plugin is already loaded.
* If $plugin is null, returns a list of plugins that have been loaded
*/
public static function loaded($plugin = null) {
if ($plugin) {
return isset(self::$_plugins[$plugin]);
return isset(static::$_plugins[$plugin]);
}
$return = array_keys(self::$_plugins);
$return = array_keys(static::$_plugins);
sort($return);
return $return;
}
@ -218,11 +261,25 @@ class CakePlugin {
* @return void
*/
public static function unload($plugin = null) {
if (is_null($plugin)) {
self::$_plugins = array();
if ($plugin === null) {
static::$_plugins = array();
} else {
unset(self::$_plugins[$plugin]);
unset(static::$_plugins[$plugin]);
}
}
/**
* Include file, ignoring include error if needed if file is missing
*
* @param string $file File to include
* @param bool $ignoreMissing Whether to ignore include error for missing files
* @return mixed
*/
protected static function _includeFile($file, $ignoreMissing = false) {
if ($ignoreMissing && !is_file($file)) {
return false;
}
return include $file;
}
}