Browse Source

Merge branch 'master' of github.com:cakephp/cakephp

Mark Story 10 years ago
parent
commit
c99664e363

+ 13 - 6
src/Datasource/ConnectionManager.php

@@ -134,20 +134,27 @@ class ConnectionManager
      *
      * You can remove aliases with ConnectionManager::dropAlias().
      *
-     * @param string $original The connection to add an alias to.
-     * @param string $target The alias to create. Fetching $original will return $target when loaded with get().
+     * ### Usage
+     *
+     * ```
+     * // Make 'things' resolve to 'test_things' connection
+     * ConnectionManager::alias('test_things', 'things');
+     * ```
+     *
+     * @param string $alias The alias to add. Fetching $source will return $alias when loaded with get.
+     * @param string $source The connection to add an alias to.
      * @return void
      * @throws \Cake\Datasource\Exception\MissingDatasourceConfigException When aliasing a
      * connection that does not exist.
      */
-    public static function alias($original, $target)
+    public static function alias($alias, $source)
     {
-        if (empty(static::$_config[$target]) && empty(static::$_config[$original])) {
+        if (empty(static::$_config[$source]) && empty(static::$_config[$alias])) {
             throw new MissingDatasourceConfigException(
-                sprintf('Cannot create alias of "%s" as it does not exist.', $original)
+                sprintf('Cannot create alias of "%s" as it does not exist.', $alias)
             );
         }
-        static::$_aliasMap[$target] = $original;
+        static::$_aliasMap[$source] = $alias;
     }
 
     /**

+ 2 - 2
src/TestSuite/Fixture/FixtureManager.php

@@ -138,8 +138,8 @@ class FixtureManager
                 $map['test_' . $connection] = $connection;
             }
         }
-        foreach ($map as $alias => $connection) {
-            ConnectionManager::alias($connection, $alias);
+        foreach ($map as $testConnection => $normal) {
+            ConnectionManager::alias($testConnection, $normal);
         }
     }
 

+ 1 - 0
tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php

@@ -93,6 +93,7 @@ class TranslateBehaviorTest extends TestCase
 
         $this->assertEquals('\TestApp\Model\Table\I18nTable', $i18n->name());
         $this->assertInstanceOf('TestApp\Model\Table\I18nTable', $i18n->target());
+        $this->assertEquals('test_custom_i18n_datasource', $i18n->target()->connection()->configName());
         $this->assertEquals('custom_i18n_table', $i18n->target()->table());
     }
 

+ 5 - 0
tests/test_app/TestApp/Model/Table/I18nTable.php

@@ -24,4 +24,9 @@ class I18nTable extends Table
     {
         $this->table('custom_i18n_table');
     }
+
+    public static function defaultConnectionName()
+    {
+        return 'custom_i18n_datasource';
+    }
 }