_enabled)) { return true; } $options = array_merge( array('break' => false, 'breakOn' => false), $options ); foreach ($this->_enabled as $name) { $result = call_user_func_array(array(&$this->_loaded[$name], $callback), $params); if ( $options['break'] && ($result === $options['breakOn'] || (is_array($options['breakOn']) && in_array($result, $options['breakOn'], true))) ) { return $result; } } return true; } /** * Provide public read access to the loaded objects * * @param string $name Name of property to read * @return mixed */ public function __get($name) { if (isset($this->_loaded[$name])) { return $this->_loaded[$name]; } return null; } /** * Provide isset access to _loaded * * @param sting $name Name of object being checked. * @return boolean */ public function __isset($name) { return isset($this->_loaded[$name]); } /** * Enables callbacks on an object or array of objects * * @param mixed $name CamelCased name of the object(s) to enable (string or array) * @return void */ public function enable($name) { foreach ((array)$name as $object) { if (isset($this->_loaded[$object]) && array_search($object, $this->_enabled) === false) { $this->_enabled[] = $object; } } } /** * Disables callbacks on a object or array of objects. Public object methods are still * callable as normal. * * @param mixed $name CamelCased name of the objects(s) to disable (string or array) * @return void */ public function disable($name) { foreach ((array)$name as $object) { $index = array_search($object, $this->_enabled); unset($this->_enabled[$index]); } $this->_enabled = array_values($this->_enabled); } /** * Gets the list of currently-enabled objects, or, the current status of a single objects * * @param string $name Optional. The name of the object to check the status of. If omitted, * returns an array of currently-enabled object * @return mixed If $name is specified, returns the boolean status of the corresponding object. * Otherwise, returns an array of all enabled objects. */ public function enabled($name = null) { if (!empty($name)) { return in_array($name, $this->_enabled); } return $this->_enabled; } /** * Gets the list of attached behaviors, or, whether the given behavior is attached * * @param string $name Optional. The name of the behavior to check the status of. If omitted, * returns an array of currently-attached behaviors * @return mixed If $name is specified, returns the boolean status of the corresponding behavior. * Otherwise, returns an array of all attached behaviors. */ public function attached($name = null) { if (!empty($name)) { return isset($this->_loaded[$name]); } return array_keys($this->_loaded); } /** * Normalizes an object array, creates an array that makes lazy loading * easier * * @param array $objects Array of child objects to normalize. * @return array Array of normalized objects. */ public static function normalizeObjectArray($objects) { $normal = array(); foreach ($objects as $i => $objectName) { $options = array(); if (!is_int($i)) { list($options, $objectName) = array($objectName, $i); } list($plugin, $name) = pluginSplit($objectName); $normal[$name] = array('class' => $objectName, 'settings' => $options); } return $normal; } }