Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cakephp/cakephp
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 7, 2016
2 parents 6e4d618 + b2d2f90 commit c99664e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/Datasource/ConnectionManager.php
Expand Up @@ -134,20 +134,27 @@ public static function parseDsn($config = null)
*
* 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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/TestSuite/Fixture/FixtureManager.php
Expand Up @@ -138,8 +138,8 @@ protected function _aliasConnections()
$map['test_' . $connection] = $connection;
}
}
foreach ($map as $alias => $connection) {
ConnectionManager::alias($connection, $alias);
foreach ($map as $testConnection => $normal) {
ConnectionManager::alias($testConnection, $normal);
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php
Expand Up @@ -93,6 +93,7 @@ public function testCustomTranslationTable()

$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());
}

Expand Down
5 changes: 5 additions & 0 deletions tests/test_app/TestApp/Model/Table/I18nTable.php
Expand Up @@ -24,4 +24,9 @@ public function initialize(array $config)
{
$this->table('custom_i18n_table');
}

public static function defaultConnectionName()
{
return 'custom_i18n_datasource';
}
}

0 comments on commit c99664e

Please sign in to comment.