mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 19:38:26 +00:00
c000940e36
Closes #2213, Support multiple plugin paths. Closes #2234, filepaths to behavior classes should be cached in class.paths.php also Closes #2345, ability to group components into subfolders Closes #2645, Improvement to basic.php for class loading. Fixes #3526, Cache::write, when using just the config name, it fails. Fixes #3559, loading plugin model as assoc don't work. Closes #3567 Controller Folders (Note this does not need routing to work, but controller names can not conflict with others in the same application so naming must still be unique) Fixes #3579, email.php component: Parse error with php 4. Adding new class and file importer. Updated most of the core to use the importer. Added ClassRegsitry::init() that will create and instance of an object and store it in the registry. Deprecated most of the load functions in basics.php Plugin model loading now forces using the dot notation, to use models within a plugin, all the model associations must be in the PluginName.Model syntax, if this is not used, the plugin will look for the models in the main app/models directory first, if not found then it will search the plugin directories recursively until it finds a model. var $belongsTo = array('SomeModel'); will look for some_model.php in the app/models var $belongsTo = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models var $belongsTo = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php The controllers of the plugin will still look for the default models inside the plugin if var $uses is not set: var $uses = array('SomeModel'); will look for some_model.php in the app/models var $uses = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models var $uses = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php All of the above will work between plugins and main app These changes also allow placing model and controllers is sub directories Removed old class.paths.php file generation git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6001 3807eeeb-6ff5-0310-8944-8be069107fe0
147 lines
No EOL
4.4 KiB
PHP
147 lines
No EOL
4.4 KiB
PHP
<?php
|
|
/* SVN FILE: $Id$ */
|
|
/**
|
|
*
|
|
* PHP versions 4 and 5
|
|
*
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
* Las Vegas, Nevada 89104
|
|
*
|
|
* Licensed under The MIT License
|
|
* Redistributions of files must retain the above copyright notice.
|
|
*
|
|
* @filesource
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
|
* @package cake
|
|
* @subpackage cake.cake.libs.controller
|
|
* @since CakePHP(tm) v TBD
|
|
* @version $Revision$
|
|
* @modifiedby $LastChangedBy$
|
|
* @lastmodified $Date$
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
*/
|
|
/**
|
|
* Base class for all CakePHP Components.
|
|
*
|
|
* @package cake
|
|
* @subpackage cake.cake.libs.controller
|
|
*/
|
|
class Component extends Object {
|
|
/**
|
|
* Components used by this component.
|
|
*
|
|
* @var array
|
|
* @access public
|
|
*/
|
|
var $components = array();
|
|
/**
|
|
* Controller to which this component is linked.
|
|
*
|
|
* @var object
|
|
* @access public
|
|
*/
|
|
var $controller = null;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @return object
|
|
*/
|
|
function __construct() {
|
|
}
|
|
/**
|
|
* Used to initialize the components for current controller
|
|
*
|
|
* @param object $controller Controller using this component.
|
|
* @access public
|
|
*/
|
|
function init(&$controller) {
|
|
$this->controller =& $controller;
|
|
if ($this->controller->components !== false) {
|
|
$loaded = array();
|
|
|
|
if(in_array('Security', $this->controller->components)) {
|
|
$remove = array_flip($this->controller->components);
|
|
unset($remove['Security']);
|
|
$this->controller->components = array_merge(array('Session', 'Security'), array_flip($remove));
|
|
} else {
|
|
$this->controller->components = array_merge(array('Session'), $this->controller->components);
|
|
}
|
|
$loaded = $this->_loadComponents($loaded, $this->controller->components);
|
|
|
|
foreach (array_keys($loaded) as $component) {
|
|
$tempComponent =& $loaded[$component];
|
|
if (isset($tempComponent->components) && is_array($tempComponent->components)) {
|
|
foreach ($tempComponent->components as $subComponent) {
|
|
$this->controller->{$component}->{$subComponent} =& $loaded[$subComponent];
|
|
}
|
|
}
|
|
if (is_callable(array($tempComponent, 'initialize'))) {
|
|
$tempComponent->initialize($controller);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* Load components used by this component.
|
|
*
|
|
* @param array $loaded Components already loaded (indexed by component name)
|
|
* @param array $components Components to load
|
|
* @return array Components loaded
|
|
* @access protected
|
|
*/
|
|
function &_loadComponents(&$loaded, $components) {
|
|
foreach ($components as $component) {
|
|
$parts = preg_split('/\/|\./', $component);
|
|
|
|
if (count($parts) === 1) {
|
|
$plugin = $this->controller->plugin;
|
|
} else {
|
|
$plugin = Inflector::underscore($parts['0']);
|
|
$component = $parts[count($parts) - 1];
|
|
}
|
|
|
|
$componentCn = $component . 'Component';
|
|
|
|
if (in_array($component, array_keys($loaded)) !== true) {
|
|
if (!class_exists($componentCn)) {
|
|
if (is_null($plugin) || !loadPluginComponent($plugin, $component)) {
|
|
if (!App::import('Component', $component)) {
|
|
$this->cakeError('missingComponentFile', array(array(
|
|
'className' => $this->controller->name,
|
|
'component' => $component,
|
|
'file' => Inflector::underscore($component) . '.php',
|
|
'base' => $this->controller->base)));
|
|
exit();
|
|
}
|
|
}
|
|
|
|
if (!class_exists($componentCn)) {
|
|
$this->cakeError('missingComponentClass', array(array(
|
|
'className' => $this->controller->name,
|
|
'component' => $component,
|
|
'file' => Inflector::underscore($component) . '.php',
|
|
'base' => $this->controller->base)));
|
|
exit();
|
|
}
|
|
}
|
|
|
|
if ($componentCn == 'SessionComponent') {
|
|
$param = Router::stripPlugin($this->controller->base, $this->controller->plugin) . '/';
|
|
} else {
|
|
$param = null;
|
|
}
|
|
$this->controller->{$component} =& new $componentCn($param);
|
|
$loaded[$component] =& $this->controller->{$component};
|
|
if (isset($this->controller->{$component}->components) && is_array($this->controller->{$component}->components)) {
|
|
$loaded =& $this->_loadComponents($loaded, $this->controller->{$component}->components);
|
|
}
|
|
}
|
|
}
|
|
return $loaded;
|
|
}
|
|
}
|
|
?>
|