Skip to content

Commit

Permalink
updating code from [8024] [8025]
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8031 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
gwoo committed Feb 15, 2009
1 parent a3f4c60 commit 43ad3d7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 55 deletions.
103 changes: 50 additions & 53 deletions cake/libs/controller/component.php
Expand Up @@ -177,41 +177,27 @@ function shutdown(&$controller) {
*/
function _loadComponents(&$object, $parent = null) {
$base = $this->__controllerVars['base'];
$normal = Set::normalize($object->components);
if ($parent == null) {
$normal = Set::merge(array('Session' => null), $normal);
}
foreach ((array)$normal as $component => $config) {
$plugin = null;

if (is_array($object->components)) {
$normal = Set::normalize($object->components);
if ($parent == null) {
$normal['Session'] = array();
if (isset($this->__controllerVars['plugin'])) {
$plugin = $this->__controllerVars['plugin'] . '.';
}
foreach ($normal as $component => $config) {
$plugin = null;

if (isset($this->__controllerVars['plugin'])) {
$plugin = $this->__controllerVars['plugin'] . '.';
}

if (strpos($component, '.') !== false) {
list($plugin, $component) = explode('.', $component);
$plugin = $plugin . '.';
}
$componentCn = $component . 'Component';

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->__controllerVars['name'],
'component' => $component,
'file' => Inflector::underscore($component) . '.php',
'base' => $base,
'code' => 500
)));
return false;
}
}
if (strpos($component, '.') !== false) {
list($plugin, $component) = explode('.', $component);
$plugin = $plugin . '.';
}
$componentCn = $component . 'Component';

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->__controllerVars['name'],
'component' => $component,
'file' => Inflector::underscore($component) . '.php',
Expand All @@ -222,35 +208,46 @@ function _loadComponents(&$object, $parent = null) {
}
}

if ($parent === null) {
$this->_primary[] = $component;
if (!class_exists($componentCn)) {
$this->cakeError('missingComponentClass', array(array(
'className' => $this->__controllerVars['name'],
'component' => $component,
'file' => Inflector::underscore($component) . '.php',
'base' => $base,
'code' => 500
)));
return false;
}
}

if (isset($this->_loaded[$component])) {
$object->{$component} =& $this->_loaded[$component];
if ($parent === null) {
$this->_primary[] = $component;
}

if (!empty($config) && isset($this->__settings[$component])) {
$this->__settings[$component] = array_merge($this->__settings[$component], $config);
} elseif (!empty($config)) {
$this->__settings[$component] = $config;
}
if (isset($this->_loaded[$component])) {
$object->{$component} =& $this->_loaded[$component];

if (!empty($config) && isset($this->__settings[$component])) {
$this->__settings[$component] = array_merge($this->__settings[$component], $config);
} elseif (!empty($config)) {
$this->__settings[$component] = $config;
}
} else {
if ($componentCn === 'SessionComponent') {
$object->{$component} =& new $componentCn($base);
} else {
if ($componentCn === 'SessionComponent') {
$object->{$component} =& new $componentCn($base);
} else {
$object->{$component} =& new $componentCn();
}
$object->{$component}->enabled = true;
$this->_loaded[$component] =& $object->{$component};
if (!empty($config)) {
$this->__settings[$component] = $config;
}
$object->{$component} =& new $componentCn();
}

if (isset($object->{$component}->components) && is_array($object->{$component}->components) && (!isset($object->{$component}->{$parent}))) {
$this->_loadComponents($object->{$component}, $component);
$object->{$component}->enabled = true;
$this->_loaded[$component] =& $object->{$component};
if (!empty($config)) {
$this->__settings[$component] = $config;
}
}

if (isset($object->{$component}->components) && is_array($object->{$component}->components) && (!isset($object->{$component}->{$parent}))) {
$this->_loadComponents($object->{$component}, $component);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/controller/controller.php
Expand Up @@ -363,7 +363,7 @@ function __mergeVars() {
}

foreach ($merge as $var) {
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
if (!empty($appVars[$var]) && is_array($this->{$var})) {
if ($var === 'components') {
$normal = Set::normalize($this->{$var});
$app = Set::normalize($appVars[$var]);
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/libs/controller/controller.test.php
Expand Up @@ -864,7 +864,7 @@ function testMergeVarsNotGreedy() {
$Controller->uses = array();
$Controller->constructClasses();

$this->assertEqual($Controller->components, array('Session'));
$this->assertTrue(isset($Controller->Session));
}
/**
* testReferer method
Expand Down

0 comments on commit 43ad3d7

Please sign in to comment.