From 91c09d87bcda582b492fdd5cb330068df49fe24b Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Wed, 12 Sep 2012 21:55:54 +0100 Subject: [PATCH] simplify the code for object collection Fixed up some abreviated variables, removing extra long lines and removed variables that were not used. --- lib/Cake/Utility/ObjectCollection.php | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/Cake/Utility/ObjectCollection.php b/lib/Cake/Utility/ObjectCollection.php index 96ec3d555..300f65095 100644 --- a/lib/Cake/Utility/ObjectCollection.php +++ b/lib/Cake/Utility/ObjectCollection.php @@ -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; }