本文整理匯總了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());
}