本文整理汇总了PHP中Cake\Datasource\ConnectionManager::alias方法的典型用法代码示例。如果您正苦于以下问题:PHP ConnectionManager::alias方法的具体用法?PHP ConnectionManager::alias怎么用?PHP ConnectionManager::alias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Datasource\ConnectionManager
的用法示例。
在下文中一共展示了ConnectionManager::alias方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _aliasConnections
/**
* Add aliases for all non test prefixed connections.
*
* This allows models to use the test connections without
* a pile of configuration work.
*
* @return void
* @see \Cake\TestSuite\Fixture\FixtureManager::_aliasConnections()
*/
protected function _aliasConnections()
{
$connections = ConnectionManager::configured();
ConnectionManager::alias('test', 'default');
$map = [];
foreach ($connections as $connection) {
if (in_array($connection, ['default', 'test', 'debug_kit'])) {
continue;
}
if (isset($map[$connection])) {
continue;
}
if (strpos($connection, 'test_') === 0) {
$map[$connection] = substr($connection, 5);
} else {
$map['test_' . $connection] = $connection;
}
}
foreach ($map as $alias => $connection) {
ConnectionManager::alias($alias, $connection);
}
}
示例2: testAliasError
/**
* Test alias() raises an error when aliasing an undefined connection.
*
* @expectedException \Cake\Datasource\Exception\MissingDatasourceConfigException
* @return void
*/
public function testAliasError()
{
$this->assertNotContains('test_kaboom', ConnectionManager::configured());
ConnectionManager::alias('test_kaboom', 'other_name');
}
示例3: bootstrap
/**
* A callback method that is used to inject the PDO object created from phinx into
* the CakePHP connection. This is needed in case the user decides to use tables
* from the ORM and executes queries.
*
* @param \Symfony\Component\Console\Input\InputInterface $input the input object
* @param \Symfony\Component\Console\Output\OutputInterface $output the output object
* @return void
*/
public function bootstrap(InputInterface $input, OutputInterface $output)
{
parent::bootstrap($input, $output);
$name = $this->getConnectionName($input);
ConnectionManager::alias($name, 'default');
$connection = ConnectionManager::get($name);
$manager = $this->getManager();
if (!$manager instanceof CakeManager) {
$this->setManager(new CakeManager($this->getConfig(), $output));
}
$env = $this->getManager()->getEnvironment('default');
$adapter = $env->getAdapter();
if (!$adapter instanceof CakeAdapter) {
$env->setAdapter(new CakeAdapter($adapter, $connection));
}
}
示例4: testGetMockForModelSecondaryDatasource
/**
* Test getMockForModel on secondary datasources.
*
* @return void
*/
public function testGetMockForModelSecondaryDatasource()
{
ConnectionManager::alias('test', 'secondary');
$post = $this->getMockForModel(__NAMESPACE__ . '\\SecondaryPostsTable', ['save']);
$this->assertEquals('test', $post->connection()->configName());
}
示例5: _aliasConnections
/**
* Add aliases for all non test prefixed connections.
*
* This allows models to use the test connections without
* a pile of configuration work.
*
* @return void
*/
protected function _aliasConnections()
{
$connections = ConnectionManager::configured();
ConnectionManager::alias('test', 'default');
$map = [];
foreach ($connections as $connection) {
if ($connection === 'test' || $connection === 'default') {
continue;
}
if (isset($map[$connection])) {
continue;
}
if (strpos($connection, 'test_') === 0) {
$map[$connection] = substr($connection, 5);
} else {
$map['test_' . $connection] = $connection;
}
}
foreach ($map as $testConnection => $normal) {
ConnectionManager::alias($testConnection, $normal);
}
}
示例6: testGetWithConnectionName
/**
* Test that get() uses config data set with config()
*
* @return void
*/
public function testGetWithConnectionName()
{
ConnectionManager::alias('test', 'testing');
$result = $this->_locator->get('Articles', ['connectionName' => 'testing']);
$this->assertEquals('articles', $result->table());
$this->assertEquals('test', $result->connection()->configName());
}