"Adding fix when a component loads a component that is also in the components array list.

{{{
	var $components = array('Auth', 'RequestHandler');
}}}
Controller::RequestHandler; would not be available.
Added additional tests

Fixed loading of libs/xml.php "

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6372 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-01-13 03:53:01 +00:00
parent d564eda38d
commit 11afd24c19
3 changed files with 60 additions and 57 deletions

View file

@ -465,6 +465,9 @@ class Configure extends Object {
if ($path == '.' || in_array(realpath($path), $used)) {
continue;
}
if (is_dir($path . DS . 'cake' . DS . 'libs')) {
$paths['libs'][] = $path . DS . 'cake' . DS . 'libs' . DS;
}
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'model')) {
$paths['model'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'model' . DS;
}
@ -483,9 +486,6 @@ class Configure extends Object {
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'view' . DS . 'helpers')) {
$paths['helper'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS;
}
if (is_dir($path . DS . 'cake' . DS . 'libs')) {
$paths['libs'][] = $path . DS . 'cake' . DS . 'libs' . DS;
}
if (is_dir($path . DS . 'cake')) {
$paths['cake'][] = $path . DS . 'cake' . DS;
$paths['class'][] = $path . DS . 'cake' . DS;

View file

@ -101,21 +101,10 @@ class Component extends Object {
$componentCn = $component . 'Component';
if (in_array($component, array_keys($loaded)) !== true) {
if (!class_exists($componentCn)) {
if (is_null($plugin) || !App::import('Component', $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(
if (!class_exists($componentCn)) {
if (is_null($plugin) || !App::import('Component', $plugin . '.' . $component)) {
if (!App::import('Component', $component)) {
$this->cakeError('missingComponentFile', array(array(
'className' => $this->controller->name,
'component' => $component,
'file' => Inflector::underscore($component) . '.php',
@ -123,30 +112,38 @@ class Component extends Object {
exit();
}
}
$base = null;
if ($componentCn == 'SessionComponent') {
$base = $this->controller->base;
}
if ($parent === null) {
$this->controller->{$component} =& new $componentCn($base);
$loaded[$component] =& $this->controller->{$component};
} elseif ($parent !== null) {
$this->controller->{$parent}->{$component} =& new $componentCn($base);
$loaded[$component] =& $this->controller->{$parent}->{$component};
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();
}
}
$base = null;
if ($componentCn == 'SessionComponent') {
$base = $this->controller->base;
}
if (isset($this->controller->{$component}->components) && is_array($this->controller->{$component}->components)) {
$loaded =& $this->_loadComponents($loaded, $this->controller->{$component}->components, $component);
}
if ($parent === null) {
$this->controller->{$component} =& new $componentCn($base);
$loaded[$component] =& $this->controller->{$component};
} elseif ($parent !== null) {
$this->controller->{$parent}->{$component} =& new $componentCn($base);
$loaded[$component] =& $this->controller->{$parent}->{$component};
}
if (isset($this->controller->{$component}->components) && is_array($this->controller->{$component}->components)) {
$loaded =& $this->_loadComponents($loaded, $this->controller->{$component}->components, $component);
}
if (isset($loaded[$parent])) {
$loaded[$parent]->{$component} =& $loaded[$component];
}
}
return $loaded;
}
}

View file

@ -41,38 +41,44 @@ class ComponentTest extends CakeTestCase {
function setUp() {
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
$this->Controller = new ComponentTestController();
}
function tearDown() {
unset($this->Controller);
}
function testLoadComponents() {
$this->Controller->components = array('RequestHandler');
$Component = new Component($this->Controller);
$Controller = new ComponentTestController();
$Controller->components = array('RequestHandler');
$loaded = array();
$result = $Component->init($this->Controller);
$this->assertTrue(is_object($this->Controller->RequestHandler));
$Component = new Component($Controller);
$Component->init($Controller);
$this->Controller->plugin = 'test_plugin';
$this->Controller->components = array('RequestHandler', 'TestPluginComponent');
$this->assertTrue(is_a($Controller->RequestHandler, 'RequestHandlerComponent'));
$result = $Component->init($this->Controller);
$Controller = new ComponentTestController();
$Controller->plugin = 'test_plugin';
$Controller->components = array('RequestHandler', 'TestPluginComponent');
$this->assertTrue(is_object($this->Controller->RequestHandler));
$this->assertTrue(is_object($this->Controller->TestPluginComponent));
$this->assertTrue(is_object($this->Controller->TestPluginComponent->TestPluginOtherComponent));
$this->assertFalse(isset($this->Controller->TestPluginOtherComponent));
$this->Controller->components = array('Security');
$result = $Component->init($this->Controller);
$this->assertTrue(is_object($this->Controller->Security));
$this->assertTrue(is_object($this->Controller->Security->Session));
$Component->init($Controller);
$this->assertTrue(is_a($Controller->RequestHandler, 'RequestHandlerComponent'));
$this->assertTrue(is_a($Controller->TestPluginComponent, 'TestPluginComponentComponent'));
$this->assertTrue(is_a($Controller->TestPluginComponent->TestPluginOtherComponent, 'TestPluginOtherComponentComponent'));
$this->assertFalse(isset($Controller->TestPluginOtherComponent));
$Controller = new ComponentTestController();
$Controller->components = array('Security');
$result = $Component->init($Controller);
$this->assertTrue(is_object($Controller->Security));
$this->assertTrue(is_object($Controller->Security->Session));
Configure::write('Security.salt', 'oUubWwvniR2G0FgaC9miDYhG93b0qyJfIxfs2guV');
$Controller = new ComponentTestController();
$Controller->components = array('Security', 'Cookie', 'RequestHandler');
$result = $Component->init($Controller);
$this->assertTrue(is_a($Controller->Security, 'SecurityComponent'));
$this->assertTrue(is_a($Controller->Security->RequestHandler, 'RequestHandlerComponent'));
$this->assertTrue(is_a($Controller->RequestHandler, 'RequestHandlerComponent'));
$this->assertTrue(is_a($Controller->Cookie, 'CookieComponent'));
}
}
?>