Skip to content
This repository
Browse code

simplify the code for object collection

Fixed up some abreviated variables, removing extra long lines and removed
variables that were not used.
  • Loading branch information...
commit 91c09d87bcda582b492fdd5cb330068df49fe24b 1 parent b227ff4
Carl Sutton authored September 12, 2012

Showing 1 changed file with 16 additions and 15 deletions. Show diff stats Hide diff stats

  1. 31  lib/Cake/Utility/ObjectCollection.php
31  lib/Cake/Utility/ObjectCollection.php
@@ -126,6 +126,7 @@ public function trigger($callback, $params = array(), $options = array()) {
126 126
 		if ($options['modParams'] !== false && !isset($params[$options['modParams']])) {
127 127
 			throw new CakeException(__d('cake_dev', 'Cannot use modParams with indexes that do not exist.'));
128 128
 		}
  129
+		$result = null;
129 130
 		foreach ($list as $name) {
130 131
 			$result = call_user_func_array(array($this->_loaded[$name], $callback), compact('subject') + $params);
131 132
 			if ($options['collectReturn'] === true) {
@@ -180,7 +181,10 @@ public function enable($name, $prioritize = true) {
180 181
 		$enabled = false;
181 182
 		foreach ((array)$name as $object) {
182 183
 			if (isset($this->_loaded[$object]) && !isset($this->_enabled[$object])) {
183  
-				$priority = isset($this->_loaded[$object]->settings['priority']) ? $this->_loaded[$object]->settings['priority'] : $this->defaultPriority;
  184
+				$priority = $this->defaultPriority;
  185
+				if (isset($this->_loaded[$object]->settings['priority'])) {
  186
+					$priority = $this->_loaded[$object]->settings['priority'];
  187
+				}
184 188
 				$this->_enabled[$object] = array($priority);
185 189
 				$enabled = true;
186 190
 			}
@@ -218,14 +222,14 @@ public function setPriority($name, $priority = null) {
218 222
 		if (is_string($name)) {
219 223
 			$name = array($name => $priority);
220 224
 		}
221  
-		foreach ($name as $obj => $prio) {
222  
-			if (isset($this->_loaded[$obj])) {
223  
-				if (is_null($prio)) {
224  
-					$prio = $this->defaultPriority;
  225
+		foreach ($name as $object => $objectPriority) {
  226
+			if (isset($this->_loaded[$object])) {
  227
+				if (is_null($objectPriority)) {
  228
+					$objectPriority = $this->defaultPriority;
225 229
 				}
226  
-				$this->_loaded[$obj]->settings['priority'] = $prio;
227  
-				if (isset($this->_enabled[$obj])) {
228  
-					$this->_enabled[$obj] = array($prio);
  230
+				$this->_loaded[$object]->settings['priority'] = $objectPriority;
  231
+				if (isset($this->_enabled[$object])) {
  232
+					$this->_enabled[$object] = array($objectPriority);
229 233
 				}
230 234
 			}
231 235
 		}
@@ -282,9 +286,8 @@ public function attached($name = null) {
282 286
  * @return void
283 287
  */
284 288
 	public function unload($name) {
285  
-		list($plugin, $name) = pluginSplit($name);
286  
-		unset($this->_loaded[$name]);
287  
-		unset($this->_enabled[$name]);
  289
+		$name = array_pop(pluginSplit($name));
  290
+		unset($this->_loaded[$name], $this->_enabled[$name]);
288 291
 	}
289 292
 
290 293
 /**
@@ -296,8 +299,7 @@ public function unload($name) {
296 299
  */
297 300
 	public function set($name = null, $object = null) {
298 301
 		if (!empty($name) && !empty($object)) {
299  
-			list($plugin, $name) = pluginSplit($name);
300  
-			$this->_loaded[$name] = $object;
  302
+			$this->_loaded[array_pop(pluginSplit($name))] = $object;
301 303
 		}
302 304
 		return $this->_loaded;
303 305
 	}
@@ -317,8 +319,7 @@ public static function normalizeObjectArray($objects) {
317 319
 				$options = (array)$objectName;
318 320
 				$objectName = $i;
319 321
 			}
320  
-			list($plugin, $name) = pluginSplit($objectName);
321  
-			$normal[$name] = array('class' => $objectName, 'settings' => $options);
  322
+			$normal[array_pop(pluginSplit($objectName))] = array('class' => $objectName, 'settings' => $options);
322 323
 		}
323 324
 		return $normal;
324 325
 	}

0 notes on commit 91c09d8

Please sign in to comment.
Something went wrong with that request. Please try again.