本文整理汇总了PHP中ConnectionManager::enumConnectionObjects方法的典型用法代码示例。如果您正苦于以下问题:PHP ConnectionManager::enumConnectionObjects方法的具体用法?PHP ConnectionManager::enumConnectionObjects怎么用?PHP ConnectionManager::enumConnectionObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionManager
的用法示例。
在下文中一共展示了ConnectionManager::enumConnectionObjects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: configure
static function configure()
{
if (empty($_COOKIE['selenium'])) {
return;
}
$cookie = $_COOKIE['selenium'];
App::import('Model', 'ConnectionManager', false);
ClassRegistry::flush();
Configure::write('Cache.disable', true);
$testDbAvailable = in_array('test', array_keys(ConnectionManager::enumConnectionObjects()));
$_prefix = null;
if ($testDbAvailable) {
// Try for test DB
restore_error_handler();
@($db =& ConnectionManager::getDataSource('test'));
set_error_handler('simpleTestErrorHandler');
$testDbAvailable = $db->isConnected();
}
// Try for default DB
if (!$testDbAvailable) {
$db =& ConnectionManager::getDataSource('default');
}
$_prefix = $db->config['prefix'];
$db->config['prefix'] = $cookie . '_';
ConnectionManager::create('test_suite', $db->config);
$db->config['prefix'] = $_prefix;
// Get db connection
$db =& ConnectionManager::getDataSource('test_suite');
$db->cacheSources = false;
ClassRegistry::config(array('ds' => 'test_suite'));
}
示例2: _isDatasourceAvailable
protected static function _isDatasourceAvailable($datasource = 'default')
{
if (self::_instantiated($datasource)) {
return true;
}
$sourceList = ConnectionManager::enumConnectionObjects();
return array_key_exists($datasource, $sourceList);
}
示例3: setUp
/**
* setUp
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->Model = new StripeAppModel();
$this->Model->setDataSource('stripe_test');
$sources = ConnectionManager::enumConnectionObjects();
$this->skipIf(!in_array('stripe_test', array_keys($sources)), '`stripe_test` db config not found');
}
示例4: startTest
/**
* Sets up the environment for each test method
*
* @return void
* @access public
*/
public function startTest()
{
$connections = ConnectionManager::enumConnectionObjects();
if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') {
$config = new DATABASE_CONFIG();
$this->_config = $config->test;
}
ConnectionManager::create('mongo_test', $this->_config);
}
示例5: setUp
/**
* setUp
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->Model = new StripeCustomer();
$this->Model->setDataSource('stripe_test');
$sources = ConnectionManager::enumConnectionObjects();
$this->skipIf(!in_array('stripe_test', array_keys($sources)), '`stripe_test` db config not found');
$this->Source = $this->Model->getDataSource('stripe_test');
$this->Source->Http = $this->getMock('HttpSocket', array('request'));
}
示例6: startTest
/**
* Sets up the environment for each test method
*
* @return void
* @access public
*/
public function startTest()
{
$connections = ConnectionManager::enumConnectionObjects();
if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') {
$config = new DATABASE_CONFIG();
$this->_config = $config->test;
}
ConnectionManager::create('mongo_test', $this->_config);
$this->Mongo = new MongodbSource($this->_config);
$this->Post = ClassRegistry::init(array('class' => 'SqlCompatiblePost', 'alias' => 'Post', 'ds' => 'mongo_test'));
$this->_setupData();
}
示例7: setUp
public function setUp()
{
$connections = ConnectionManager::enumConnectionObjects();
if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') {
$config = new DATABASE_CONFIG();
$this->_config = $config->test;
}
if (!isset($connections['test_mongo'])) {
ConnectionManager::create('test_mongo', $this->_config);
$this->Mongo = new MongodbSource($this->_config);
}
$this->Post = ClassRegistry::init(array('class' => 'SqlCompatiblePost', 'alias' => 'Post', 'ds' => 'test_mongo'), true);
}
示例8: getConfig
/**
* Get a user specified Connection name
*
* @return void
*/
public function getConfig()
{
App::uses('ConnectionManager', 'Model');
$configs = ConnectionManager::enumConnectionObjects();
$useDbConfig = key($configs);
if (!is_array($configs) || empty($configs)) {
return $this->execute();
}
$connections = array_keys($configs);
if (count($connections) > 1) {
$useDbConfig = $this->in(__d('cake_console', 'Use Database Config') . ':', $connections, $useDbConfig);
}
return $useDbConfig;
}
示例9: startTest
/**
* Sets up the environment for each test method
*
* @return void
* @access public
*/
public function startTest()
{
$connections = ConnectionManager::enumConnectionObjects();
if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') {
$config = new DATABASE_CONFIG();
$this->_config = $config->test;
}
ConnectionManager::create('mongo_test', $this->_config);
$this->Mongo = new MongodbSource($this->_config);
$this->Post = ClassRegistry::init('Post');
$this->Post->setDataSource('mongo_test');
$this->mongodb =& ConnectionManager::getDataSource($this->Post->useDbConfig);
$this->dropData();
}
示例10: getSlave
private function getSlave()
{
if (!defined('APP_DEV') || APP_DEV) {
return $this->useDbConfig;
}
$sources_list = ConnectionManager::enumConnectionObjects();
$slaves = array();
foreach ($sources_list as $name => $values) {
if (preg_match('/^slave[0-9]+$/i', $name) == 1) {
$slaves[] = $name;
}
}
return $slaves[rand(0, count($slaves) - 1)];
}
示例11: _initDb
protected function _initDb()
{
$testDbAvailable = in_array('test', array_keys(ConnectionManager::enumConnectionObjects()));
if ($testDbAvailable) {
// Try for test DB
restore_error_handler();
$db = ConnectionManager::getDataSource('test');
$testDbAvailable = $db->isConnected();
}
// Try for default DB
if (!$testDbAvailable) {
$db = ConnectionManager::getDataSource('default');
$db->config['prefix'] = 'test_suite_';
}
ConnectionManager::create('test_suite', $db->config);
ClassRegistry::config(array('ds' => 'test_suite'));
}
示例12: authorize
public function authorize($user, \CakeRequest $request)
{
$dbs = ConnectionManager::enumConnectionObjects();
$connNames = array_keys($dbs);
$Apis = key($this->settings['Apis']) === 0 ? $this->settings['Apis'] : array_keys($this->settings['Apis']);
$apiNames = array_intersect($Apis, $connNames);
$authorized = true;
foreach ($apiNames as $name) {
$storeMethod = empty($this->settings['Apis'][$name]['store']) ? 'Db' : ucfirst($this->settings['Apis'][$name]['store']);
$Store = $this->_getTokenStore($storeMethod);
if ($Store instanceof TokenStoreInterface) {
$allowed = $Store->checkToken($name, $user['id']);
}
$this->controller()->Apis[$name]['authorized'] = $allowed;
if (!$allowed) {
$authorized = false;
}
}
return $authorized;
}
示例13: _initDb
/**
* Initializes this class with a DataSource object to use as default for all fixtures
*
* @return void
*/
protected function _initDb()
{
if ($this->_initialized) {
return;
}
$testDbAvailable = in_array('test', array_keys(ConnectionManager::enumConnectionObjects()));
$_prefix = null;
if ($testDbAvailable) {
// Try for test DB
@($db = ConnectionManager::getDataSource('test'));
$testDbAvailable = $db->isConnected();
} else {
throw new MissingConnectionException(__('You need to create a $test datasource connection to start using fixtures'));
}
if (!$testDbAvailable) {
throw new MissingConnectionException(__('Unable to connect to the $test datasource'));
}
$this->_db = $db;
ClassRegistry::config(array('ds' => 'test'));
$this->_initialized = true;
}
示例14: main
/**
* Truncates all tables and loads fixtures into db
*
* @return void
* @access public
*/
function main()
{
if (!empty($this->args) && $this->args[0] != 'all') {
$fixtures = $this->args;
foreach ($fixtures as $i => $fixture) {
$fixtures[$i] = APP . 'tests/fixtures/' . $fixture . '_fixture.php';
}
} elseif (!empty($this->args) && $this->args[0] == 'all') {
App::import('Folder');
$Folder = new Folder(APP . 'tests/fixtures');
$fixtures = $Folder->findRecursive('.+_fixture\\.php');
} else {
$this->out('Usage: cake fixtures [ all | <table-name-singluar> ]');
return;
}
$datasource = 'default';
if (isset($this->params['datasource'])) {
$datasource = $this->params['datasource'];
}
$list = ConnectionManager::enumConnectionObjects();
if (!isset($list[$datasource])) {
$this->error("Data Source", "Non-existent data source '{$datasource}'");
}
$db = ConnectionManager::getDataSource($datasource);
$records = 0;
foreach ($fixtures as $path) {
require_once $path;
$name = str_replace('_fixture.php', '', basename($path));
$class = Inflector::camelize($name) . 'Fixture';
$Fixture =& new $class($db);
$this->out('-> Truncating table "' . $Fixture->table . '"');
$db->truncate($Fixture->table);
$Fixture->insert($db);
$fixtureRecords = count($Fixture->records);
$records += $fixtureRecords;
$this->out('-> Inserting ' . $fixtureRecords . ' records for "' . $Fixture->table . '"');
}
$this->out(sprintf('-> Done inserting %d records for %d tables', $records, count($fixtures)));
}
示例15: __construct
/**
* Sets up the configuration for the model, and loads databse from Multi Tenant Site
*
* @param Model $model Model using this behavior.
* @param array $config Configuration options.
* @return void
*/
public function __construct($id = false, $table = null, $ds = null)
{
// usar el correspondiente al tenant
//debug( Router::$_requests );
if (CakeSession::started()) {
$currentTenant = MtSites::getSiteName();
if ($currentTenant) {
// listar sources actuales
$sources = ConnectionManager::enumConnectionObjects();
//copiar del default
$tenantConf = $sources['default'];
// colocar el nombre de la base de datos
$tenantConf['database'] = $tenantConf['database'] . "_" . $currentTenant;
// crear la conexion con la bd
$confName = 'tenant_' . $currentTenant;
ConnectionManager::create($confName, $tenantConf);
// usar tenant para este model
$this->useDbConfig = $confName;
}
}
// ahora construir el Model
parent::__construct($id, $table, $ds);
}