mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Moving loaded helpers into a protected array.
Adding magic methods to access the object array.
This commit is contained in:
parent
c78e869be6
commit
fcbfb556c5
2 changed files with 36 additions and 6 deletions
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue