/** * Test version string * * @assert equals * * @author Simon Thulbourn <*****@*****.**> */ public function testVersionString() { $version = \phpcouch\VERSION_NUMBER; // only append a status (like "RC3") if it is set if (\phpcouch\VERSION_STATUS !== null) { $version .= '-' . \phpcouch\VERSION_STATUS; } $this->assertEquals(Phpcouch::getVersionString(), 'PHPCouch/' . $version); }
/** * Adapter constructor. * * @param array An array of initialization options for this driver implementation. * * @author David Zülke <*****@*****.**> * @since 1.0.0 */ public function __construct(array $options = array()) { $this->options = array('http' => array('header' => array('Accept: */*, application/json'), 'ignore_errors' => true, 'user_agent' => \phpcouch\Phpcouch::getVersionString())); // can't do array_merge_recursive foreach ($options as $wrapper => $opts) { if (isset($this->options[$wrapper])) { $this->options[$wrapper] = array_merge($this->options[$wrapper], $opts); } else { $this->options[$wrapper] = $opts; } } }
/** * Adapter constructor. * * @param array An array of initialization options for this driver implementation. * * @author Simon Thulbourn <*****@*****.**> * @since 1.0.0 */ public function __construct(array $options = array()) { $this->headers = array('Accept' => '*/*, application/json', 'User-Agent' => \phpcouch\Phpcouch::getVersionString()); }
public function setUp() { Phpcouch::bootstrap(); }
<?php use phpcouch\Phpcouch; use phpcouch\Exception; use phpcouch\connection; use phpcouch\adapter; error_reporting(E_ALL | E_STRICT); set_include_path(get_include_path() . ':' . '/Users/dzuelke/Downloads/ZendFramework-1.0.2/library'); require '../lib/phpcouch/Phpcouch.php'; Phpcouch::bootstrap(); PhpCouch::registerConnection('default', $con = new connection\Connection(null, new adapter\PhpAdapter())); var_dump($con->listDatabases()); var_dump('A UUID (from /_uuids): ' . $con->retrieveUuids()->uuids[0]); var_dump('Database dir (from /_config): ' . $con->retrieveConfig()->couchdb->database_dir); var_dump('CouchDB Version (from /): ' . $con->retrieveInfo()->version); var_dump('Mean request time (from /_stats): ' . $con->retrieveStats()->couchdb->request_time->mean); var_dump($db = $con->retrieveDatabase('test_suite_db/with_slashes')); // foreach($db->callView('test', 'testing', array('reduce' => false, 'stale' => true, /*'keys' => array('foo', 'bar')*/)) as $row) { // var_dump($row); // } foreach ($db->listDocuments(array('include_docs' => true)) as $row) { var_dump($row->getDocument()->_id); } var_dump($db->retrieveDocument('_design/test')); // var_dump($db->retrieveDocument('_design/testx')); $new = $db->newDocument(); $new->foo = 'bar'; try { $new->save(); var_dump($new); } catch (\phpcouch\http\HttpClientErrorException $e) {
/** * Initialize this Database. * * @param AgaviDatabaseManager The database manager of this instance. * @param array An assoc array of initialization params. * * @author David Zülke <*****@*****.**> */ public function initialize(AgaviDatabaseManager $databaseManager, array $parameters = array()) { parent::initialize($databaseManager, $parameters); if (!class_exists('phpcouch\\Phpcouch')) { // assume it's on the include path include 'phpcouch/Phpcouch.php'; } // call bootstrap regardless. it won't re-initialize if it's already been done \phpcouch\Phpcouch::bootstrap(); if (!$this->hasParameter('database') && ($database = trim(parse_url($this->getParameter('uri'), PHP_URL_PATH), '/'))) { $this->setParameter('database', $database); } }
/** * Set the connection to be used with this record. * * @param \phpcouch\connection\Connection The connection to associate. * * @throws ? * * @author David Zülke <*****@*****.**> * @since 1.0.0 */ public function setConnection(\phpcouch\connection\Connection $connection = null) { if ($connection === null) { $connection = \phpcouch\Phpcouch::getConnection(); } $this->connection = $connection; }