diff --git a/cake/libs/object_collection.php b/cake/libs/object_collection.php index 97ff33d7a..3395ad774 100644 --- a/cake/libs/object_collection.php +++ b/cake/libs/object_collection.php @@ -35,6 +35,13 @@ abstract class ObjectCollection { */ protected $_disabled = array(); +/** + * A hash of loaded helpers, indexed by the classname + * + * @var array + */ + protected $_loaded = array(); + /** * Loads a new object onto the collection. Can throw a variety of exceptions * @@ -96,6 +103,29 @@ abstract class ObjectCollection { 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 a behavior or array of behaviors * diff --git a/cake/libs/view/helper_collection.php b/cake/libs/view/helper_collection.php index 15e5ab46f..0db172266 100644 --- a/cake/libs/view/helper_collection.php +++ b/cake/libs/view/helper_collection.php @@ -48,8 +48,8 @@ class HelperCollection extends ObjectCollection { public function load($helper, $settings = array(), $enable = true) { list($plugin, $name) = pluginSplit($helper, true); - if (isset($this->{$name})) { - return $this->{$name}; + if (isset($this->_loaded[$name])) { + return $this->_loaded[$name]; } $helperClass = $name . 'Helper'; if (!class_exists($helperClass)) { @@ -60,11 +60,11 @@ class HelperCollection extends ObjectCollection { throw new MissingHelperClassException($helperClass); } } - $this->{$name} = new $helperClass($this->_View, $settings); + $this->_loaded[$name] = new $helperClass($this->_View, $settings); $vars = array('base', 'webroot', 'here', 'params', 'action', 'data', 'theme', 'plugin'); foreach ($vars as $var) { - $this->{$name}->{$var} = $this->_View->{$var}; + $this->_loaded[$name]->{$var} = $this->_View->{$var}; } if (!in_array($name, $this->_attached)) { @@ -73,7 +73,7 @@ class HelperCollection extends ObjectCollection { if ($enable === false) { $this->_disabled[] = $name; } - return $this->{$name}; + return $this->_loaded[$name]; } /** @@ -84,7 +84,7 @@ class HelperCollection extends ObjectCollection { */ public function unload($name) { list($plugin, $name) = pluginSplit($name); - unset($this->{$name}); + unset($this->_loaded[$name]); $this->_attached = array_values(array_diff($this->_attached, (array)$name)); }