Fixed aliasing so it works with plugins in the 'className' key

This commit is contained in:
Jeremy Harris 2011-01-14 17:44:33 -08:00
parent 39e06b0425
commit 1f0c57c4ee
6 changed files with 47 additions and 13 deletions

View file

@ -74,10 +74,13 @@ class ComponentCollection extends ObjectCollection {
* @throws MissingComponentFileException, MissingComponentClassException when the component could not be found
*/
public function load($component, $settings = array()) {
list($plugin, $name) = pluginSplit($component);
$alias = $name;
if (isset($settings['className'])) {
$name = $settings['className'];
$alias = $component;
$component = $settings['className'];
}
list($plugin, $name) = pluginSplit($component);
if (!isset($alias)) {
$alias = $name;
}
if (isset($this->_loaded[$alias])) {
return $this->_loaded[$alias];
@ -86,13 +89,13 @@ class ComponentCollection extends ObjectCollection {
if (!class_exists($componentClass)) {
if (!App::import('Component', $component)) {
throw new MissingComponentFileException(array(
'file' => Inflector::underscore($component) . '.php',
'file' => Inflector::underscore($componentClass) . '.php',
'class' => $componentClass
));
}
if (!class_exists($componentClass)) {
throw new MissingComponentClassException(array(
'file' => Inflector::underscore($component) . '.php',
'file' => Inflector::underscore($componentClass) . '.php',
'class' => $componentClass
));
}

View file

@ -99,12 +99,15 @@ class BehaviorCollection extends ObjectCollection {
* @throws MissingBehaviorFileException or MissingBehaviorClassException when a behavior could not be found.
*/
public function load($behavior, $config = array()) {
list($plugin, $name) = pluginSplit($behavior);
$alias = $name;
if (isset($config['className'])) {
$name = $config['className'];
$alias = $behavior;
$behavior = $config['className'];
}
list($plugin, $name) = pluginSplit($behavior);
if (!isset($alias)) {
$alias = $name;
}
$class = $name . 'Behavior';
if (!App::import('Behavior', $behavior)) {

View file

@ -57,11 +57,13 @@ class HelperCollection extends ObjectCollection {
* @throws MissingHelperFileException, MissingHelperClassException when the helper could not be found
*/
public function load($helper, $settings = array()) {
list($plugin, $name) = pluginSplit($helper, true);
$alias = $name;
if (isset($settings['className'])) {
$name = $settings['className'];
$alias = $helper;
$helper = $settings['className'];
}
list($plugin, $name) = pluginSplit($helper);
if (!isset($alias)) {
$alias = $name;
}
if (isset($this->_loaded[$alias])) {

View file

@ -82,6 +82,15 @@ class ComponentCollectionTest extends CakeTestCase {
$result = $this->Components->load('Cookie');
$this->assertInstanceOf('CookieAliasComponent', $result);
App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)));
$result = $this->Components->load('SomeOther', array('className' => 'TestPlugin.OtherComponent'));
$this->assertInstanceOf('OtherComponentComponent', $result);
$this->assertInstanceOf('OtherComponentComponent', $this->Components->SomeOther);
$result = $this->Components->attached();
$this->assertEquals(array('Cookie', 'SomeOther'), $result, 'attached() results are wrong.');
App::build();
}
/**

View file

@ -451,6 +451,14 @@ class BehaviorCollectionTest extends CakeTestCase {
$this->assertEquals($Apple->Behaviors->Test->testMethod($Apple, true), 'working');
$this->assertEquals($Apple->testMethod(true), 'working');
$this->assertEquals($Apple->Behaviors->dispatchMethod($Apple, 'testMethod'), 'working');
App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)));
$this->assertTrue($Apple->Behaviors->load('SomeOther', array('className' => 'TestPlugin.TestPluginPersisterOne')));
$this->assertInstanceOf('TestPluginPersisterOneBehavior', $Apple->Behaviors->SomeOther);
$result = $Apple->Behaviors->attached();
$this->assertEquals(array('Test', 'SomeOther'), $result, 'attached() results are wrong.');
App::build();
}
/**

View file

@ -80,6 +80,15 @@ class HelperCollectionTest extends CakeTestCase {
$result = $this->Helpers->load('Html');
$this->assertInstanceOf('HtmlAliasHelper', $result);
App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)));
$result = $this->Helpers->load('SomeOther', array('className' => 'TestPlugin.OtherHelper'));
$this->assertInstanceOf('OtherHelperHelper', $result);
$this->assertInstanceOf('OtherHelperHelper', $this->Helpers->SomeOther);
$result = $this->Helpers->attached();
$this->assertEquals(array('Html', 'SomeOther'), $result, 'attached() results are wrong.');
App::build();
}
/**