php lithium-data-Connections类(方法)实例源码

下面列出了php lithium-data-Connections 类(方法)源码代码实例,从而了解它的用法。

作者:nie    项目:lithiu   
public function skip() {
		$isAvailable = (
			Connections::get('test', array('config' => true)) &&
			Connections::get('test')->isConnected(array('autoConnect' => true))
		);
		$this->skipIf(!$isAvailable, "No test connection available");
	}

作者:djordj    项目:li3_recaptch   
/**
  * 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;
     }
 }

作者:adityamoole    项目:Lithium-Blog-Tutoria   
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));
     });
 }

作者:kdambekaln    项目:framework-bench   
/**
  * 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);
 }

作者:kdambekaln    项目:framework-bench   
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);
 }

作者:mehla    项目:li3_tops   
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);
 }

作者:EHE    项目:chegamo   
/**
  * 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");
 }

作者:jail    项目:li3_acces   
/**
  * 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.");
 }

作者:blainesc    项目:li3_fake_mode   
public function tearDown()
 {
     $connection = Connections::get('default');
     $mongo = $connection->connection;
     foreach ($mongo->listCollections() as $collection) {
         $collection->drop();
     }
 }

作者:EHE    项目:monopoli   
/**
  * 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);
 }

作者:fedeisa    项目:lithiu   
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.");
 }

作者:nashadala    项目:lithiu   
/**
  * 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());
 }

作者:unionofra    项目:lithiu   
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.");
 }

作者:notomat    项目:li3_githu   
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);
 }

作者:rmarsche    项目:lithiu   
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.");
 }

作者:kdambekaln    项目:framework-bench   
/**
  * 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);
 }

作者:davidpersso    项目:FrameworkBenchmark   
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'));
 }

作者:unionofra    项目:lithiu   
public function tearDown()
 {
     Connections::remove('mockconn');
     MockQueryPost::reset();
     MockQueryComment::reset();
     MockGallery::reset();
     MockImage::reset();
     MockImageTag::reset();
     MockTag::reset();
 }

作者:newmight201    项目:Blockchain-   
/**
  * 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);
 }

作者:davidpersso    项目:FrameworkBenchmark   
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();
 }


问题


面经


文章

微信
公众号

扫码关注公众号