Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@dogmatic69 dogmatic69 authored
Showing with 16 additions and 15 deletions.
  1. +16 −15 lib/Cake/Utility/ObjectCollection.php
View
31 lib/Cake/Utility/ObjectCollection.php
@@ -126,6 +126,7 @@ public function trigger($callback, $params = array(), $options = array()) {
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 @@ public function enable($name, $prioritize = true) {
$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 @@ public function setPriority($name, $priority = null) {
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 @@ public function attached($name = null) {
* @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 @@ public function unload($name) {
*/
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 @@ public static function normalizeObjectArray($objects) {
$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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.