本文整理汇总了PHP中lithium\data\Connections类的典型用法代码示例。如果您正苦于以下问题:PHP Connections类的具体用法?PHP Connections怎么用?PHP Connections使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Connections类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: skip
public function skip() {
$isAvailable = (
Connections::get('test', array('config' => true)) &&
Connections::get('test')->isConnected(array('autoConnect' => true))
);
$this->skipIf(!$isAvailable, "No test connection available");
}
开发者ID:niel,项目名称:lithium,代码行数:7,代码来源:FieldsTest.php
示例2: check
/**
* Check request reCAPTCHA validity
* This method return `true` or `false` after validation, and set error in
* helper. If `true` error is set to null, otherwise `'incorrect-captcha-sol'`
*
* Example:
* {{{
* class YourController extends \lithium\action\Controller {
* public function index() {
* if ($this->request->data) {
* if (!Recaptcha::check($this->request)) {
* return;
* }
* }
* }
* }
* }}}
* @param object $request Pass request object to check method
* @return boolean
* @throws ConfigException
* @throws RuntimeException
*/
public static function check(\lithium\net\http\Request $request)
{
$config = Libraries::get('li3_recaptcha', 'keys');
if (!$config['private']) {
throw new ConfigException('To use reCAPTCHA you must get API key from' . 'https://www.google.com/recaptcha/admin/create');
}
if (!$request->env('SERVER_ADDR')) {
throw new RuntimeException('For security reasons, you must pass the remote ip to reCAPTCHA');
}
$data = array('privatekey' => $config['private'], 'remoteip' => $request->env('SERVER_ADDR'), 'challenge' => null, 'response' => null);
if ($request->data) {
$data['challenge'] = $request->data['recaptcha_challenge_field'];
$data['response'] = $request->data['recaptcha_response_field'];
}
if (!$data['challenge'] || !$data['response']) {
RecaptchaHelper::$error = 'incorrect-captcha-sol';
return false;
}
$service = Connections::get('recaptcha');
$serviceRespond = explode("\n", $service->post('/recaptcha/api/verify', $data));
if ($serviceRespond[0] == 'true') {
RecaptchaHelper::$error = null;
return true;
} else {
RecaptchaHelper::$error = 'incorrect-captcha-sol';
return false;
}
}
开发者ID:djordje,项目名称:li3_recaptcha,代码行数:50,代码来源:Recaptcha.php
示例3: __init
public static function __init(array $options = array())
{
parent::__init($options);
$self = static::_instance();
$self->_finders['count'] = function ($self, $params, $chain) use(&$query, &$classes) {
$db = Connections::get($self::meta('connection'));
$records = $db->read('SELECT count(*) as count FROM posts', array('return' => 'array'));
return $records[0]['count'];
};
Post::applyFilter('save', function ($self, $params, $chain) {
$post = $params['record'];
if (!$post->id) {
$post->created = date('Y-m-d H:i:s');
} else {
$post->modified = date('Y-m-d H:i:s');
}
$params['record'] = $post;
return $chain->next($self, $params, $chain);
});
Validator::add('isUniqueTitle', function ($value, $format, $options) {
$conditions = array('title' => $value);
// If editing the post, skip the current psot
if (isset($options['values']['id'])) {
$conditions[] = 'id != ' . $options['values']['id'];
}
// Lookup for posts with same title
return !Post::find('first', array('conditions' => $conditions));
});
}
开发者ID:adityamooley,项目名称:Lithium-Blog-Tutorial,代码行数:29,代码来源:Post.php
示例4: skip
/**
* Skip the test if a Sqlite adapter configuration is unavailable.
*
* @return void
* @todo Tie into the Environment class to ensure that the test database is being used.
*/
public function skip()
{
$this->_dbConfig = Connections::get('sqlite3', array('config' => true));
$hasDb = isset($this->_dbConfig['adapter']) && $this->_dbConfig['adapter'] == 'Sqlite3';
$message = 'Test database is either unavailable, or not using a Sqlite adapter';
$this->skipIf(!$hasDb, $message);
}
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:13,代码来源:Sqlite3Test.php
示例5: testStreamConnection
public function testStreamConnection()
{
$config = array('socket' => 'Stream', 'host' => 'localhost', 'login' => 'root', 'password' => '', 'port' => '80');
Connections::add('stream-test', 'Http', $config);
$result = Connections::get('stream-test');
$this->assertTrue($result instanceof \lithium\data\source\Http);
}
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:7,代码来源:ConnectionsTest.php
示例6: testBasicGet
public function testBasicGet()
{
$topsy = Connections::get('test-topsy');
$headers = array('Content-Type' => 'application/json');
$results = json_decode($topsy->connection->get('authorinfo.json?url=http://twitter.com/mehlah', array(), compact('headers')));
$this->assertEqual('Mehdi Lahmam B.', $results->response->name);
}
开发者ID:mehlah,项目名称:li3_topsy,代码行数:7,代码来源:TopsyTest.php
示例7: skip
/**
* Skip the test if no `test` CouchDb connection available.
*
* @return void
*/
public function skip()
{
$isAvailable = Connections::get('test', array('config' => true)) && Connections::get('test')->isConnected(array('autoConnect' => true));
$this->skipIf(!$isAvailable, "No test connection available");
$couchConnection = strpos(get_class(Connections::get('test')), 'CouchDb');
$this->skipIf(!$couchConnection, "Test connection is not CouchDb");
}
开发者ID:EHER,项目名称:chegamos,代码行数:12,代码来源:CouchDbIntegrationTest.php
示例8: skip
/**
* Skip the test if no test database connection available.
*/
public function skip()
{
$dbConfig = Connections::get($this->_connection, ['config' => true]);
$isAvailable = $dbConfig && Connections::get($this->_connection)->isConnected(['autoConnect' => true]);
$this->skipIf(!$isAvailable, "No {$this->_connection} connection available.");
$db = Connections::get($this->_connection);
$this->skipIf(!$db instanceof Database, "The {$this->_connection} connection is not a relational database.");
}
开发者ID:jails,项目名称:li3_access,代码行数:11,代码来源:AclNodeTest.php
示例9: tearDown
public function tearDown()
{
$connection = Connections::get('default');
$mongo = $connection->connection;
foreach ($mongo->listCollections() as $collection) {
$collection->drop();
}
}
开发者ID:blainesch,项目名称:li3_fake_model,代码行数:8,代码来源:ModelTest.php
示例10: skip
/**
* Skip the test if a MySQL adapter configuration is unavailable.
*
* @return void
* @todo Tie into the Environment class to ensure that the test database is being used.
*/
public function skip()
{
$this->skipIf(!MySql::enabled(), 'MySQL Extension is not loaded');
$this->_dbConfig = Connections::get('test', array('config' => true));
$hasDb = isset($this->_dbConfig['adapter']) && $this->_dbConfig['adapter'] == 'MySql';
$message = 'Test database is either unavailable, or not using a MySQL adapter';
$this->skipIf(!$hasDb, $message);
}
开发者ID:EHER,项目名称:monopolis,代码行数:14,代码来源:MySqlTest.php
示例11: skip
public function skip()
{
$connection = $this->_connection;
$this->_dbConfig = Connections::get($this->_connection, array('config' => true));
$this->skipIf(!$this->with(array('Sqlite3')));
$this->_db = new MockSqlite3($this->_dbConfig);
$isConnected = $this->_db->isConnected(array('autoConnect' => true));
$this->skipIf(!$isConnected, "No {$connection} connection available.");
}
开发者ID:fedeisas,项目名称:lithium,代码行数:9,代码来源:Sqlite3SchemaTest.php
示例12: testAccessorMethods
/**
* Tests Collection accessors (getters/setters).
*/
public function testAccessorMethods()
{
Connections::config(array('mock-source' => array('type' => 'lithium\\tests\\mocks\\data\\MockSource')));
$model = $this->_model;
$model::config(array('connection' => false, 'key' => 'id'));
$collection = new DocumentSet(compact('model'));
$this->assertEqual($model, $collection->model());
$this->assertEqual(compact('model'), $collection->meta());
}
开发者ID:nashadalam,项目名称:lithium,代码行数:12,代码来源:CollectionTest.php
示例13: connect
public function connect($connection, $options = array())
{
$options += array('autoConnect' => true);
$this->_dbConfig = Connections::get($connection, array('config' => true));
$db = $this->_db = Connections::get($connection);
$this->skipIf(!$db, "The `{$connection}` connection is not correctly configured.");
$this->skipIf(!$db::enabled(), 'Extension is not loaded.');
$this->skipIf(!$db->isConnected($options), "No `{$connection}` connection available.");
}
开发者ID:unionofrad,项目名称:lithium,代码行数:9,代码来源:Base.php
示例14: testIssuesRead
public function testIssuesRead()
{
$gh = Connections::get('test-gh');
$query = new Query(array('model' => $this->_models['issues']));
$results = $gh->read($query);
$expected = 'octocat';
$result = $results->first();
$this->assertEqual($expected, $result->user->login);
}
开发者ID:notomato,项目名称:li3_github,代码行数:9,代码来源:GitHubTest.php
示例15: skip
public function skip()
{
$connection = 'lithium_mysql_test';
$this->_dbConfig = Connections::get($connection, array('config' => true));
$isAvailable = $this->_dbConfig && Connections::get($connection)->isConnected(array('autoConnect' => true));
$this->skipIf(!$isAvailable, "No {$connection} connection available.");
$this->db = Connections::get($connection);
$this->skipIf(!$this->db instanceof Database, "The {$connection} connection is not a relational database.");
}
开发者ID:rmarscher,项目名称:lithium,代码行数:9,代码来源:FieldsTest.php
示例16: skip
/**
* Skip the test if a MySQL adapter configuration is unavailable.
*
* @return void
* @todo Tie into the Environment class to ensure that the test database is being used.
*/
public function skip()
{
$message = 'MySQLi extension is not available for testing the adapter.';
$hasClass = class_exists('\\mysqli');
$this->skipIf(!$hasClass, $message);
$this->_dbConfig = Connections::get('MySQLi-tests', array('config' => true));
$hasDb = isset($this->_dbConfig['adapter']) && $this->_dbConfig['adapter'] == 'MySQLi';
$message = 'Test database is either unavailable, or not using a MySQLi adapter';
$this->skipIf(!$hasDb, $message);
}
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:16,代码来源:MySQLiTest.php
示例17: setUp
public function setUp()
{
$this->_backup['cwd'] = getcwd();
$this->_backup['_SERVER'] = $_SERVER;
$_SERVER['argv'] = array();
Libraries::add('create_test', array('path' => $this->_testPath . '/create_test'));
$this->request = new Request(array('input' => fopen('php://temp', 'w+')));
$this->request->params = array('library' => 'create_test', 'action' => null);
Connections::add('default', array('type' => null, 'adapter' => 'lithium\\tests\\mocks\\data\\model\\MockDatabase'));
}
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:10,代码来源:CreateTest.php
示例18: tearDown
public function tearDown()
{
Connections::remove('mockconn');
MockQueryPost::reset();
MockQueryComment::reset();
MockGallery::reset();
MockImage::reset();
MockImageTag::reset();
MockTag::reset();
}
开发者ID:unionofrad,项目名称:lithium,代码行数:10,代码来源:QueryTest.php
示例19: skip
/**
* Skip the test if no test database connection available.
*/
public function skip()
{
$connection = 'lithium_couch_test';
$config = Connections::get($connection, array('config' => true));
$isAvailable = $config && Connections::get($connection)->isConnected(array('autoConnect' => true));
$this->skipIf(!$isAvailable, "No {$connection} connection available.");
$this->_key = Companies::key();
$this->_database = $config['database'];
$this->_connection = Connections::get($connection);
}
开发者ID:newmight2015,项目名称:Blockchain-2,代码行数:13,代码来源:DocumentTest.php
示例20: testConnectWithWrongPassword
public function testConnectWithWrongPassword()
{
$config = $this->_dbConfig;
$config['login'] = 'wrong_login';
$config['password'] = 'wrong_pass';
$connection = 'wrong_passord';
Connections::add($connection, $config);
$this->expectException('/Host connected, but could not access database/');
Connections::get($connection)->connect();
}
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:10,代码来源:DatabaseTest.php
注:本文中的lithium\data\Connections类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论