"Fixes #3743, Loading mechanism tries to load files twice from same location.

Fixes #3751, Behavior of Configure::listObjects() changed."

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6209 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-12-23 04:42:59 +00:00
parent 17610a5287
commit c98d1457ac
4 changed files with 46 additions and 10 deletions

View file

@ -125,9 +125,9 @@ class ClassRegistry {
$options = array('id' => $id, 'table' => $table, 'ds' => $ds, 'alias' => $alias, 'name' => $class);
}
if (App::import($type, $plugin . $class)) {
${$class} = new $class($options);
${$class} =& new $class($options);
} elseif ($type === 'Model') {
${$class} = new AppModel($options);
${$class} =& new AppModel($options);
}
if (!isset(${$class})) {
@ -136,7 +136,7 @@ class ClassRegistry {
}
if ($type !== 'Model') {
$_this->addObject($this->alias, ${$class});
$_this->addObject($alias, ${$class});
} else {
$_this->map($alias, $class);
}

View file

@ -730,6 +730,13 @@ class App extends Object {
* @access private
*/
var $__paths = array();
/**
* Holds loaded files
*
* @var array
* @access private
*/
var $__loaded = array();
/**
* Will find Classes based on the $name, or can accept specific file to search for
*
@ -927,10 +934,15 @@ class App extends Object {
function __load($file) {
$_this =& App::getInstance();
if (!$_this->return && in_array($file, $_this->__loaded)) {
return true;
}
if (file_exists($file)) {
if (!$_this->return) {
require($file);
}
$_this->__loaded[] = $file;
return true;
}
return false;

View file

@ -56,7 +56,12 @@ class ClassRegistryTest extends UnitTestCase {
$Tag->name = 'SomeNewName';
if (PHP5) {
$TagCopy = ClassRegistry::getObject('RegisterArticleTag');
} else {
$TagCopy =& ClassRegistry::getObject('RegisterArticleTag');
}
$this->assertTrue(is_a($TagCopy, 'RegisterArticleTag'));
$this->assertIdentical($Tag, $TagCopy);

View file

@ -44,15 +44,27 @@ class AppImportTest extends UnitTestCase {
if (!class_exists('AppController')) {
$classes = array_flip(get_declared_classes());
if (PHP5) {
$this->assertFalse(isset($classes['PagesController']));
$this->assertFalse(isset($classes['AppController']));
} else {
$this->assertFalse(isset($classes['pagescontroller']));
$this->assertFalse(isset($classes['appcontroller']));
}
$file = App::import('Controller', 'Pages');
$this->assertTrue($file);
$classes = array_flip(get_declared_classes());
if (PHP5) {
$this->assertTrue(isset($classes['PagesController']));
$this->assertTrue(isset($classes['AppController']));
} else {
$this->assertTrue(isset($classes['pagescontroller']));
$this->assertTrue(isset($classes['appcontroller']));
}
}
}
@ -115,15 +127,22 @@ class AppImportTest extends UnitTestCase {
$this->assertFalse(isset($classes['i18n']));
$this->assertFalse(isset($classes['Socket']));
$load = App::import($toLoad);
$this->assertTrue($load);
$classes = array_flip(get_declared_classes());
if (PHP5) {
$this->assertTrue(isset($classes['I18n']));
} else {
$this->assertTrue(isset($classes['i18n']));
}
$load = App::import(array('I18n', 'SomeNotFoundClass', 'Socket'));
$this->assertFalse($load);
$load = App::import($toLoad);
$this->assertTrue($load);
}
/**
* This test only works if you have plugins/my_plugin set up.