本文整理汇总了PHP中ClassRegistry::config方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassRegistry::config方法的具体用法?PHP ClassRegistry::config怎么用?PHP ClassRegistry::config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClassRegistry
的用法示例。
在下文中一共展示了ClassRegistry::config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* Initialize the fixture.
*
* @param object Cake's DBO driver (e.g: DboMysql).
* @access public
*
*/
function init() {
if (isset($this->import) && (is_string($this->import) || is_array($this->import))) {
$import = array_merge(
array('connection' => 'default', 'records' => false),
is_array($this->import) ? $this->import : array('model' => $this->import)
);
if (isset($import['model']) && App::import('Model', $import['model'])) {
ClassRegistry::config(array('ds' => $import['connection']));
$model =& ClassRegistry::init($import['model']);
$db =& ConnectionManager::getDataSource($model->useDbConfig);
$db->cacheSources = false;
$this->fields = $model->schema(true);
$this->fields[$model->primaryKey]['key'] = 'primary';
$this->table = $db->fullTableName($model, false);
ClassRegistry::config(array('ds' => 'test_suite'));
ClassRegistry::flush();
} elseif (isset($import['table'])) {
$model =& new Model(null, $import['table'], $import['connection']);
$db =& ConnectionManager::getDataSource($import['connection']);
$db->cacheSources = false;
$model->useDbConfig = $import['connection'];
$model->name = Inflector::camelize(Inflector::singularize($import['table']));
$model->table = $import['table'];
$model->tablePrefix = $db->config['prefix'];
$this->fields = $model->schema(true);
ClassRegistry::flush();
}
if (!empty($db->config['prefix']) && strpos($this->table, $db->config['prefix']) === 0) {
$this->table = str_replace($db->config['prefix'], '', $this->table);
}
if (isset($import['records']) && $import['records'] !== false && isset($model) && isset($db)) {
$this->records = array();
$query = array(
'fields' => $db->fields($model, null, array_keys($this->fields)),
'table' => $db->fullTableName($model),
'alias' => $model->alias,
'conditions' => array(),
'order' => null,
'limit' => null,
'group' => null
);
$records = $db->fetchAll($db->buildStatement($query, $model), false, $model->alias);
if ($records !== false && !empty($records)) {
$this->records = Set::extract($records, '{n}.' . $model->alias);
}
}
}
if (!isset($this->table)) {
$this->table = Inflector::underscore(Inflector::pluralize($this->name));
}
if (!isset($this->primaryKey) && isset($this->fields['id'])) {
$this->primaryKey = 'id';
}
}
示例2: 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'));
}
示例3: _initDb
/**
* Initializes this class with a DataSource object to use as default for all fixtures
*
* @return void
*/
protected function _initDb()
{
if ($this->_initialized) {
return;
}
$db = ConnectionManager::getDataSource('test');
$this->_db = $db;
ClassRegistry::config(array('ds' => 'test'));
$this->_initialized = true;
}
示例4: suite
/**
* @return CakeTestSuite
*/
public static function suite()
{
ClassRegistry::config(['ds' => 'test']);
$suite = new CakeTestSuite('Working Tests');
$suite->addTestFile(TESTS . 'Case/WorldPayTest.php');
// $suite->addTestFile(TESTS.'Case/NetSuiteTest.php');
// $suite->addTestFile(TESTS.'Case/BackOrderRestockTest.php');
$suite->addTestFile(TESTS . 'Case/QueueTasksTest.php');
// $suite->addTestFile(TESTS.'Case/PresenterRollupTest.php');
$suite->addTestFile(TESTS . 'Case/OrderNotificationsTest.php');
$suite->addTestFile(TESTS . 'Case/ShoppingCartTest.php');
$suite->addTestFile(TESTS . 'Case/OrdersTest.php');
$suite->addTestFile(TESTS . 'Case/SnapDirectTest.php');
$suite->addTestFile(TESTS . 'Case/InventoryTest.php');
return $suite;
}
示例5: init
/**
* Initialize the fixture.
*
* @param object Cake's DBO driver (e.g: DboMysql).
* @access public
*
*/
function init()
{
if (isset($this->import) && (is_string($this->import) || is_array($this->import))) {
$import = array();
if (is_string($this->import) || is_array($this->import) && isset($this->import['model'])) {
$import = array_merge(array('records' => false), ife(is_array($this->import), $this->import, array()));
$import['model'] = ife(is_array($this->import), $this->import['model'], $this->import);
} elseif (isset($this->import['table'])) {
$import = array_merge(array('connection' => 'default', 'records' => false), $this->import);
}
if (isset($import['model']) && (class_exists($import['model']) || App::import('Model', $import['model']))) {
$connection = isset($import['connection']) ? $import['connection'] : 'test_suite';
ClassRegistry::config(array('ds' => $connection));
$model =& ClassRegistry::init($import['model']);
$db =& ConnectionManager::getDataSource($model->useDbConfig);
$db->cacheSources = false;
$this->fields = $model->schema(true);
$this->fields[$model->primaryKey]['key'] = 'primary';
} elseif (isset($import['table'])) {
$model =& new Model(null, $import['table'], $import['connection']);
$db =& ConnectionManager::getDataSource($import['connection']);
$db->cacheSources = false;
$model->name = Inflector::camelize(Inflector::singularize($import['table']));
$model->table = $import['table'];
$model->tablePrefix = $db->config['prefix'];
$this->fields = $model->schema(true);
}
if ($import['records'] !== false && isset($model) && isset($db)) {
$this->records = array();
$query = array('fields' => array_keys($this->fields), 'table' => $db->name($model->table), 'alias' => $model->alias, 'conditions' => array(), 'order' => null, 'limit' => null, 'group' => null);
foreach ($query['fields'] as $index => $field) {
$query['fields'][$index] = $db->name($query['alias']) . '.' . $db->name($field);
}
$records = $db->fetchAll($db->buildStatement($query, $model), false, $model->alias);
if ($records !== false && !empty($records)) {
$this->records = Set::extract($records, '{n}.' . $model->alias);
}
}
}
if (!isset($this->table)) {
$this->table = Inflector::underscore(Inflector::pluralize($this->name));
}
if (!isset($this->primaryKey) && isset($this->fields['id'])) {
$this->primaryKey = 'id';
}
}
示例6: _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'));
}
示例7: fixturize
/**
* Inspects the test to look for unloaded fixtures and loads them
*
* @param CakeTestCase $test the test case to inspect
* @return void
*/
public function fixturize($test)
{
if (!$this->_initialized) {
ClassRegistry::config(array('ds' => 'test', 'testing' => true));
}
if (empty($test->fixtures) || !empty($this->_processed[get_class($test)])) {
$test->db = $this->_db;
return;
}
$this->_initDb();
$test->db = $this->_db;
if (!is_array($test->fixtures)) {
$test->fixtures = array_map('trim', explode(',', $test->fixtures));
}
if (isset($test->fixtures)) {
$this->_loadFixtures($test->fixtures);
}
$this->_processed[get_class($test)] = true;
}
示例8: all
/**
* Bake All the controllers at once. Will only bake controllers for models that exist.
*
* @return void
*/
public function all()
{
$this->interactive = false;
$this->listAll($this->connection, false);
ClassRegistry::config('Model', array('ds' => $this->connection));
$unitTestExists = $this->_checkUnitTest();
$admin = false;
if (!empty($this->params['admin'])) {
$admin = $this->Project->getPrefix();
}
$controllersCreated = 0;
foreach ($this->__tables as $table) {
$model = $this->_modelName($table);
$controller = $this->_controllerName($model);
App::uses($model, 'Model');
if (class_exists($model)) {
$actions = $this->bakeActions($controller);
if ($admin) {
$this->out(__d('cake_console', 'Adding %s methods', $admin));
$actions .= "\n" . $this->bakeActions($controller, $admin);
}
if ($this->bake($controller, $actions) && $unitTestExists) {
$this->bakeTest($controller);
}
$controllersCreated++;
}
}
if (!$controllersCreated) {
$this->out(__d('cake_console', 'No Controllers were baked, Models need to exist before Controllers can be baked.'));
}
}
示例9: getMockForModel
/**
* Mock a model, maintain fixtures and table association
*
* @param string $model
* @param mixed $methods
* @param array $config
* @throws MissingModelException
* @return Model
*/
public function getMockForModel($model, $methods = array(), $config = array())
{
$config += ClassRegistry::config('Model');
list($plugin, $name) = pluginSplit($model, true);
App::uses($name, $plugin . 'Model');
$config = array_merge((array) $config, array('name' => $name));
if (!class_exists($name)) {
throw new MissingModelException(array($model));
}
$mock = $this->getMock($name, $methods, array($config));
ClassRegistry::removeObject($name);
ClassRegistry::addObject($name, $mock);
return $mock;
}
示例10: all
/**
* Bake All the controllers at once. Will only bake controllers for models that exist.
*
* @return void
*/
public function all()
{
$this->interactive = false;
$this->listAll($this->connection, false);
ClassRegistry::config('Model', array('ds' => $this->connection));
$unitTestExists = $this->_checkUnitTest();
foreach ($this->__tables as $table) {
$model = $this->_modelName($table);
$controller = $this->_controllerName($model);
App::uses($model, 'Model');
if (class_exists($model)) {
$actions = $this->bakeActions($controller);
if ($this->bake($controller, $actions) && $unitTestExists) {
$this->bakeTest($controller);
}
}
}
}
示例11: all
/**
* Bake All the controllers at once. Will only bake controllers for models that exist.
*
* @access public
* @return void
*/
function all()
{
$this->interactive = false;
$this->listAll($this->connection, false);
ClassRegistry::config('Model', array('ds' => $this->connection));
$unitTestExists = $this->_checkUnitTest();
foreach ($this->__tables as $table) {
$model = $this->_modelName($table);
$admin = $this->Project->getPrefix();
$controller = $this->_controllerName($model);
if (App::import('Model', $model)) {
$actions = $this->bakeActions($controller, $admin);
// $actions .= "\n" . $this->bakeActions($controller, 'co_');
// $actions .= "\n" . $this->bakeActions($controller, 'eo_');
if ($this->bake($controller, $actions) && $unitTestExists) {
$this->bakeTest($controller);
}
}
}
}
示例12: testArrayToArrayHasAndBelongsToMany
/**
* testArrayToArrayHasAndBelongsToMany
*
* @return void
* @access public
*/
function testArrayToArrayHasAndBelongsToMany()
{
ClassRegistry::config(array());
$model = ClassRegistry::init('ArrayModel');
$model->unBindModel(array('hasOne' => array('Relate')), false);
$model->bindModel(array('hasAndBelongsToMany' => array('Relate' => array('className' => 'ArrayModel', 'with' => 'ArraysRelateModel', 'associationForeignKey' => 'relate_id'))), false);
$result = $model->find('all', array('recursive' => 1));
$expected = array(array('ArrayModel' => array('id' => 1, 'name' => 'USA', 'relate_id' => 1), 'Relate' => array(array('id' => 1, 'name' => 'USA', 'relate_id' => 1), array('id' => 2, 'name' => 'Brazil', 'relate_id' => 1), array('id' => 3, 'name' => 'Germany', 'relate_id' => 2))), array('ArrayModel' => array('id' => 2, 'name' => 'Brazil', 'relate_id' => 1), 'Relate' => array(array('id' => 1, 'name' => 'USA', 'relate_id' => 1), array('id' => 3, 'name' => 'Germany', 'relate_id' => 2))), array('ArrayModel' => array('id' => 3, 'name' => 'Germany', 'relate_id' => 2), 'Relate' => array(array('id' => 1, 'name' => 'USA', 'relate_id' => 1), array('id' => 2, 'name' => 'Brazil', 'relate_id' => 1))));
$this->assertEqual($result, $expected);
}
示例13: _handleVersion
/**
* バージョンコントロールをします。
* クライアントはヘッダにAPIVersionを含めることで使用するバージョンを指定できます。
* 指定されなかった場合、ApiComponent::$recetnVersionが使用されます。
*
* @param Controller $controller
* @return void
*/
protected function _handleVersion($controller)
{
$modelConfig = ClassRegistry::config('Model');
if (!empty($modelConfig['testing'])) {
$this->version = $this->recentVersion;
if ($version = Configure::read('TEST_API_VERSION')) {
$this->version = $version;
}
return;
}
$this->version = $this->currentVersion;
if ($version = $controller->request->header('APIVersion')) {
$this->version = $version;
}
}
示例14: getMockForModel
/**
* Mock a model, maintain fixtures and table association
*
* @param string $model The model to get a mock for.
* @param mixed $methods The list of methods to mock
* @param array $config The config data for the mock's constructor.
*
* @throws MissingModelException
* @return Model
*/
public function getMockForModel($model, $methods = array(), $config = array())
{
$config += ClassRegistry::config('Model');
list($plugin, $name) = pluginSplit($model, TRUE);
App::uses($name, $plugin . 'Model');
$config = array_merge((array) $config, array('name' => $name));
unset($config['ds']);
if (!class_exists($name)) {
throw new MissingModelException(array($model));
}
$mock = $this->getMock($name, $methods, array($config));
$availableDs = array_keys(ConnectionManager::enumConnectionObjects());
if ($mock->useDbConfig !== 'test' && in_array('test_' . $mock->useDbConfig, $availableDs)) {
$mock->setDataSource('test_' . $mock->useDbConfig);
} else {
$mock->useDbConfig = 'test';
$mock->setDataSource('test');
}
ClassRegistry::removeObject($name);
ClassRegistry::addObject($name, $mock);
return $mock;
}
示例15: generate
/**
* Generates a mocked controller and mocks any classes passed to `$mocks`. By
* default, `_stop()` is stubbed as is sending the response headers, so to not
* interfere with testing.
*
* ### Mocks:
*
* - `methods` Methods to mock on the controller. `_stop()` is mocked by default
* - `models` Models to mock. Models are added to the ClassRegistry so they any
* time they are instantiated the mock will be created. Pass as key value pairs
* with the value being specific methods on the model to mock. If `true` or
* no value is passed, the entire model will be mocked.
* - `components` Components to mock. Components are only mocked on this controller
* and not within each other (i.e., components on components)
*
* @param string $controller Controller name
* @param array $mocks List of classes and methods to mock
* @return Controller Mocked controller
* @throws MissingControllerException When controllers could not be created.
* @throws MissingComponentException When components could not be created.
*/
public function generate($controller, $mocks = array())
{
list($plugin, $controller) = pluginSplit($controller);
if ($plugin) {
App::uses($plugin . 'AppController', $plugin . '.Controller');
$plugin .= '.';
}
App::uses($controller . 'Controller', $plugin . 'Controller');
if (!class_exists($controller . 'Controller')) {
throw new MissingControllerException(array('class' => $controller . 'Controller', 'plugin' => substr($plugin, 0, -1)));
}
ClassRegistry::flush();
$mocks = array_merge_recursive(array('methods' => array('_stop'), 'models' => array(), 'components' => array()), (array) $mocks);
list($plugin, $name) = pluginSplit($controller);
$controllerObj = $this->getMock($name . 'Controller', $mocks['methods'], array(), '', false);
$controllerObj->name = $name;
$request = $this->getMock('CakeRequest');
$response = $this->getMock('CakeResponse', array('_sendHeader'));
$controllerObj->__construct($request, $response);
$controllerObj->Components->setController($controllerObj);
$config = ClassRegistry::config('Model');
foreach ($mocks['models'] as $model => $methods) {
if (is_string($methods)) {
$model = $methods;
$methods = true;
}
if ($methods === true) {
$methods = array();
}
$this->getMockForModel($model, $methods, $config);
}
foreach ($mocks['components'] as $component => $methods) {
if (is_string($methods)) {
$component = $methods;
$methods = true;
}
if ($methods === true) {
$methods = array();
}
list($plugin, $name) = pluginSplit($component, true);
$componentClass = $name . 'Component';
App::uses($componentClass, $plugin . 'Controller/Component');
if (!class_exists($componentClass)) {
throw new MissingComponentException(array('class' => $componentClass));
}
$config = isset($controllerObj->components[$component]) ? $controllerObj->components[$component] : array();
$componentObj = $this->getMock($componentClass, $methods, array($controllerObj->Components, $config));
$controllerObj->Components->set($name, $componentObj);
$controllerObj->Components->enable($name);
}
$controllerObj->constructClasses();
$this->_dirtyController = false;
$this->controller = $controllerObj;
return $this->controller;
}