mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch '2.0' of github.com:cakephp/cakephp into 2.0
This commit is contained in:
commit
bd0a303c09
664 changed files with 1040 additions and 472 deletions
|
@ -63,7 +63,7 @@ class PhpReader implements ConfigReaderInterface {
|
||||||
list($plugin, $key) = pluginSplit($key);
|
list($plugin, $key) = pluginSplit($key);
|
||||||
|
|
||||||
if ($plugin) {
|
if ($plugin) {
|
||||||
$file = App::pluginPath($plugin) . 'config' . DS . $key;
|
$file = App::pluginPath($plugin) . 'Config' . DS . $key;
|
||||||
} else {
|
} else {
|
||||||
$file = $this->_path . $key;
|
$file = $this->_path . $key;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ class CommandListShell extends Shell {
|
||||||
$appShells = App::objects('Console/Command', null, false);
|
$appShells = App::objects('Console/Command', null, false);
|
||||||
$shellList = $this->_appendShells('app', $appShells, $shellList);
|
$shellList = $this->_appendShells('app', $appShells, $shellList);
|
||||||
|
|
||||||
$plugins = App::objects('plugin');
|
$plugins = CakePlugin::loaded();
|
||||||
foreach ($plugins as $plugin) {
|
foreach ($plugins as $plugin) {
|
||||||
$pluginShells = App::objects($plugin . '.Console/Command');
|
$pluginShells = App::objects($plugin . '.Console/Command');
|
||||||
$shellList = $this->_appendShells($plugin, $pluginShells, $shellList);
|
$shellList = $this->_appendShells($plugin, $pluginShells, $shellList);
|
||||||
|
@ -187,13 +187,13 @@ class CommandListShell extends Shell {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function _asXml($shellList) {
|
protected function _asXml($shellList) {
|
||||||
$plugins = App::objects('plugin');
|
$plugins = CakePlugin::loaded();
|
||||||
$shells = new SimpleXmlElement('<shells></shells>');
|
$shells = new SimpleXmlElement('<shells></shells>');
|
||||||
foreach ($shellList as $name => $location) {
|
foreach ($shellList as $name => $location) {
|
||||||
$source = current($location);
|
$source = current($location);
|
||||||
$callable = $name;
|
$callable = $name;
|
||||||
if (in_array($source, $plugins)) {
|
if (in_array($source, $plugins)) {
|
||||||
$callable = Inflector::underscore($source) . '.' . $name;
|
$callable = Inflector::camelize($source) . '.' . $name;
|
||||||
}
|
}
|
||||||
$shell = $shells->addChild('shell');
|
$shell = $shells->addChild('shell');
|
||||||
$shell->addAttribute('name', $name);
|
$shell->addAttribute('name', $name);
|
||||||
|
|
|
@ -440,7 +440,7 @@ class SchemaShell extends Shell {
|
||||||
);
|
);
|
||||||
$path = array(
|
$path = array(
|
||||||
'help' => __d('cake_console', 'Path to read and write schema.php'),
|
'help' => __d('cake_console', 'Path to read and write schema.php'),
|
||||||
'default' => CONFIGS . 'schema'
|
'default' => CONFIGS . 'Schema'
|
||||||
);
|
);
|
||||||
$file = array(
|
$file = array(
|
||||||
'help' => __d('cake_console', 'File name to read and write.'),
|
'help' => __d('cake_console', 'File name to read and write.'),
|
||||||
|
|
|
@ -64,7 +64,7 @@ class DbConfigTask extends Shell {
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public function initialize() {
|
public function initialize() {
|
||||||
$this->path = APP . 'config' . DS;
|
$this->path = APP . 'Config' . DS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,7 +41,7 @@ class PluginTask extends Shell {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function initialize() {
|
function initialize() {
|
||||||
$this->path = APP . 'plugins' . DS;
|
$this->path = APP . 'Plugin' . DS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,7 +76,7 @@ class PluginTask extends Shell {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->bake($plugin)) {
|
if (!$this->bake($plugin)) {
|
||||||
$this->error(__d('cake_console', "An error occured trying to bake: %s in %s", $plugin, $this->path . Inflector::underscore($pluginPath)));
|
$this->error(__d('cake_console', "An error occured trying to bake: %s in %s", $plugin, $this->path . Inflector::camelize($pluginPath)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,8 +88,7 @@ class PluginTask extends Shell {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function bake($plugin) {
|
public function bake($plugin) {
|
||||||
$pluginPath = Inflector::underscore($plugin);
|
$pluginPath = Inflector::camelize($plugin);
|
||||||
|
|
||||||
$pathOptions = App::path('plugins');
|
$pathOptions = App::path('plugins');
|
||||||
if (count($pathOptions) > 1) {
|
if (count($pathOptions) > 1) {
|
||||||
$this->findPath($pathOptions);
|
$this->findPath($pathOptions);
|
||||||
|
@ -104,7 +103,7 @@ class PluginTask extends Shell {
|
||||||
if (strtolower($looksGood) == 'y') {
|
if (strtolower($looksGood) == 'y') {
|
||||||
$Folder = new Folder($this->path . $pluginPath);
|
$Folder = new Folder($this->path . $pluginPath);
|
||||||
$directories = array(
|
$directories = array(
|
||||||
'config' . DS . 'schema',
|
'Config' . DS . 'schema',
|
||||||
'Model' . DS . 'Behavior',
|
'Model' . DS . 'Behavior',
|
||||||
'Model' . DS . 'Datasource',
|
'Model' . DS . 'Datasource',
|
||||||
'Console' . DS . 'Command' . DS . 'Task',
|
'Console' . DS . 'Command' . DS . 'Task',
|
||||||
|
|
|
@ -60,7 +60,7 @@ class ProjectTask extends Shell {
|
||||||
|
|
||||||
if ($project) {
|
if ($project) {
|
||||||
$response = false;
|
$response = false;
|
||||||
while ($response == false && is_dir($project) === true && file_exists($project . 'config' . 'core.php')) {
|
while ($response == false && is_dir($project) === true && file_exists($project . 'Config' . 'core.php')) {
|
||||||
$prompt = __d('cake_console', '<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
|
$prompt = __d('cake_console', '<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
|
||||||
$response = $this->in($prompt, array('y','n'), 'n');
|
$response = $this->in($prompt, array('y','n'), 'n');
|
||||||
if (strtolower($response) === 'n') {
|
if (strtolower($response) === 'n') {
|
||||||
|
@ -236,7 +236,7 @@ class ProjectTask extends Shell {
|
||||||
* @return boolean Success
|
* @return boolean Success
|
||||||
*/
|
*/
|
||||||
public function securitySalt($path) {
|
public function securitySalt($path) {
|
||||||
$File = new File($path . 'config' . DS . 'core.php');
|
$File = new File($path . 'Config' . DS . 'core.php');
|
||||||
$contents = $File->read();
|
$contents = $File->read();
|
||||||
if (preg_match('/([\s]*Configure::write\(\'Security.salt\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
|
if (preg_match('/([\s]*Configure::write\(\'Security.salt\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
|
||||||
$string = Security::generateAuthKey();
|
$string = Security::generateAuthKey();
|
||||||
|
@ -256,7 +256,7 @@ class ProjectTask extends Shell {
|
||||||
* @return boolean Success
|
* @return boolean Success
|
||||||
*/
|
*/
|
||||||
public function securityCipherSeed($path) {
|
public function securityCipherSeed($path) {
|
||||||
$File = new File($path . 'config' . DS . 'core.php');
|
$File = new File($path . 'Config' . DS . 'core.php');
|
||||||
$contents = $File->read();
|
$contents = $File->read();
|
||||||
if (preg_match('/([\s]*Configure::write\(\'Security.cipherSeed\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
|
if (preg_match('/([\s]*Configure::write\(\'Security.cipherSeed\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
|
||||||
if (!class_exists('Security')) {
|
if (!class_exists('Security')) {
|
||||||
|
|
|
@ -756,6 +756,9 @@ class Shell extends Object {
|
||||||
* @return string $path path to the correct plugin.
|
* @return string $path path to the correct plugin.
|
||||||
*/
|
*/
|
||||||
function _pluginPath($pluginName) {
|
function _pluginPath($pluginName) {
|
||||||
return App::pluginPath($pluginName);
|
if (CakePlugin::loaded($pluginName)) {
|
||||||
|
return CakePlugin::path($pluginName);
|
||||||
|
}
|
||||||
|
return current(App::path('plugins')) . $pluginName . DS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,11 +129,11 @@ class ShellDispatcher {
|
||||||
if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) {
|
if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) {
|
||||||
define('TMP', CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'templates' . DS . 'skel' . DS . 'tmp' . DS);
|
define('TMP', CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'templates' . DS . 'skel' . DS . 'tmp' . DS);
|
||||||
}
|
}
|
||||||
$boot = file_exists(ROOT . DS . APP_DIR . DS . 'config' . DS . 'bootstrap.php');
|
$boot = file_exists(ROOT . DS . APP_DIR . DS . 'Config' . DS . 'bootstrap.php');
|
||||||
require CORE_PATH . 'Cake' . DS . 'bootstrap.php';
|
require CORE_PATH . 'Cake' . DS . 'bootstrap.php';
|
||||||
|
|
||||||
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
|
if (!file_exists(APP_PATH . 'Config' . DS . 'core.php')) {
|
||||||
include_once CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
|
include_once CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'templates' . DS . 'skel' . DS . 'Config' . DS . 'core.php';
|
||||||
App::build();
|
App::build();
|
||||||
}
|
}
|
||||||
require_once CONSOLE_LIBS . 'ConsoleErrorHandler.php';
|
require_once CONSOLE_LIBS . 'ConsoleErrorHandler.php';
|
||||||
|
|
|
@ -90,7 +90,7 @@ $output .= "<?php\n";
|
||||||
$output .= "\techo __('To change the content of this page, edit: %s\n";
|
$output .= "\techo __('To change the content of this page, edit: %s\n";
|
||||||
$output .= "\t\tTo change its layout, edit: %s\n";
|
$output .= "\t\tTo change its layout, edit: %s\n";
|
||||||
$output .= "\t\tYou can also add some CSS styles for your pages at: %s',\n";
|
$output .= "\t\tYou can also add some CSS styles for your pages at: %s',\n";
|
||||||
$output .= "\t\tAPP . 'views' . DS . 'pages' . DS . 'home.ctp.<br />', APP . 'views' . DS . 'layouts' . DS . 'default.ctp.<br />', APP . 'webroot' . DS . 'css');\n";
|
$output .= "\t\tAPP . 'View' . DS . 'Pages' . DS . 'home.ctp.<br />', APP . 'View' . DS . 'Layouts' . DS . 'default.ctp.<br />', APP . 'webroot' . DS . 'css');\n";
|
||||||
$output .= "?>\n";
|
$output .= "?>\n";
|
||||||
$output .= "</p>\n";
|
$output .= "</p>\n";
|
||||||
?>
|
?>
|
|
@ -315,7 +315,7 @@ class AuthComponent extends Component {
|
||||||
$controller->redirect($loginAction);
|
$controller->redirect($loginAction);
|
||||||
return false;
|
return false;
|
||||||
} elseif (!empty($this->ajaxLogin)) {
|
} elseif (!empty($this->ajaxLogin)) {
|
||||||
$controller->viewPath = 'elements';
|
$controller->viewPath = 'Elements';
|
||||||
echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
|
echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
|
||||||
$this->_stop();
|
$this->_stop();
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -315,7 +315,7 @@ class Controller extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->viewPath == null) {
|
if ($this->viewPath == null) {
|
||||||
$this->viewPath = Inflector::underscore($this->name);
|
$this->viewPath = $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->modelClass = Inflector::singularize($this->name);
|
$this->modelClass = Inflector::singularize($this->name);
|
||||||
|
|
|
@ -125,7 +125,7 @@ class Scaffold {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->ScaffoldModel = $this->controller->{$this->modelClass};
|
$this->ScaffoldModel = $this->controller->{$this->modelClass};
|
||||||
$this->scaffoldTitle = Inflector::humanize($this->viewPath);
|
$this->scaffoldTitle = Inflector::humanize(Inflector::underscore($this->viewPath));
|
||||||
$this->scaffoldActions = $controller->scaffold;
|
$this->scaffoldActions = $controller->scaffold;
|
||||||
$title_for_layout = __d('cake', 'Scaffold :: ') . Inflector::humanize($request->action) . ' :: ' . $this->scaffoldTitle;
|
$title_for_layout = __d('cake', 'Scaffold :: ') . Inflector::humanize($request->action) . ' :: ' . $this->scaffoldTitle;
|
||||||
$modelClass = $this->controller->modelClass;
|
$modelClass = $this->controller->modelClass;
|
||||||
|
|
|
@ -92,7 +92,7 @@ class App {
|
||||||
'class' => array('extends' => null, 'core' => true),
|
'class' => array('extends' => null, 'core' => true),
|
||||||
'file' => array('extends' => null, 'core' => true),
|
'file' => array('extends' => null, 'core' => true),
|
||||||
'model' => array('extends' => 'AppModel', 'core' => false),
|
'model' => array('extends' => 'AppModel', 'core' => false),
|
||||||
'behavior' => array('extends' => 'ModelBehavior', 'core' => true),
|
'behavior' => array( 'suffix' => 'Behavior', 'extends' => 'Model/ModelBehavior', 'core' => true),
|
||||||
'controller' => array('suffix' => 'Controller', 'extends' => 'AppController', 'core' => true),
|
'controller' => array('suffix' => 'Controller', 'extends' => 'AppController', 'core' => true),
|
||||||
'component' => array('suffix' => 'Component', 'extends' => null, 'core' => true),
|
'component' => array('suffix' => 'Component', 'extends' => null, 'core' => true),
|
||||||
'lib' => array('extends' => null, 'core' => true),
|
'lib' => array('extends' => null, 'core' => true),
|
||||||
|
@ -247,6 +247,8 @@ class App {
|
||||||
*
|
*
|
||||||
* `App::build(array('View/Helper' => array('/path/to/helpers/', '/another/path/))); will setup multiple search paths for helpers`
|
* `App::build(array('View/Helper' => array('/path/to/helpers/', '/another/path/))); will setup multiple search paths for helpers`
|
||||||
*
|
*
|
||||||
|
* If reset is set to true, all loaded plugins will be forgotten and they will be needed to be loaded again.
|
||||||
|
*
|
||||||
* @param array $paths associative array with package names as keys and a list of directories for new search paths
|
* @param array $paths associative array with package names as keys and a list of directories for new search paths
|
||||||
* @param mixed $mode App::RESET will set paths, App::APPEND with append paths, App::PREPEND will prepend paths, [default] App::PREPEND
|
* @param mixed $mode App::RESET will set paths, App::APPEND with append paths, App::PREPEND will prepend paths, [default] App::PREPEND
|
||||||
* @return void
|
* @return void
|
||||||
|
@ -309,10 +311,11 @@ class App {
|
||||||
'locales' => array(
|
'locales' => array(
|
||||||
'%s' . 'locale' . DS
|
'%s' . 'locale' . DS
|
||||||
),
|
),
|
||||||
'vendors' => array('%s' . 'vendors' . DS, VENDORS),
|
'vendors' => array('%s' . 'Vendor' . DS, VENDORS),
|
||||||
'plugins' => array(
|
'plugins' => array(
|
||||||
APP . 'plugins' . DS,
|
APP . 'Plugin' . DS,
|
||||||
dirname(dirname(CAKE)) . DS . 'plugins' . DS
|
APP . 'plugin' . DS,
|
||||||
|
dirname(dirname(CAKE)) . DS . 'Plugin' . DS,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -374,13 +377,7 @@ class App {
|
||||||
* @return string full path to the plugin.
|
* @return string full path to the plugin.
|
||||||
*/
|
*/
|
||||||
public static function pluginPath($plugin) {
|
public static function pluginPath($plugin) {
|
||||||
$pluginDir = Inflector::underscore($plugin);
|
return CakePlugin::path($plugin);
|
||||||
foreach (self::$__packages['plugins'] as $pluginPath) {
|
|
||||||
if (is_dir($pluginPath . $pluginDir)) {
|
|
||||||
return $pluginPath . $pluginDir . DS ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return self::$__packages['plugins'][0] . $pluginDir . DS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -390,11 +387,11 @@ class App {
|
||||||
*
|
*
|
||||||
* `App::themePath('MyTheme'); will return the full path to the 'MyTheme' theme`
|
* `App::themePath('MyTheme'); will return the full path to the 'MyTheme' theme`
|
||||||
*
|
*
|
||||||
* @param string $theme lower_cased theme name to find the path of.
|
* @param string $theme theme name to find the path of.
|
||||||
* @return string full path to the theme.
|
* @return string full path to the theme.
|
||||||
*/
|
*/
|
||||||
public static function themePath($theme) {
|
public static function themePath($theme) {
|
||||||
$themeDir = 'themed' . DS . Inflector::underscore($theme);
|
$themeDir = 'Themed' . DS . Inflector::camelize($theme);
|
||||||
foreach (self::$__packages['View'] as $path) {
|
foreach (self::$__packages['View'] as $path) {
|
||||||
if (is_dir($path . $themeDir)) {
|
if (is_dir($path . $themeDir)) {
|
||||||
return $path . $themeDir . DS ;
|
return $path . $themeDir . DS ;
|
||||||
|
@ -647,6 +644,9 @@ class App {
|
||||||
list($plugin, $name) = pluginSplit($name);
|
list($plugin, $name) = pluginSplit($name);
|
||||||
if (!empty($plugin)) {
|
if (!empty($plugin)) {
|
||||||
$plugin = Inflector::camelize($plugin);
|
$plugin = Inflector::camelize($plugin);
|
||||||
|
if (!CakePlugin::loaded($plugin)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$specialPackage) {
|
if (!$specialPackage) {
|
||||||
|
@ -683,10 +683,15 @@ class App {
|
||||||
$suffix = self::$types[$originalType]['suffix'];
|
$suffix = self::$types[$originalType]['suffix'];
|
||||||
$name .= ($suffix == $name) ? '' : $suffix;
|
$name .= ($suffix == $name) ? '' : $suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($parent && isset(self::$types[$originalType]['extends'])) {
|
if ($parent && isset(self::$types[$originalType]['extends'])) {
|
||||||
$extends = self::$types[$originalType]['extends'];
|
$extends = self::$types[$originalType]['extends'];
|
||||||
App::uses($extends, $type);
|
$extendType = $type;
|
||||||
|
if (strpos($extends, '/') !== false) {
|
||||||
|
$parts = explode('/', $extends);
|
||||||
|
$extends = array_pop($parts);
|
||||||
|
$extendType = implode('/', $parts);
|
||||||
|
}
|
||||||
|
App::uses($extends, $extendType);
|
||||||
if ($plugin && in_array($originalType, array('controller', 'model'))) {
|
if ($plugin && in_array($originalType, array('controller', 'model'))) {
|
||||||
App::uses($plugin . $extends, $plugin . '.' .$type);
|
App::uses($plugin . $extends, $plugin . '.' .$type);
|
||||||
}
|
}
|
||||||
|
@ -782,6 +787,7 @@ class App {
|
||||||
self::$__map = (array)Cache::read('file_map', '_cake_core_');
|
self::$__map = (array)Cache::read('file_map', '_cake_core_');
|
||||||
self::$__objects = (array)Cache::read('object_map', '_cake_core_');
|
self::$__objects = (array)Cache::read('object_map', '_cake_core_');
|
||||||
register_shutdown_function(array('App', 'shutdown'));
|
register_shutdown_function(array('App', 'shutdown'));
|
||||||
|
self::uses('CakePlugin', 'Core');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
192
lib/Cake/Core/CakePlugin.php
Normal file
192
lib/Cake/Core/CakePlugin.php
Normal file
|
@ -0,0 +1,192 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class CakePlugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds a list of all loaded plugins and their configuration
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static $_plugins = 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
|
||||||
|
*
|
||||||
|
* @param mixed $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
|
||||||
|
* @throws MissingPluginException if the folder for the plugin to be loaded is not found
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function load($plugin, $config = array()) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$config += array('bootstrap' => false, 'routes' => 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);
|
||||||
|
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);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self::$_plugins[$plugin] = $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty(self::$_plugins[$plugin]['path'])) {
|
||||||
|
throw new MissingPluginException(array('plugin' => $plugin));
|
||||||
|
}
|
||||||
|
if (!empty(self::$_plugins[$plugin]['bootstrap'])) {
|
||||||
|
self::bootstrap($plugin);
|
||||||
|
}
|
||||||
|
if (!empty(self::$_plugins[$plugin]['routes'])) {
|
||||||
|
self::routes($plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @param array $options
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function loadAll($options = array()) {
|
||||||
|
$plugins = App::objects('plugins');
|
||||||
|
foreach ($plugins as $p) {
|
||||||
|
$opts = isset($options[$p]) ? $options[$p] : $options;
|
||||||
|
self::load($p, $opts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the filesystem path for a plugin
|
||||||
|
*
|
||||||
|
* @param string $plugin name of the plugin in CamelCase format
|
||||||
|
* @return string path to the plugin folder
|
||||||
|
* @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])) {
|
||||||
|
throw new MissingPluginException(array('plugin' => $plugin));
|
||||||
|
}
|
||||||
|
return self::$_plugins[$plugin]['path'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the bootstrapping files for a plugin, or calls the initialization setup in the configuration
|
||||||
|
*
|
||||||
|
* @param string $plugin name of the plugin
|
||||||
|
* @return mixed
|
||||||
|
* @see CakePlugin::load() for examples of bootstrap configuration
|
||||||
|
*/
|
||||||
|
public static function bootstrap($plugin) {
|
||||||
|
$config = self::$_plugins[$plugin];
|
||||||
|
if ($config['bootstrap'] === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (is_callable($config['bootstrap'])) {
|
||||||
|
return call_user_func_array($config['bootstrap'], array($plugin, $config));
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = self::path($plugin);
|
||||||
|
if ($config['bootstrap'] === true) {
|
||||||
|
return include($path . 'Config' . DS . 'bootstrap.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
$bootstrap = (array)$config['bootstrap'];
|
||||||
|
foreach ($bootstrap as $file) {
|
||||||
|
include $path . 'Config' . DS . $file . '.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the routes file for a plugin
|
||||||
|
*
|
||||||
|
* @param string $plugin name of the plugin
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function routes($plugin) {
|
||||||
|
$config = self::$_plugins[$plugin];
|
||||||
|
if ($config['routes'] === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (bool) include self::path($plugin) . 'Config' . DS . 'routes.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retruns true if the plugin $plugin is already loaded
|
||||||
|
* If plugin is null, it will return a list of all loaded plugins
|
||||||
|
*
|
||||||
|
* @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 array_keys(self::$_plugins);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forgets a loaded plugin or all of them if first parameter is null
|
||||||
|
*
|
||||||
|
* @param string $plugin name of the plugin to forget
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function unload($plugin = null) {
|
||||||
|
if (is_null($plugin)) {
|
||||||
|
self::$_plugins = array();
|
||||||
|
} else {
|
||||||
|
unset(self::$_plugins[$plugin]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -318,7 +318,7 @@ class Configure {
|
||||||
*/
|
*/
|
||||||
public static function version() {
|
public static function version() {
|
||||||
if (!isset(self::$_values['Cake']['version'])) {
|
if (!isset(self::$_values['Cake']['version'])) {
|
||||||
require(LIBS . 'config' . DS . 'config.php');
|
require(LIBS . 'Config' . DS . 'config.php');
|
||||||
self::write($config);
|
self::write($config);
|
||||||
}
|
}
|
||||||
return self::$_values['Cake']['version'];
|
return self::$_values['Cake']['version'];
|
||||||
|
|
|
@ -417,6 +417,14 @@ class MissingTestLoaderException extends CakeException {
|
||||||
protected $_messageTemplate = 'Test loader %s could not be found.';
|
protected $_messageTemplate = 'Test loader %s could not be found.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception Raised when a test loader could not be found
|
||||||
|
*
|
||||||
|
* @package cake.libs
|
||||||
|
*/
|
||||||
|
class MissingPluginException extends CakeException {
|
||||||
|
protected $_messageTemplate = 'Test plugin %s could not be found.';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception class for Cache. This exception will be thrown from Cache when it
|
* Exception class for Cache. This exception will be thrown from Cache when it
|
||||||
|
|
|
@ -263,13 +263,13 @@ class I18n {
|
||||||
$core = true;
|
$core = true;
|
||||||
$merge = array();
|
$merge = array();
|
||||||
$searchPaths = App::path('locales');
|
$searchPaths = App::path('locales');
|
||||||
$plugins = App::objects('plugin');
|
$plugins = CakePlugin::loaded();
|
||||||
|
|
||||||
if (!empty($plugins)) {
|
if (!empty($plugins)) {
|
||||||
foreach ($plugins as $plugin) {
|
foreach ($plugins as $plugin) {
|
||||||
$plugin = Inflector::underscore($plugin);
|
$pluginDomain = Inflector::underscore($plugin);
|
||||||
if ($plugin === $domain) {
|
if ($pluginDomain === $domain) {
|
||||||
$searchPaths[] = App::pluginPath($plugin) . DS . 'locale' . DS;
|
$searchPaths[] = CakePlugin::path($plugin) . DS . 'locale' . DS;
|
||||||
$searchPaths = array_reverse($searchPaths);
|
$searchPaths = array_reverse($searchPaths);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue