Reversed alias and actual class to be more consistent with how Model aliases load and to make migration easier

This commit is contained in:
Jeremy Harris 2011-01-13 18:04:06 -08:00
parent 24d90c17d6
commit 2b596859cb
6 changed files with 11 additions and 10 deletions

View file

@ -76,8 +76,8 @@ class ComponentCollection extends ObjectCollection {
public function load($component, $settings = array()) { public function load($component, $settings = array()) {
list($plugin, $name) = pluginSplit($component); list($plugin, $name) = pluginSplit($component);
$alias = $name; $alias = $name;
if (isset($settings['alias'])) { if (isset($settings['className'])) {
$alias = $settings['alias']; $name = $settings['className'];
} }
if (isset($this->_loaded[$alias])) { if (isset($this->_loaded[$alias])) {
return $this->_loaded[$alias]; return $this->_loaded[$alias];

View file

@ -100,11 +100,12 @@ class BehaviorCollection extends ObjectCollection {
*/ */
public function load($behavior, $config = array()) { public function load($behavior, $config = array()) {
list($plugin, $name) = pluginSplit($behavior); list($plugin, $name) = pluginSplit($behavior);
$class = $name . 'Behavior';
$alias = $name; $alias = $name;
if (isset($config['alias'])) { if (isset($config['className'])) {
$alias = $config['alias']; $name = $config['className'];
} }
$class = $name . 'Behavior';
if (!App::import('Behavior', $behavior)) { if (!App::import('Behavior', $behavior)) {
throw new MissingBehaviorFileException(array( throw new MissingBehaviorFileException(array(

View file

@ -60,8 +60,8 @@ class HelperCollection extends ObjectCollection {
list($plugin, $name) = pluginSplit($helper, true); list($plugin, $name) = pluginSplit($helper, true);
$alias = $name; $alias = $name;
if (isset($settings['alias'])) { if (isset($settings['className'])) {
$alias = $settings['alias']; $name = $settings['className'];
} }
if (isset($this->_loaded[$alias])) { if (isset($this->_loaded[$alias])) {

View file

@ -70,7 +70,7 @@ class ComponentCollectionTest extends CakeTestCase {
* @return void * @return void
*/ */
function testLoadWithAlias() { function testLoadWithAlias() {
$result = $this->Components->load('CookieAlias', array('alias' => 'Cookie', 'somesetting' => true)); $result = $this->Components->load('Cookie', array('className' => 'CookieAlias', 'somesetting' => true));
$this->assertInstanceOf('CookieAliasComponent', $result); $this->assertInstanceOf('CookieAliasComponent', $result);
$this->assertInstanceOf('CookieAliasComponent', $this->Components->Cookie); $this->assertInstanceOf('CookieAliasComponent', $this->Components->Cookie);
$this->assertTrue($this->Components->Cookie->settings['somesetting']); $this->assertTrue($this->Components->Cookie->settings['somesetting']);

View file

@ -443,7 +443,7 @@ class BehaviorCollectionTest extends CakeTestCase {
$Apple = new Apple(); $Apple = new Apple();
$this->assertIdentical($Apple->Behaviors->attached(), array()); $this->assertIdentical($Apple->Behaviors->attached(), array());
$Apple->Behaviors->load('TestAlias', array('alias' => 'Test', 'somesetting' => true)); $Apple->Behaviors->load('Test', array('className' => 'TestAlias', 'somesetting' => true));
$this->assertIdentical($Apple->Behaviors->attached(), array('Test')); $this->assertIdentical($Apple->Behaviors->attached(), array('Test'));
$this->assertInstanceOf('TestAliasBehavior', $Apple->Behaviors->Test); $this->assertInstanceOf('TestAliasBehavior', $Apple->Behaviors->Test);
$this->assertTrue($Apple->Behaviors->Test->settings['Apple']['somesetting']); $this->assertTrue($Apple->Behaviors->Test->settings['Apple']['somesetting']);

View file

@ -69,7 +69,7 @@ class HelperCollectionTest extends CakeTestCase {
* @return void * @return void
*/ */
function testLoadWithAlias() { function testLoadWithAlias() {
$result = $this->Helpers->load('HtmlAlias', array('alias' => 'Html')); $result = $this->Helpers->load('Html', array('className' => 'HtmlAlias'));
$this->assertInstanceOf('HtmlAliasHelper', $result); $this->assertInstanceOf('HtmlAliasHelper', $result);
$this->assertInstanceOf('HtmlAliasHelper', $this->Helpers->Html); $this->assertInstanceOf('HtmlAliasHelper', $this->Helpers->Html);