本文整理汇总了PHP中Cake\ORM\TableRegistry::config方法的典型用法代码示例。如果您正苦于以下问题:PHP TableRegistry::config方法的具体用法?PHP TableRegistry::config怎么用?PHP TableRegistry::config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\TableRegistry
的用法示例。
在下文中一共展示了TableRegistry::config方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMockForModel
/**
* Mock a model, maintain fixtures and table association
*
* @param string $alias
* @param array $methods
* @param array $options
* @throws \Cake\ORM\Error\MissingTableClassException
* @return Model
*/
public function getMockForModel($alias, array $methods = array(), array $options = array())
{
if (empty($options['className'])) {
$class = Inflector::camelize($alias);
$className = App::classname($class, 'Model/Table', 'Table');
if (!$className) {
throw new \Cake\ORM\Error\MissingTableClassException(array($alias));
}
$options['className'] = $className;
}
list($plugin, $baseClass) = pluginSplit($alias);
$options += ['alias' => $baseClass] + TableRegistry::config($alias);
$mock = $this->getMock($options['className'], $methods, array($options));
TableRegistry::set($alias, $mock);
return $mock;
}
示例2: testConfigAndBuild
/**
* Tests that table options can be pre-configured for the factory method
*
* @return void
*/
public function testConfigAndBuild()
{
TableRegistry::clear();
$map = TableRegistry::config();
$this->assertEquals([], $map);
$connection = ConnectionManager::get('test', false);
$options = ['connection' => $connection];
TableRegistry::config('users', $options);
$map = TableRegistry::config();
$this->assertEquals(['users' => $options], $map);
$this->assertEquals($options, TableRegistry::config('users'));
$schema = ['id' => ['type' => 'rubbish']];
$options += ['schema' => $schema];
TableRegistry::config('users', $options);
$table = TableRegistry::get('users', ['table' => 'users']);
$this->assertInstanceOf('Cake\\ORM\\Table', $table);
$this->assertEquals('users', $table->table());
$this->assertEquals('users', $table->alias());
$this->assertSame($connection, $table->connection());
$this->assertEquals(array_keys($schema), $table->schema()->columns());
$this->assertEquals($schema['id']['type'], $table->schema()->column('id')['type']);
TableRegistry::clear();
$this->assertEmpty(TableRegistry::config());
TableRegistry::config('users', $options);
$table = TableRegistry::get('users', ['className' => __NAMESPACE__ . '\\MyUsersTable']);
$this->assertInstanceOf(__NAMESPACE__ . '\\MyUsersTable', $table);
$this->assertEquals('users', $table->table());
$this->assertEquals('users', $table->alias());
$this->assertSame($connection, $table->connection());
$this->assertEquals(array_keys($schema), $table->schema()->columns());
}
示例3: getMockForModel
/**
* Mock a model, maintain fixtures and table association
*
* @param string $alias The model to get a mock for.
* @param mixed $methods The list of methods to mock
* @param array $options The config data for the mock's constructor.
* @throws \Cake\ORM\Exception\MissingTableClassException
* @return \Cake\ORM\Table|\PHPUnit_Framework_MockObject_MockObject
*/
public function getMockForModel($alias, array $methods = [], array $options = [])
{
if (empty($options['className'])) {
$class = Inflector::camelize($alias);
$className = App::className($class, 'Model/Table', 'Table');
if (!$className) {
throw new MissingTableClassException([$alias]);
}
$options['className'] = $className;
}
$connectionName = $options['className']::defaultConnectionName();
$connection = ConnectionManager::get($connectionName);
list(, $baseClass) = pluginSplit($alias);
$options += ['alias' => $baseClass, 'connection' => $connection];
$options += TableRegistry::config($alias);
$mock = $this->getMock($options['className'], $methods, [$options]);
if (empty($options['entityClass']) && $mock->entityClass() === '\\Cake\\ORM\\Entity') {
$parts = explode('\\', $options['className']);
$entityAlias = Inflector::singularize(substr(array_pop($parts), 0, -5));
$entityClass = implode('\\', array_slice($parts, 0, -1)) . '\\Entity\\' . $entityAlias;
if (class_exists($entityClass)) {
$mock->entityClass($entityClass);
}
}
TableRegistry::set($baseClass, $mock);
return $mock;
}
示例4: testConfigWithMultipleValidators
/**
* Tests that table options can be pre-configured with multiple validators
*
* @return void
*/
public function testConfigWithMultipleValidators()
{
$validator1 = new Validator();
$validator2 = new Validator();
$validator3 = new Validator();
TableRegistry::config('users', ['validator' => ['default' => $validator1, 'secondary' => $validator2, 'tertiary' => $validator3]]);
$table = TableRegistry::get('users');
$this->assertSame($table->validator('default'), $validator1);
$this->assertSame($table->validator('secondary'), $validator2);
$this->assertSame($table->validator('tertiary'), $validator3);
}
示例5: getMockForModel
/**
* Mock a model, maintain fixtures and table association
*
* @param string $alias The model to get a mock for.
* @param mixed $methods The list of methods to mock
* @param array $options The config data for the mock's constructor.
* @throws \Cake\ORM\Exception\MissingTableClassException
* @return Model
*/
public function getMockForModel($alias, array $methods = array(), array $options = array())
{
if (empty($options['className'])) {
$class = Inflector::camelize($alias);
$className = App::className($class, 'Model/Table', 'Table');
if (!$className) {
throw new \Cake\ORM\Exception\MissingTableClassException(array($alias));
}
$options['className'] = $className;
}
$connectionName = $options['className']::defaultConnectionName();
$connection = ConnectionManager::get($connectionName);
list($plugin, $baseClass) = pluginSplit($alias);
$options += ['alias' => $baseClass, 'connection' => $connection];
$options += TableRegistry::config($alias);
$mock = $this->getMock($options['className'], $methods, [$options]);
TableRegistry::set($alias, $mock);
return $mock;
}
示例6: catch
* @copyright Copyright 2010 - 2015, Cake Development Corporation (+1 702 425 5085) (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
use Cake\Core\Configure;
use Cake\Core\Exception\MissingPluginException;
use Cake\Core\Plugin;
use Cake\Event\EventManager;
use Cake\Log\Log;
use Cake\ORM\TableRegistry;
use Cake\Routing\Router;
Configure::load('CakeDC/Users.users');
collection((array) Configure::read('Users.config'))->each(function ($file) {
Configure::load($file);
});
TableRegistry::config('Users', ['className' => Configure::read('Users.table')]);
TableRegistry::config('CakeDC/Users.Users', ['className' => Configure::read('Users.table')]);
if (Configure::check('Users.auth')) {
Configure::write('Auth.authenticate.all.userModel', Configure::read('Users.table'));
}
if (Configure::read('Users.Social.login') && php_sapi_name() != 'cli') {
try {
EventManager::instance()->on(\CakeDC\Users\Controller\Component\UsersAuthComponent::EVENT_FAILED_SOCIAL_LOGIN, [new \CakeDC\Users\Controller\UsersController(), 'failedSocialLoginListener']);
} catch (MissingPluginException $e) {
Log::error($e->getMessage());
}
}
$oauthPath = Configure::read('OAuth.path');
if (is_array($oauthPath)) {
Router::scope('/auth', function ($routes) use($oauthPath) {
$routes->connect('/:provider', $oauthPath, ['provider' => implode('|', array_keys(Configure::read('OAuth.providers')))]);
});
示例7: testConfig
/**
* Test config() method.
*
* @return void
*/
public function testConfig()
{
$locator = $this->_setMockLocator();
$locator->expects($this->once())->method('config')->with('Test', []);
TableRegistry::config('Test', []);
}
示例8:
<?php
use Cake\ORM\TableRegistry;
/**
* Create aliases for core objects.
*/
TableRegistry::config('Users', ['className' => 'BEdita\\Core\\Model\\Table\\UsersTable']);