Browse Source

ObjectRegistry::loaded() now only returns lists of all loaded objects.

ADmad 11 years ago
parent
commit
e8ded81846
4 changed files with 19 additions and 12 deletions
  1. 13 6
      src/Core/ObjectRegistry.php
  2. 1 1
      src/Log/Log.php
  3. 4 4
      src/ORM/BehaviorRegistry.php
  4. 1 1
      src/ORM/Table.php

+ 13 - 6
src/Core/ObjectRegistry.php

@@ -155,14 +155,21 @@ abstract class ObjectRegistry {
 	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);
 	}

+ 1 - 1
src/Log/Log.php

@@ -191,7 +191,7 @@ class Log {
 			if (isset($properties['engine'])) {
 				$properties['className'] = $properties['engine'];
 			}
-			if (!static::$_registry->loaded($name)) {
+			if (!static::$_registry->has($name)) {
 				static::$_registry->load($name, $properties);
 			}
 		}

+ 4 - 4
src/ORM/BehaviorRegistry.php

@@ -134,7 +134,7 @@ class BehaviorRegistry extends ObjectRegistry {
 		$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"',
@@ -148,7 +148,7 @@ class BehaviorRegistry extends ObjectRegistry {
 		}
 
 		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"',
@@ -202,7 +202,7 @@ class BehaviorRegistry extends ObjectRegistry {
  */
 	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);
 		}
@@ -223,7 +223,7 @@ class BehaviorRegistry extends ObjectRegistry {
 	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);
 		}

+ 1 - 1
src/ORM/Table.php

@@ -542,7 +542,7 @@ class Table implements RepositoryInterface, EventListenerInterface {
  * @return array
  */
 	public function hasBehavior($name) {
-		return $this->_behaviors->loaded($name);
+		return $this->_behaviors->has($name);
 	}
 
 /**