Skip to content

Commit

Permalink
ObjectRegistry::loaded() now only returns lists of all loaded objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Nov 26, 2014
1 parent 61e1057 commit e8ded81
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
19 changes: 13 additions & 6 deletions src/Core/ObjectRegistry.php
Expand Up @@ -155,14 +155,21 @@ abstract protected function _throwMissingClassError($class, $plugin);
abstract protected function _create($class, $alias, $config);

/**
* Get the loaded object list, or check whether or not a given object is loaded.
* Get the list of loaded objects.
*
* @param null|string $name The object name to get or null.
* @return array|\Cake\View\Helper Either a list of object names, or a loaded object.
* @return array List of object names.
*/
public function loaded($name = null) {
if (!empty($name)) {
return isset($this->_loaded[$name]);
public function loaded() {
if (func_num_args() > 0) {
$class = get_class($this);
trigger_error(
sprintf(
"%s::loaded() doesn't take object name as argument any more. Use %s::has() instead.",
$class,
$class
),
E_USER_ERROR
);
}
return array_keys($this->_loaded);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Log/Log.php
Expand Up @@ -191,7 +191,7 @@ protected static function _loadConfig() {
if (isset($properties['engine'])) {
$properties['className'] = $properties['engine'];
}
if (!static::$_registry->loaded($name)) {
if (!static::$_registry->has($name)) {
static::$_registry->load($name, $properties);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/ORM/BehaviorRegistry.php
Expand Up @@ -134,7 +134,7 @@ protected function _getMethods(Behavior $instance, $class, $alias) {
$methods = array_change_key_case($instance->implementedMethods());

foreach ($finders as $finder => $methodName) {
if (isset($this->_finderMap[$finder]) && $this->loaded($this->_finderMap[$finder][0])) {
if (isset($this->_finderMap[$finder]) && $this->has($this->_finderMap[$finder][0])) {
$duplicate = $this->_finderMap[$finder];
$error = sprintf(
'%s contains duplicate finder "%s" which is already provided by "%s"',
Expand All @@ -148,7 +148,7 @@ protected function _getMethods(Behavior $instance, $class, $alias) {
}

foreach ($methods as $method => $methodName) {
if (isset($this->_methodMap[$method]) && $this->loaded($this->_methodMap[$method][0])) {
if (isset($this->_methodMap[$method]) && $this->has($this->_methodMap[$method][0])) {
$duplicate = $this->_methodMap[$method];
$error = sprintf(
'%s contains duplicate method "%s" which is already provided by "%s"',
Expand Down Expand Up @@ -202,7 +202,7 @@ public function hasFinder($method) {
*/
public function call($method, array $args = []) {
$method = strtolower($method);
if ($this->hasMethod($method) && $this->loaded($this->_methodMap[$method][0])) {
if ($this->hasMethod($method) && $this->has($this->_methodMap[$method][0])) {
list($behavior, $callMethod) = $this->_methodMap[$method];
return call_user_func_array([$this->_loaded[$behavior], $callMethod], $args);
}
Expand All @@ -223,7 +223,7 @@ public function call($method, array $args = []) {
public function callFinder($type, array $args = []) {
$type = strtolower($type);

if ($this->hasFinder($type) && $this->loaded($this->_finderMap[$type][0])) {
if ($this->hasFinder($type) && $this->has($this->_finderMap[$type][0])) {
list($behavior, $callMethod) = $this->_finderMap[$type];
return call_user_func_array([$this->_loaded[$behavior], $callMethod], $args);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Table.php
Expand Up @@ -542,7 +542,7 @@ public function behaviors() {
* @return array
*/
public function hasBehavior($name) {
return $this->_behaviors->loaded($name);
return $this->_behaviors->has($name);
}

/**
Expand Down

0 comments on commit e8ded81

Please sign in to comment.