simplify the code for object collection

Fixed up some abreviated variables, removing extra long lines and removed
variables that were not used.
This commit is contained in:
dogmatic69 2012-09-12 21:55:54 +01:00
parent b227ff486e
commit 91c09d87bc

View file

@ -126,6 +126,7 @@ abstract class ObjectCollection {
if ($options['modParams'] !== false && !isset($params[$options['modParams']])) {
throw new CakeException(__d('cake_dev', 'Cannot use modParams with indexes that do not exist.'));
}
$result = null;
foreach ($list as $name) {
$result = call_user_func_array(array($this->_loaded[$name], $callback), compact('subject') + $params);
if ($options['collectReturn'] === true) {
@ -180,7 +181,10 @@ abstract class ObjectCollection {
$enabled = false;
foreach ((array)$name as $object) {
if (isset($this->_loaded[$object]) && !isset($this->_enabled[$object])) {
$priority = isset($this->_loaded[$object]->settings['priority']) ? $this->_loaded[$object]->settings['priority'] : $this->defaultPriority;
$priority = $this->defaultPriority;
if (isset($this->_loaded[$object]->settings['priority'])) {
$priority = $this->_loaded[$object]->settings['priority'];
}
$this->_enabled[$object] = array($priority);
$enabled = true;
}
@ -218,14 +222,14 @@ abstract class ObjectCollection {
if (is_string($name)) {
$name = array($name => $priority);
}
foreach ($name as $obj => $prio) {
if (isset($this->_loaded[$obj])) {
if (is_null($prio)) {
$prio = $this->defaultPriority;
foreach ($name as $object => $objectPriority) {
if (isset($this->_loaded[$object])) {
if (is_null($objectPriority)) {
$objectPriority = $this->defaultPriority;
}
$this->_loaded[$obj]->settings['priority'] = $prio;
if (isset($this->_enabled[$obj])) {
$this->_enabled[$obj] = array($prio);
$this->_loaded[$object]->settings['priority'] = $objectPriority;
if (isset($this->_enabled[$object])) {
$this->_enabled[$object] = array($objectPriority);
}
}
}
@ -282,9 +286,8 @@ abstract class ObjectCollection {
* @return void
*/
public function unload($name) {
list($plugin, $name) = pluginSplit($name);
unset($this->_loaded[$name]);
unset($this->_enabled[$name]);
$name = array_pop(pluginSplit($name));
unset($this->_loaded[$name], $this->_enabled[$name]);
}
/**
@ -296,8 +299,7 @@ abstract class ObjectCollection {
*/
public function set($name = null, $object = null) {
if (!empty($name) && !empty($object)) {
list($plugin, $name) = pluginSplit($name);
$this->_loaded[$name] = $object;
$this->_loaded[array_pop(pluginSplit($name))] = $object;
}
return $this->_loaded;
}
@ -317,8 +319,7 @@ abstract class ObjectCollection {
$options = (array)$objectName;
$objectName = $i;
}
list($plugin, $name) = pluginSplit($objectName);
$normal[$name] = array('class' => $objectName, 'settings' => $options);
$normal[array_pop(pluginSplit($objectName))] = array('class' => $objectName, 'settings' => $options);
}
return $normal;
}