Browse Source

Split TableRegistry::locator() into a getter and a setter.

Robert Pustułka 9 years ago
parent
commit
6846686622
1 changed files with 23 additions and 1 deletions
  1. 23 1
      src/ORM/TableRegistry.php

+ 23 - 1
src/ORM/TableRegistry.php

@@ -69,13 +69,24 @@ class TableRegistry
      *
      * @param \Cake\ORM\Locator\LocatorInterface|null $locator Instance of a locator to use.
      * @return \Cake\ORM\Locator\LocatorInterface
+     * @deprecated 3.5.0 Use getter/setter instead.
      */
     public static function locator(LocatorInterface $locator = null)
     {
         if ($locator) {
-            static::$_locator = $locator;
+            static::setTableLocator($locator);
         }
 
+        return static::getTableLocator();
+    }
+
+    /**
+     * Returns a singleton instance of LocatorInterface implementation.
+     *
+     * @return \Cake\ORM\Locator\LocatorInterface
+     */
+    public static function getTableLocator()
+    {
         if (!static::$_locator) {
             static::$_locator = new static::$_defaultLocatorClass;
         }
@@ -84,6 +95,17 @@ class TableRegistry
     }
 
     /**
+     * Sets singleton instance of LocatorInterface implementation.
+     *
+     * @param \Cake\ORM\Locator\LocatorInterface|null $locator Instance of a locator to use.
+     * @return void
+     */
+    public static function setTableLocator(LocatorInterface $locator)
+    {
+        static::$_locator = $locator;
+    }
+
+    /**
      * Stores a list of options to be used when instantiating an object
      * with a matching alias.
      *