2005-08-21 06:49:02 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Class collections.
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* A repository for class objects, each registered with a key.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
2008-01-01 22:18:17 +00:00
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2006-01-12 02:10:47 +00:00
|
|
|
* @filesource
|
2008-01-01 22:18:17 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
2007-02-02 10:39:45 +00:00
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2007-02-02 10:39:45 +00:00
|
|
|
* @since CakePHP(tm) v 0.9.2
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Class Collections.
|
|
|
|
*
|
2006-01-12 02:10:47 +00:00
|
|
|
* A repository for class objects, each registered with a key.
|
2005-09-17 02:22:07 +00:00
|
|
|
* If you try to add an object with the same key twice, nothing will come of it.
|
|
|
|
* If you need a second instance of an object, give it another key.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
2007-01-31 23:25:05 +00:00
|
|
|
class ClassRegistry {
|
2005-08-21 06:49:02 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Names of classes with their objects.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* @var array
|
2005-08-21 06:49:02 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
2007-02-05 04:53:31 +00:00
|
|
|
var $__objects = array();
|
|
|
|
/**
|
|
|
|
* Names of class names mapped to the object in the registry.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
var $__map = array();
|
2005-08-21 06:49:02 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Return a singleton instance of the ClassRegistry.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* @return ClassRegistry instance
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function &getInstance() {
|
|
|
|
static $instance = array();
|
|
|
|
if (!$instance) {
|
2007-02-05 04:53:31 +00:00
|
|
|
$instance[0] =& new ClassRegistry();
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
return $instance[0];
|
|
|
|
}
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
/**
|
|
|
|
* Loads a class, registers the object in the registry and returns instance of the object.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param mixed $class as a string or a single key => value array instance will be created, stored in the registry and returned.
|
|
|
|
* Required: array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry', 'type' => 'TypeOfClass');
|
|
|
|
* Model Classes can accept optional array('id' => $id, 'table' => $table, 'ds' => $ds, 'alias' => $alias);
|
|
|
|
* When $class is a numeric keyed array, multiple class instances will be stored in the registry, no instance of the object will be returned
|
|
|
|
* array(
|
|
|
|
* array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry', 'type' => 'TypeOfClass'),
|
|
|
|
* array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry', 'type' => 'TypeOfClass'),
|
|
|
|
* array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry', 'type' => 'TypeOfClass'));
|
|
|
|
*
|
|
|
|
* @param string $type TypeOfClass
|
|
|
|
* @return object intance of ClassName
|
|
|
|
*/
|
|
|
|
function &init($class, $type = null) {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
|
|
|
$id = $false = false;
|
|
|
|
$table = $ds = $alias = $plugin = null;
|
|
|
|
$options = null;
|
|
|
|
$true = true;
|
2007-12-22 19:25:24 +00:00
|
|
|
if (!$type) {
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
$type = 'Model';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($class)) {
|
2007-12-22 19:25:24 +00:00
|
|
|
$objects = $class;
|
|
|
|
if (!isset($class[0])) {
|
|
|
|
$objects = array($class);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$objects = array(array('class' => $class));
|
|
|
|
}
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
|
2007-12-22 19:25:24 +00:00
|
|
|
$count = count($objects);
|
|
|
|
foreach ($objects as $key => $settings) {
|
|
|
|
if (is_array($settings)) {
|
|
|
|
$plugin = null;
|
|
|
|
$settings = array_merge(array('id' => false, 'table' => null, 'ds' => null, 'alias' => null, 'name' => null), $settings);
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
|
2007-12-22 19:25:24 +00:00
|
|
|
extract($settings, EXTR_OVERWRITE);
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
|
|
|
|
if (strpos($class, '.') !== false) {
|
|
|
|
list($plugin, $class) = explode('.', $class);
|
|
|
|
$plugin = $plugin . '.';
|
|
|
|
}
|
2007-12-22 19:25:24 +00:00
|
|
|
|
|
|
|
if (empty($alias)) {
|
|
|
|
$alias = $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($_this->_duplicate($alias, $class) && $count == 1) {
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
$_this->map($alias, $class);
|
|
|
|
return $_this->getObject($alias);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type === 'Model') {
|
|
|
|
$options = array('id' => $id, 'table' => $table, 'ds' => $ds, 'alias' => $alias, 'name' => $class);
|
|
|
|
}
|
|
|
|
if (App::import($type, $plugin . $class)) {
|
2007-12-23 04:42:59 +00:00
|
|
|
${$class} =& new $class($options);
|
2007-12-22 19:25:24 +00:00
|
|
|
} elseif ($type === 'Model') {
|
2007-12-23 04:42:59 +00:00
|
|
|
${$class} =& new AppModel($options);
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
2007-12-22 19:25:24 +00:00
|
|
|
if (!isset(${$class})) {
|
|
|
|
trigger_error(sprintf(__('(ClassRegistry::init() could not create instance of %1$s class %2$s ', true), $class, $type), E_USER_WARNING);
|
|
|
|
return $false;
|
|
|
|
}
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
|
2007-12-22 19:25:24 +00:00
|
|
|
if ($type !== 'Model') {
|
2007-12-23 04:42:59 +00:00
|
|
|
$_this->addObject($alias, ${$class});
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
} else {
|
|
|
|
$_this->map($alias, $class);
|
|
|
|
}
|
2007-12-22 19:25:24 +00:00
|
|
|
} elseif (is_numeric($settings)) {
|
|
|
|
trigger_error(__('(ClassRegistry::init() Attempted to create instance of a class with a numeric name', true), E_USER_WARNING);
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
return $false;
|
|
|
|
}
|
|
|
|
}
|
2007-12-22 19:25:24 +00:00
|
|
|
|
|
|
|
if ($count > 1) {
|
|
|
|
return $true;
|
|
|
|
}
|
|
|
|
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
return ${$class};
|
|
|
|
}
|
2005-08-21 06:49:02 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Add $object to the registry, associating it with the name $key.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2007-05-20 06:30:19 +00:00
|
|
|
* @param string $key Key for the object in registry
|
|
|
|
* @param mixed $object Object to store
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True if the object was written, false if $key already exists
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function addObject($key, &$object) {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
2006-11-27 01:04:19 +00:00
|
|
|
$key = Inflector::underscore($key);
|
2007-02-05 04:53:31 +00:00
|
|
|
if (array_key_exists($key, $_this->__objects) === false) {
|
|
|
|
$_this->__objects[$key] = &$object;
|
2007-09-20 14:50:42 +00:00
|
|
|
return true;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-09-20 14:50:42 +00:00
|
|
|
return false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-03-12 00:11:40 +00:00
|
|
|
/**
|
|
|
|
* Remove object which corresponds to given key.
|
|
|
|
*
|
2007-05-20 06:30:19 +00:00
|
|
|
* @param string $key Key of object to remove from registry
|
|
|
|
* @access public
|
2006-03-12 00:11:40 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function removeObject($key) {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
2006-11-27 01:04:19 +00:00
|
|
|
$key = Inflector::underscore($key);
|
2007-02-05 04:53:31 +00:00
|
|
|
if (array_key_exists($key, $_this->__objects) === true) {
|
|
|
|
unset($_this->__objects[$key]);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-21 06:49:02 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Returns true if given key is present in the ClassRegistry.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @param string $key Key to look for
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean true if key exists in registry, false otherwise
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function isKeySet($key) {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
2006-11-27 01:04:19 +00:00
|
|
|
$key = Inflector::underscore($key);
|
2007-06-20 06:15:35 +00:00
|
|
|
if (array_key_exists($key, $_this->__objects)) {
|
2007-02-05 04:53:31 +00:00
|
|
|
return true;
|
|
|
|
} elseif (array_key_exists($key, $_this->__map)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-04-27 20:16:38 +00:00
|
|
|
/**
|
|
|
|
* Get all keys from the regisrty.
|
|
|
|
*
|
2007-05-20 06:30:19 +00:00
|
|
|
* @return array Set of keys stored in registry
|
|
|
|
* @access public
|
2007-04-27 20:16:38 +00:00
|
|
|
*/
|
|
|
|
function keys() {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
|
|
|
return array_keys($_this->__objects);
|
|
|
|
}
|
2005-08-21 06:49:02 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Return object which corresponds to given key.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2007-05-20 06:30:19 +00:00
|
|
|
* @param string $key Key of object to look for
|
|
|
|
* @return mixed Object stored in registry
|
|
|
|
* @access public
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function &getObject($key) {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
2006-11-27 01:04:19 +00:00
|
|
|
$key = Inflector::underscore($key);
|
2007-03-16 23:54:24 +00:00
|
|
|
|
2007-06-20 07:51:52 +00:00
|
|
|
if (isset($_this->__objects[$key])) {
|
2007-02-05 04:53:31 +00:00
|
|
|
return $_this->__objects[$key];
|
|
|
|
} else {
|
|
|
|
$key = $_this->__getMap($key);
|
2007-06-20 07:51:52 +00:00
|
|
|
if (isset($_this->__objects[$key])) {
|
2007-02-05 04:53:31 +00:00
|
|
|
return $_this->__objects[$key];
|
|
|
|
}
|
|
|
|
}
|
2007-05-20 06:30:19 +00:00
|
|
|
|
2007-03-16 23:54:24 +00:00
|
|
|
$return = false;
|
|
|
|
return $return;
|
2007-02-05 04:53:31 +00:00
|
|
|
}
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
/**
|
|
|
|
* Checks to see if $alias is a duplicate $class Object
|
|
|
|
*
|
|
|
|
* @param string $alias
|
|
|
|
* @param string $class
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function _duplicate($alias, $class) {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
|
|
|
$duplicate = false;
|
|
|
|
|
|
|
|
if ($_this->isKeySet($alias)) {
|
|
|
|
$model = $_this->getObject($alias);
|
|
|
|
if (is_a($model, $class)) {
|
|
|
|
$duplicate = true;
|
|
|
|
}
|
|
|
|
unset($model);
|
|
|
|
}
|
|
|
|
return $duplicate;
|
|
|
|
}
|
2007-02-05 04:53:31 +00:00
|
|
|
/**
|
|
|
|
* Add a key name pair to the registry to map name to class in the regisrty.
|
|
|
|
*
|
2007-05-20 06:30:19 +00:00
|
|
|
* @param string $key Key to include in map
|
|
|
|
* @param string $name Key that is being mapped
|
|
|
|
* @access public
|
2007-02-05 04:53:31 +00:00
|
|
|
*/
|
2007-03-16 23:54:24 +00:00
|
|
|
function map($key, $name) {
|
2007-02-05 04:53:31 +00:00
|
|
|
$_this =& ClassRegistry::getInstance();
|
|
|
|
$key = Inflector::underscore($key);
|
|
|
|
$name = Inflector::underscore($name);
|
|
|
|
if (array_key_exists($key, $_this->__map) === false) {
|
|
|
|
$_this->__map[$key] = $name;
|
|
|
|
}
|
|
|
|
}
|
2007-04-27 20:16:38 +00:00
|
|
|
/**
|
|
|
|
* Get all keys from the map in the regisrty.
|
|
|
|
*
|
2007-05-20 06:30:19 +00:00
|
|
|
* @return array Keys of registry's map
|
|
|
|
* @access public
|
2007-04-27 20:16:38 +00:00
|
|
|
*/
|
|
|
|
function mapKeys() {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
|
|
|
return array_keys($_this->__map);
|
|
|
|
}
|
2007-02-05 04:53:31 +00:00
|
|
|
/**
|
|
|
|
* Return the name of a class in the registry.
|
|
|
|
*
|
2007-05-20 06:30:19 +00:00
|
|
|
* @param string $key Key to find in map
|
|
|
|
* @return string Mapped value
|
|
|
|
* @access private
|
2007-02-05 04:53:31 +00:00
|
|
|
*/
|
2007-03-16 23:54:24 +00:00
|
|
|
function __getMap($key) {
|
2007-02-05 04:53:31 +00:00
|
|
|
$_this =& ClassRegistry::getInstance();
|
|
|
|
if (array_key_exists($key, $_this->__map)) {
|
|
|
|
return $_this->__map[$key];
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-10-22 20:58:55 +00:00
|
|
|
/**
|
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
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
2007-11-16 09:35:19 +00:00
|
|
|
* Flushes all objects from the ClassRegistry.
|
2007-10-22 20:58:55 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function flush() {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
|
|
|
$_this->__objects = array();
|
|
|
|
$_this->__map = array();
|
|
|
|
}
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
2007-05-03 04:35:25 +00:00
|
|
|
?>
|