本文整理汇总了PHP中lithium\data\Connections::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Connections::get方法的具体用法?PHP Connections::get怎么用?PHP Connections::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\data\Connections
的用法示例。
在下文中一共展示了Connections::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
示例2: 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);
}
示例3: 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");
}
示例4: 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");
}
示例5: 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);
}
示例6: 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);
}
示例7: __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));
});
}
示例8: tearDown
public function tearDown()
{
$connection = Connections::get('default');
$mongo = $connection->connection;
foreach ($mongo->listCollections() as $collection) {
$collection->drop();
}
}
示例9: 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.");
}
示例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);
}
示例11: setUp
/**
* Setup method run before every test method.
*/
public function setUp()
{
if (empty($this->_backup)) {
foreach (Connections::get() as $conn) {
$this->_backup[$conn] = Connections::get($conn, array('config' => true));
}
}
Connections::reset();
}
示例12: 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.");
}
示例13: 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.");
}
示例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);
}
示例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.");
}