Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move Doctrine\CouchDB namespace into its own library

  • Loading branch information...
commit 3e3b263524df5358c746436d88c0f338493d343f 1 parent 46f3565
@beberlei beberlei authored
Showing with 38 additions and 3,018 deletions.
  1. +1 −0  .gitignore
  2. +6 −2 composer.json
  3. +19 −0 composer.lock
  4. +0 −265 lib/Doctrine/CouchDB/Attachment.php
  5. +0 −498 lib/Doctrine/CouchDB/CouchDBClient.php
  6. +0 −65 lib/Doctrine/CouchDB/CouchDBException.php
  7. +0 −88 lib/Doctrine/CouchDB/HTTP/AbstractHTTPClient.php
  8. +0 −39 lib/Doctrine/CouchDB/HTTP/Client.php
  9. +0 −19 lib/Doctrine/CouchDB/HTTP/ErrorResponse.php
  10. +0 −68 lib/Doctrine/CouchDB/HTTP/HTTPException.php
  11. +0 −82 lib/Doctrine/CouchDB/HTTP/LoggingClient.php
  12. +0 −67 lib/Doctrine/CouchDB/HTTP/Response.php
  13. +0 −260 lib/Doctrine/CouchDB/HTTP/SocketClient.php
  14. +0 −127 lib/Doctrine/CouchDB/HTTP/StreamClient.php
  15. +0 −23 lib/Doctrine/CouchDB/JsonDecodeException.php
  16. +0 −44 lib/Doctrine/CouchDB/Tools/Console/Command/CompactDatabaseCommand.php
  17. +0 −47 lib/Doctrine/CouchDB/Tools/Console/Command/CompactViewCommand.php
  18. +0 −51 lib/Doctrine/CouchDB/Tools/Console/Command/MigrationCommand.php
  19. +0 −62 lib/Doctrine/CouchDB/Tools/Console/Command/ReplicationCancelCommand.php
  20. +0 −67 lib/Doctrine/CouchDB/Tools/Console/Command/ReplicationStartCommand.php
  21. +0 −44 lib/Doctrine/CouchDB/Tools/Console/Command/ViewCleanupCommand.php
  22. +0 −84 lib/Doctrine/CouchDB/Tools/Console/Helper/CouchDBHelper.php
  23. +0 −71 lib/Doctrine/CouchDB/Tools/Migrations/AbstractMigration.php
  24. +0 −71 lib/Doctrine/CouchDB/Utils/BulkUpdater.php
  25. +0 −25 lib/Doctrine/CouchDB/Version.php
  26. +0 −129 lib/Doctrine/CouchDB/View/AbstractQuery.php
  27. +0 −51 lib/Doctrine/CouchDB/View/DesignDocument.php
  28. +0 −60 lib/Doctrine/CouchDB/View/FolderDesignDocument.php
  29. +0 −122 lib/Doctrine/CouchDB/View/LuceneQuery.php
  30. +0 −46 lib/Doctrine/CouchDB/View/LuceneResult.php
  31. +0 −209 lib/Doctrine/CouchDB/View/Query.php
  32. +0 −48 lib/Doctrine/CouchDB/View/Result.php
  33. +0 −167 tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php
  34. +12 −17 tests/TestInit.php
View
1  .gitignore
@@ -4,3 +4,4 @@ tests/phpunit.xml
build.properties
build/
dist/
+vendor/
View
8 composer.json
@@ -11,11 +11,15 @@
],
"require": {
"php": ">=5.3.2",
- "doctrine/common": ">=2.2.0"
+ "doctrine/common": ">=2.2.0,<2.2.9999",
+ "doctrine/couchdb": "*",
+ "symfony/console": ">=2.0,<=2.1"
+ },
+ "suggest": {
+ "symfony/yaml": ">=2.0,<=2.1"
},
"autoload": {
"psr-0": {
- "Doctrine\\CouchDB": "lib/",
"Doctrine\\ODM\\CouchDB": "lib/"
}
}
View
19 composer.lock
@@ -0,0 +1,19 @@
+{
+ "hash": "68401cf287a5dfd9f4349ee807d5809b",
+ "packages": [
+ {
+ "package": "doctrine/common",
+ "version": "2.2.1"
+ },
+ {
+ "package": "doctrine/couchdb",
+ "version": "dev-master",
+ "source-reference": "86c480de76fb2e0eeab976ae462b7e72c9259e5d"
+ },
+ {
+ "package": "symfony/console",
+ "version": "v2.0.10"
+ }
+ ],
+ "aliases": []
+}
View
265 lib/Doctrine/CouchDB/Attachment.php
@@ -1,265 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-
-namespace Doctrine\CouchDB;
-
-use Doctrine\CouchDB\HTTP\Client;
-use Doctrine\CouchDB\HTTP\HTTPException;
-
-/**
- * An attachment is a special embedded document that exists inside CouchDB.
- * It is created inside the "Attachments" object for each attachment that is found.
- *
- * TODO: This is a very inefficient first version implementation that saves both
- * binary and base64 data of everything if possible to ease the API.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.com
- * @since 1.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- */
-class Attachment
-{
- /**
- * Content-Type of the Attachment
- *
- * If this is false on putting a new attachment into the database the
- * generic "application/octet-stream" type will be used.
- *
- * @var string
- */
- private $contentType = false;
-
- /**
- * Base64 Encoded tring of the Data.
- *
- * @var string
- */
- private $data;
-
- /**
- * @var string
- */
- private $binaryData;
-
- /**
- * This attachment only represented as stub, which means the attachment is standalone and not inline.
- *
- * WARNING: Never change this variable from true to false if you don't provide data.
- * CouchDB otherwise quits with an error: {"error":"unknown_error","reason":"function_clause"}
- *
- * @var bool
- */
- private $stub = true;
-
- /**
- * Size of the attachment.
- *
- * @var int
- */
- private $length = 0;
-
- /**
- * Revision Position field of this Attachment.
- *
- * @var int
- */
- private $revpos = 0;
-
- /**
- * @var Client
- */
- private $httpClient;
-
- /**
- * @var string
- */
- private $path;
-
- /**
- * Get the content-type of this attachment.
- *
- * @return string
- */
- public function getContentType()
- {
- return $this->contentType;
- }
-
- /**
- * Get the length of the base64 encoded representation of this attachment.
- *
- * @return int
- */
- public function getLength()
- {
- if (!$this->stub && !is_int($this->length)) {
- $this->length = strlen($this->data);
- }
- return $this->length;
- }
-
- /**
- * Get the raw data of this attachment.
- *
- * @return string
- */
- public function getRawData()
- {
- $this->lazyLoad();
-
- return $this->binaryData;
- }
-
- /**
- * @return string
- */
- public function getBase64EncodedData()
- {
- $this->lazyLoad();
-
- return $this->data;
- }
-
- /**
- * Lazy Load Data from CouchDB if necessary
- *
- * @return void
- */
- private function lazyLoad()
- {
- if ($this->stub) {
- $response = $this->httpClient->request('GET', $this->path, null, true); // raw request
- if ($response->status != 200) {
- throw HTTPException::fromResponse($this->path, $response);
- }
- $this->stub = false;
- $this->binaryData = $response->body;
- $this->data = \base64_encode($this->binaryData);
- }
- }
-
- public function isLoaded()
- {
- return !$this->stub;
- }
-
- /**
- * Number of times an attachment was alreaady saved with the document, indicating in which revision it was added.
- *
- * @return int
- */
- public function getRevPos()
- {
- return $this->revpos;
- }
-
- /**
- * Attachments are special in how they need to be persisted depending on stub or not.
- *
- * TODO: Is this really necessary with all this special logic? Having attahments as special
- * case without special code would be really awesome.
- *
- * @return string
- */
- public function toArray()
- {
- if ($this->stub) {
- $json = array('stub' => true);
- } else {
- $json = array('data' => $this->getBase64EncodedData());
- if ($this->contentType) {
- $json['content_type'] = $this->contentType;
- }
- }
- return $json;
- }
-
- /**
- * @param string $binaryData
- * @param string $base64Data
- * @param string $contentType
- * @param int $length
- * @param int $revPos
- * @param Client $httpClient
- * @param string $path
- */
- final private function __construct($binaryData = null, $base64Data = null, $contentType = false, $length = false, $revPos = false, $httpClient = null, $path = null)
- {
- if ($binaryData || $base64Data) {
- $this->binaryData = $binaryData;
- $this->data = $base64Data;
- $this->stub = false;
- } else {
- $this->stub = true;
- }
- $this->contentType = $contentType;
- $this->length = $length;
- $this->revpos = $revPos;
- $this->httpClient = $httpClient;
- $this->path = $path;
- }
-
- /**
- * Create an Attachment from a string or resource of binary data.
- *
- * WARNING: Changes to the file handle after calling this method will *NOT* be recognized anymore.
- *
- * @param string|resource $data
- * @param string $contentType
- * @return Attachment
- */
- static public function createFromBinaryData($data, $contentType = false)
- {
- if (\is_resource($data)) {
- $data = \stream_get_contents($data);
- }
-
- return new self($data, \base64_encode($data), $contentType);
- }
-
- /**
- * Create an attachment from base64 data.
- *
- * @param string $data
- * @param string $contentType
- * @param int $revpos
- * @return Attachment
- */
- static public function createFromBase64Data($data, $contentType = false, $revpos = false)
- {
- return new self(\base64_decode($data), $data, $contentType, false, $revpos);
- }
-
- /**
- * Create a stub attachment that has lazy loading capabilities.
- *
- * @param string $contentType
- * @param int $length
- * @param int $revPos
- * @param Client $httpClient
- * @param string $path
- * @return Attachment
- */
- static public function createStub($contentType, $length, $revPos, Client $httpClient, $path)
- {
- return new self(null, null, $contentType, $length, $revPos, $httpClient, $path);
- }
-}
View
498 lib/Doctrine/CouchDB/CouchDBClient.php
@@ -1,498 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB;
-
-use Doctrine\CouchDB\HTTP\Client;
-use Doctrine\CouchDB\HTTP\HTTPException;
-use Doctrine\CouchDB\Utils\BulkUpdater;
-use Doctrine\CouchDB\View\DesignDocument;
-
-/**
- * CouchDB client class
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.com
- * @since 1.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @author Lukas Kahwe Smith <smith@pooteeweet.org>
- */
-class CouchDBClient
-{
- /**
- * Name of the CouchDB database
- *
- * @string
- */
- private $databaseName;
-
- /**
- * The underlying HTTP Connection of the used DocumentManager.
- *
- * @var Doctrine\ODM\CouchDB\HTTP\Client
- */
- private $httpClient;
-
- /**
- * CouchDB Version
- *
- * @var string
- */
- private $version = null;
-
- static private $clients = array(
- 'socket' => 'Doctrine\CouchDB\HTTP\SocketClient',
- 'stream' => 'Doctrine\CouchDB\HTTP\StreamClient',
- );
-
- /**
- * Factory method for CouchDBClients
- *
- * @param array $options
- * @return CouchDBClient
- */
- static public function create(array $options)
- {
- if (!isset($options['dbname'])) {
- throw new \InvalidArgumentException("'dbname' is a required option to create a CouchDBClient");
- }
-
- $defaults = array('type' => 'socket', 'host' => 'localhost', 'port' => 5984, 'user' => null, 'password' => null, 'ip' => null, 'logging' => false);
- $options = array_merge($defaults, $options);
-
- if (!isset(self::$clients[$options['type']])) {
- throw new \InvalidArgumentException(sprintf('There is no client implementation registered for %s, valid options are %s',
- $options['type'], array_keys(self::$clients)
- ));
- }
- $connectionClass = self::$clients[$options['type']];
- $connection = new $connectionClass($options['host'], $options['port'], $options['user'], $options['password'], $options['ip']);
- if ($options['logging'] === true) {
- $connection = new HTTP\LoggingClient($connection);
- }
- return new self($connection, $options['dbname']);
- }
-
- /**
- * @param Client $client
- * @param string $databaseName
- */
- public function __construct(Client $client, $databaseName)
- {
- $this->httpClient = $client;
- $this->databaseName = $databaseName;
- }
-
- public function setHttpClient(Client $client)
- {
- $this->httpClient = $client;
- }
-
- /**
- * @return HttpClient
- */
- public function getHttpClient()
- {
- return $this->httpClient;
- }
-
- public function getDatabase()
- {
- return $this->databaseName;
- }
-
- /**
- * Let CouchDB generate an array of UUIDs.
- *
- * @param int $count
- * @return array
- */
- public function getUuids($count = 1)
- {
- $count = (int)$count;
- $response = $this->httpClient->request('GET', '/_uuids?count=' . $count);
-
- if ($response->status != 200) {
- throw new CouchDBException("Could not retrieve UUIDs from CouchDB.");
- }
-
- return $response->body['uuids'];
- }
-
- /**
- * Find a document by ID and return the HTTP response.
- *
- * @param string $id
- * @return Response
- */
- public function findDocument($id)
- {
- $documentPath = '/' . $this->databaseName . '/' . urlencode($id);
- return $this->httpClient->request( 'GET', $documentPath );
- }
-
- /**
- * Find many documents by passing their ids and return the HTTP response.
- *
- * @param array $ids
- * @return array
- */
- public function findDocuments(array $ids, $limit = null, $offset = null)
- {
- $allDocsPath = '/' . $this->databaseName . '/_all_docs?include_docs=true';
- if ($limit) {
- $allDocsPath .= '&limit=' . (int)$limit;
- }
- if ($offset) {
- $allDocsPath .= '&skip=' . (int)$offset;
- }
-
- return $this->httpClient->request('POST', $allDocsPath, json_encode(
- array('keys' => array_values($ids)))
- );
- }
-
- /**
- * Get all documents
- *
- * @param int|null $limit
- * @param string|null $startKey
- * @return array
- */
- public function allDocs($limit = null, $startKey = null)
- {
- $allDocsPath = '/' . $this->databaseName . '/_all_docs?include_docs=true';
- if ($limit) {
- $allDocsPath .= '&limit=' . (int)$limit;
- }
- if ($startKey) {
- $allDocsPath .= '&startkey="' . (string)$startKey.'"';
- }
- return $this->httpClient->request('GET', $allDocsPath);
- }
-
- /**
- * Get the current version of CouchDB.
- *
- * @throws HTTPException
- * @return string
- */
- public function getVersion()
- {
- if ($this->version === null) {
- $response = $this->httpClient->request('GET', '/');
- if ($response->status != 200) {
- throw HTTPException::fromResponse('/', $response);
- }
-
- $this->version = $response->body['version'];
- }
- return $this->version;
- }
-
- /**
- * Get all databases
- *
- * @throws HTTPException
- * @return array
- */
- public function getAllDatabases()
- {
- $response = $this->httpClient->request('GET', '/_all_dbs');
- if ($response->status != 200) {
- throw HTTPException::fromResponse('/_all_dbs', $response);
- }
-
- return $response->body;
- }
-
- /**
- * Create a new database
- *
- * @throws HTTPException
- * @param string $name
- * @return void
- */
- public function createDatabase($name)
- {
- $response = $this->httpClient->request('PUT', '/' . urlencode($name));
-
- if ($response->status != 201) {
- throw HTTPException::fromResponse('/' . urlencode($name), $response);
- }
- }
-
- /**
- * Drop a database
- *
- * @throws HTTPException
- * @param string $name
- * @return void
- */
- public function deleteDatabase($name)
- {
- $response = $this->httpClient->request('DELETE', '/' . urlencode($name));
-
- if ($response->status != 200 && $response->status != 404) {
- throw HTTPException::fromResponse('/' . urlencode($name), $response);
- }
- }
-
- /**
- * Get Information about a database.
- *
- * @param string $name
- * @return array
- */
- public function getDatabaseInfo($name)
- {
- $response = $this->httpClient->request('GET', '/' . $this->databaseName);
-
- if ($response->status != 200) {
- throw HTTPException::fromResponse('/' . urlencode($name), $response);
- }
-
- return $response->body;
- }
-
- /**
- * Get changes.
- *
- * @param array $params
- * @return array
- */
- public function getChanges(array $params = null)
- {
- $path = '/' . $this->databaseName . '/_changes';
- $response = $this->httpClient->request('GET', $path, $params);
-
- if ($response->status != 200) {
- throw HTTPException::fromResponse($path, $response);
- }
-
- return $response->body;
- }
-
- /**
- * Create a bulk updater instance.
- *
- * @return BulkUpdater
- */
- public function createBulkUpdater()
- {
- return new BulkUpdater($this->httpClient, $this->databaseName);
- }
-
- /**
- * Execute a POST request against CouchDB inserting a new document, leaving the server to generate a uuid.
- *
- * @param array $data
- * @return array<id, rev>
- */
- public function postDocument(array $data)
- {
- $path = '/' . $this->databaseName;
- $response = $this->httpClient->request('POST', $path, json_encode($data));
-
- if ($response->status != 201) {
- throw HTTPException::fromResponse($path, $response);
- }
-
- return array($response->body['id'], $response->body['rev']);
- }
-
- /**
- * Execute a PUT request against CouchDB inserting or updating a document.
- *
- * @param array $data
- * @param string $id
- * @param string|null $rev
- * @return array<id, rev>
- */
- public function putDocument($data, $id, $rev = null)
- {
- $data['_id'] = $id;
- if ($rev) {
- $data['_rev'] = $rev;
- }
-
- $path = '/' . $this->databaseName . '/' . urlencode($id);
- $response = $this->httpClient->request('PUT', $path, json_encode($data));
-
- if ($response->status != 201) {
- throw HTTPException::fromResponse($path, $response);
- }
-
- return array($response->body['id'], $response->body['rev']);
- }
-
- /**
- * Delete a document.
- *
- * @param string $id
- * @param string $rev
- * @return void
- */
- public function deleteDocument($id, $rev)
- {
- $path = '/' . $this->databaseName . '/' . $id . '?rev=' . $rev;
- $response = $this->httpClient->request('DELETE', $path);
-
- if ($response->status != 200) {
- throw HTTPException::fromResponse($path, $response);
- }
- }
-
- /**
- * @param string $designDocName
- * @param string $viewName
- * @param DesignDocument $designDoc
- * @return View\Query
- */
- public function createViewQuery($designDocName, $viewName, DesignDocument $designDoc)
- {
- return new View\Query($this->httpClient, $this->databaseName, $designDocName, $viewName, $designDoc);
- }
-
- /**
- * Create or update a design document from the given in memory definition.
- *
- * @param string $designDocName
- * @param DesignDocument $designDoc
- * @return HTTP\Response
- */
- public function createDesignDocument($designDocName, DesignDocument $designDoc)
- {
- $data = $designDoc->getData();
- $data['_id'] = '_design/' . $designDocName;
-
- $response = $this->findDocument($data['_id']);
- if ($response->status == 200) {
- $docData = $response->body;
- $data['_rev'] = $docData['_rev'];
- }
-
- return $this->httpClient->request(
- "PUT",
- sprintf("/%s/_design/%s", $this->databaseName, $designDocName),
- json_encode($data)
- );
- }
-
- /**
- * GET /db/_compact
- *
- * Return array of data about compaction status.
- *
- * @return array
- */
- public function getCompactInfo()
- {
- $path = sprintf('/%s/_compact', $this->databaseName);
- $response = $this->httpClient->request('GET', $path);
- if ($response->status >= 400) {
- throw HTTPException::fromResponse($path, $response);
- }
- return $response->body;
- }
-
- /**
- * POST /db/_compact
- *
- * @return array
- */
- public function compactDatabase()
- {
- $path = sprintf('/%s/_compact', $this->databaseName);
- $response = $this->httpClient->request('POST', $path);
- if ($response->status >= 400) {
- throw HTTPException::fromResponse($path, $response);
- }
- return $response->body;
- }
-
- /**
- * POST /db/_compact/designDoc
- *
- * @param string $designDoc
- * @return array
- */
- public function compactView($designDoc)
- {
- $path = sprintf('/%s/_compact/%s', $this->databaseName, $designDoc);
- $response = $this->httpClient->request('POST', $path);
- if ($response->status >= 400) {
- throw HTTPException::fromResponse($path, $response);
- }
- return $response->body;
- }
-
- /**
- * POST /db/_view_cleanup
- *
- * @return array
- */
- public function viewCleanup()
- {
- $path = sprintf('/%s/_view_cleanup', $this->databaseName);
- $response = $this->httpClient->request('POST', $path);
- if ($response->status >= 400) {
- throw HTTPException::fromResponse($path, $response);
- }
- return $response->body;
- }
-
- /**
- * POST /db/_replicate
- *
- * @param string $source
- * @param string $target
- * @param bool|null $cancel
- * @param bool|null $continuous
- * @param string|null $filter
- * @param array|null $ids
- * @param string|null $proxy
- * @return array
- */
- public function replicate($source, $target, $cancel = null, $continuous = null, $filter = null, array $ids = null, $proxy = null)
- {
- $params = array('target' => $target, 'source' => $source);
- if ($cancel !== null) {
- $params['cancel'] = (bool)$cancel;
- }
- if ($continuous !== null) {
- $params['continuous'] = (bool)$continuous;
- }
- if ($filter !== null) {
- $params['filter'] = $filter;
- }
- if ($ids !== null) {
- $params['doc_ids'] = $ids;
- }
- if ($proxy !== null) {
- $params['proxy'] = $proxy;
- }
- $path = '/_replicate';
- $response = $this->httpClient->request('POST', $path, json_encode($params));
- if ($response->status >= 400) {
- throw HTTPException::fromResponse($path, $response);
- }
- return $response->body;
- }
-}
View
65 lib/Doctrine/CouchDB/CouchDBException.php
@@ -1,65 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB;
-
-/**
- * Base exception class for package Doctrine\ODM\CouchDB
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.com
- * @since 1.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- */
-class CouchDBException extends \Exception
-{
-
- public static function unknownDocumentNamespace($documentNamespaceAlias)
- {
- return new self("Unknown Document namespace alias '$documentNamespaceAlias'.");
- }
-
- public static function unregisteredDesignDocument($designDocumentName)
- {
- return new self("No design document with name '" . $designDocumentName . "' was registered with the DocumentManager.");
- }
-
- public static function invalidAttachment($className, $id, $filename)
- {
- return new self("Trying to save invalid attachment with filename " . $filename . " in document " . $className . " with id " . $id);
- }
-
- public static function detachedDocumentFound($className, $id, $assocName)
- {
- return new self("Found a detached or new document at property " .
- $className . "::" . $assocName. " of document with ID " . $id . ", ".
- "but the assocation is not marked as cascade persist.");
- }
-
- public static function persistRemovedDocument()
- {
- return new self("Trying to persist document that is scheduled for removal.");
- }
-
- public static function luceneNotConfigured()
- {
- return new self("CouchDB Lucene is not configured. You have to configure the handler name to enable support for Lucene Queries.");
- }
-}
-
View
88 lib/Doctrine/CouchDB/HTTP/AbstractHTTPClient.php
@@ -1,88 +0,0 @@
-<?php
-/** HTTP Client interface
- *
- */
-
-namespace Doctrine\CouchDB\HTTP;
-
-/**
- * Basic couch DB connection handling class
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.com
- * @since 1.0
- * @author Kore Nordmann <kore@arbitracker.org>
- */
-abstract class AbstractHTTPClient implements Client
-{
- /**
- * CouchDB connection options
- *
- * @var array
- */
- protected $options = array(
- 'host' => 'localhost',
- 'port' => 5984,
- 'ip' => '127.0.0.1',
- 'timeout' => .01,
- 'keep-alive' => true,
- 'username' => null,
- 'password' => null,
- );
-
- /**
- * Construct a CouchDB connection
- *
- * Construct a CouchDB connection from basic connection parameters for one
- * given database.
- *
- * @param string $host
- * @param int $port
- * @param string $username
- * @param string $password
- * @param string $ip
- * @return void
- */
- public function __construct( $host = 'localhost', $port = 5984, $username = null, $password = null, $ip = null )
- {
- $this->options['host'] = (string) $host;
- $this->options['port'] = (int) $port;
- $this->options['username'] = $username;
- $this->options['password'] = $password;
-
- if ($ip === null) {
- $this->options['ip'] = gethostbyname($this->options['host']);
- } else {
- $this->options['ip'] = $ip;
- }
- }
-
- /**
- * Set option value
- *
- * Set the value for an connection option. Throws an
- * InvalidArgumentException for unknown options.
- *
- * @param string $option
- * @param mixed $value
- * @return void
- */
- public function setOption( $option, $value )
- {
- switch ( $option ) {
- case 'keep-alive':
- $this->options[$option] = (bool) $value;
- break;
-
- case 'http-log':
- case 'password':
- case 'username':
- $this->options[$option] = $value;
- break;
-
- default:
- throw new \InvalidArgumentException( "Unknown option $option." );
- }
- }
-}
-
View
39 lib/Doctrine/CouchDB/HTTP/Client.php
@@ -1,39 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\HTTP;
-
-interface Client
-{
- /**
- * Perform a request to the server and return the result
- *
- * Perform a request to the server and return the result converted into a
- * Response object. If you do not expect a JSON structure, which
- * could be converted in such a response object, set the fourth parameter to
- * true, and you get a response object retuerned, containing the raw body.
- *
- * @param string $method
- * @param string $path
- * @param string $data
- * @param bool $raw
- * @return Response
- */
- function request( $method, $path, $data = null, $raw = false );
-}
View
19 lib/Doctrine/CouchDB/HTTP/ErrorResponse.php
@@ -1,19 +0,0 @@
-<?php
-/** HTTP Client interface
- *
- */
-
-namespace Doctrine\CouchDB\HTTP;
-
-/**
- * HTTP response
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.com
- * @since 1.0
- * @author Kore Nordmann <kore@arbitracker.org>
- */
-class ErrorResponse extends Response
-{
-}
-
View
68 lib/Doctrine/CouchDB/HTTP/HTTPException.php
@@ -1,68 +0,0 @@
-<?php
-
-namespace Doctrine\CouchDB\HTTP;
-
-/**
- * Base exception class for package Doctrine\ODM\CouchDB\HTTP
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.com
- * @since 1.0
- * @author Kore Nordmann <kore@arbitracker.org>
- */
-class HTTPException extends \Doctrine\CouchDB\CouchDBException
-{
- /**
- * @param string $ip
- * @param integer $port
- * @param string $errstr
- * @param integer $errno
- * @return \Doctrine\CouchDB\HTTP\HTTPException
- */
- public static function connectionFailure( $ip, $port, $errstr, $errno )
- {
- return new self( sprintf(
- "Could not connect to server at %s:%d: '%d: %s'",
- $ip,
- $port,
- $errno,
- $errstr
- ), $errno );
- }
-
- /**
- * @param string $ip
- * @param integer $port
- * @param string $errstr
- * @param integer $errno
- * @return \Doctrine\CouchDB\HTTP\HTTPException
- */
- public static function readFailure( $ip, $port, $errstr, $errno )
- {
- return new static( sprintf(
- "Could read from server at %s:%d: '%d: %s'",
- $ip,
- $port,
- $errno,
- $errstr
- ), $errno );
- }
-
- /**
- * @param string $path
- * @param Response $response
- * @return \Doctrine\CouchDB\HTTP\HTTPException
- */
- public static function fromResponse( $path, Response $response )
- {
- if (!isset($response->body['error'])) {
- $response->body['error'] = '';
- }
-
- return new self(
- "HTTP Error with status " . $response->status . " occoured while "
- . "requesting " . $path . ". Error: " . $response->body['error']
- . " " . $response->body['reason'],
- $response->status );
- }
-}
View
82 lib/Doctrine/CouchDB/HTTP/LoggingClient.php
@@ -1,82 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\HTTP;
-
-class LoggingClient implements Client
-{
- /**
- * @var Client
- */
- private $client;
-
- /**
- * Array of requests made to CouchDB with this client.
- *
- * Contains the following keys:
- * - duration - Microseconds it took to execute and process the request
- * - method (GET, POST, ..)
- * - path - The requested url path on the server including parameters
- * - request - The request body if its size is smaller than 10000 chars.
- * - request_size - The size of the request body
- * - response_status - The response HTTP status
- * - response - The body of the response.
- * - response_headers
- *
- * @var array
- */
- public $requests = array();
-
- /**
- * @var float
- */
- public $totalDuration = 0;
-
- /**
- * Construct new logging client wrapping the real client.
- *
- * @param Client $client
- */
- public function __construct(Client $client)
- {
- $this->client = $client;
- }
-
- public function request($method, $path, $data = null, $raw = false)
- {
- $start = microtime(true);
-
- $response = $this->client->request($method, $path, $data, $raw);
-
- $duration = microtime(true) - $start;
- $this->requests[] = array(
- 'duration' => $duration,
- 'method' => $method,
- 'path' => rawurldecode($path),
- 'request' => $data,
- 'request_size' => strlen($data),
- 'response_status' => $response->status,
- 'response' => $response->body,
- 'response_headers' => $response->headers,
- );
- $this->totalDuration += $duration;
-
- return $response;
- }
-}
View
67 lib/Doctrine/CouchDB/HTTP/Response.php
@@ -1,67 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\HTTP;
-
-/**
- * HTTP response
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.com
- * @since 1.0
- * @author Kore Nordmann <kore@arbitracker.org>
- */
-class Response
-{
- /**
- * HTTP repsonse status
- *
- * @var int
- */
- public $status;
-
- /**
- * HTTP repsonse headers
- *
- * @var array
- */
- public $headers;
-
- /**
- * Decoded JSON response body
- *
- * @var array
- */
- public $body;
-
- /**
- * Construct response
- *
- * @param array $headers
- * @param string $body
- * @return void
- */
- public function __construct( $status, array $headers, $body, $raw = false )
- {
- $this->status = (int) $status;
- $this->headers = $headers;
- $this->body = $raw ? $body : json_decode( $body, true );
- }
-}
-
View
260 lib/Doctrine/CouchDB/HTTP/SocketClient.php
@@ -1,260 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\HTTP;
-
-/**
- * This class uses a custom HTTP client, which may have more bugs then the
- * default PHP HTTP clients, but supports keep alive connections without any
- * extension dependencies.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.com
- * @since 1.0
- * @author Kore Nordmann <kore@arbitracker.org>
- */
-class SocketClient extends AbstractHTTPClient
-{
- /**
- * Connection pointer for connections, once keep alive is working on the
- * CouchDb side.
- *
- * @var resource
- */
- protected $connection;
-
- /**
- * Check for server connection
- *
- * Checks if the connection already has been established, or tries to
- * establish the connection, if not done yet.
- *
- * @return void
- */
- protected function checkConnection()
- {
- // If the connection could not be established, fsockopen sadly does not
- // only return false (as documented), but also always issues a warning.
- if ( ( $this->connection === null ) &&
- ( ( $this->connection = @fsockopen( $this->options['ip'], $this->options['port'], $errno, $errstr ) ) === false ) )
- {
- // This is a bit hackisch...
- $this->connection = null;
- throw HTTPException::connectionFailure(
- $this->options['ip'],
- $this->options['port'],
- $errstr,
- $errno
- );
- }
- }
-
- /**
- * Build a HTTP 1.1 request
- *
- * Build the HTTP 1.1 request headers from the gicven input.
- *
- * @param string $method
- * @param string $path
- * @param string $data
- * @return string
- */
- protected function buildRequest( $method, $path, $data )
- {
- // Create basic request headers
- $request = "$method $path HTTP/1.1\r\nHost: {$this->options['host']}\r\n";
-
- // Add basic auth if set
- if ( $this->options['username'] )
- {
- $request .= sprintf( "Authorization: Basic %s\r\n",
- base64_encode( $this->options['username'] . ':' . $this->options['password'] )
- );
- }
-
- // Set keep-alive header, which helps to keep to connection
- // initilization costs low, especially when the database server is not
- // available in the locale net.
- $request .= "Connection: " . ( $this->options['keep-alive'] ? 'Keep-Alive' : 'Close' ) . "\r\n";
-
- // Also add headers and request body if data should be sent to the
- // server. Otherwise just add the closing mark for the header section
- // of the request.
- if ( $data !== null )
- {
- $request .= "Content-type: application/json\r\n";
- $request .= "Content-Length: " . strlen( $data ) . "\r\n\r\n";
- $request .= "$data";
- }
- else
- {
- $request .= "\r\n";
- }
-
- return $request;
- }
-
- /**
- * Perform a request to the server and return the result
- *
- * Perform a request to the server and return the result converted into a
- * Response object. If you do not expect a JSON structure, which
- * could be converted in such a response object, set the forth parameter to
- * true, and you get a response object retuerned, containing the raw body.
- *
- * @param string $method
- * @param string $path
- * @param string $data
- * @param bool $raw
- * @return Response
- */
- public function request( $method, $path, $data = null, $raw = false )
- {
- // Try establishing the connection to the server
- $this->checkConnection();
-
- // Send the build request to the server
- if ( fwrite( $this->connection, $request = $this->buildRequest( $method, $path, $data ) ) === false )
- {
- // Reestablish which seems to have been aborted
- //
- // The recursion in this method might be problematic if the
- // connection establishing mechanism does not correctly throw an
- // exception on failure.
- $this->connection = null;
- return $this->request( $method, $path, $data, $raw );
- }
-
- // Read server response headers
- $rawHeaders = '';
- $headers = array(
- 'connection' => ( $this->options['keep-alive'] ? 'Keep-Alive' : 'Close' ),
- );
-
- // Remove leading newlines, should not accur at all, actually.
- while ( ( ( $line = fgets( $this->connection ) ) !== false ) &&
- ( ( $lineContent = rtrim( $line ) ) === '' ) );
-
- // Throw exception, if connection has been aborted by the server, and
- // leave handling to the user for now.
- if ( $line === false )
- {
- // Reestablish which seems to have been aborted
- //
- // The recursion in this method might be problematic if the
- // connection establishing mechanism does not correctly throw an
- // exception on failure.
- //
- // An aborted connection seems to happen here on long running
- // requests, which cause a connection timeout at server side.
- $this->connection = null;
- return $this->request( $method, $path, $data, $raw );
- }
-
- do {
- // Also store raw headers for later logging
- $rawHeaders .= $lineContent . "\n";
-
- // Extract header values
- if ( preg_match( '(^HTTP/(?P<version>\d+\.\d+)\s+(?P<status>\d+))S', $lineContent, $match ) )
- {
- $headers['version'] = $match['version'];
- $headers['status'] = (int) $match['status'];
- }
- else
- {
- list( $key, $value ) = explode( ':', $lineContent, 2 );
- $headers[strtolower( $key )] = ltrim( $value );
- }
- } while ( ( ( $line = fgets( $this->connection ) ) !== false ) &&
- ( ( $lineContent = rtrim( $line ) ) !== '' ) );
-
- // Read response body
- $body = '';
- if ( !isset( $headers['transfer-encoding'] ) ||
- ( $headers['transfer-encoding'] !== 'chunked' ) )
- {
- // HTTP 1.1 supports chunked transfer encoding, if the according
- // header is not set, just read the specified amount of bytes.
- $bytesToRead = (int) ( isset( $headers['content-length'] ) ? $headers['content-length'] : 0 );
-
- // Read body only as specified by chunk sizes, everything else
- // are just footnotes, which are not relevant for us.
- while ( $bytesToRead > 0 )
- {
- $body .= $read = fgets( $this->connection, $bytesToRead + 1 );
- $bytesToRead -= strlen( $read );
- }
- }
- else
- {
- // When transfer-encoding=chunked has been specified in the
- // response headers, read all chunks and sum them up to the body,
- // until the server has finished. Ignore all additional HTTP
- // options after that.
- do {
- $line = rtrim( fgets( $this->connection ) );
-
- // Get bytes to read, with option appending comment
- if ( preg_match( '(^([0-9a-f]+)(?:;.*)?$)', $line, $match ) )
- {
- $bytesToRead = hexdec( $match[1] );
-
- // Read body only as specified by chunk sizes, everything else
- // are just footnotes, which are not relevant for us.
- $bytesLeft = $bytesToRead;
- while ( $bytesLeft > 0 )
- {
- $body .= $read = fread( $this->connection, $bytesLeft + 2 );
- $bytesLeft -= strlen( $read );
- }
- }
- } while ( $bytesToRead > 0 );
-
- // Chop off \r\n from the end.
- $body = substr( $body, 0, -2 );
- }
-
- // Reset the connection if the server asks for it.
- if ( $headers['connection'] !== 'Keep-Alive' )
- {
- fclose( $this->connection );
- $this->connection = null;
- }
-
- // Handle some response state as special cases
- switch ( $headers['status'] )
- {
- case 301:
- case 302:
- case 303:
- case 307:
- $path = parse_url( $headers['location'], PHP_URL_PATH );
- return $this->request( $method, $path, $data, $raw );
- }
-
- // Create repsonse object from couch db response
- if ( $headers['status'] >= 400 )
- {
- return new ErrorResponse( $headers['status'], $headers, $body );
- }
- return new Response( $headers['status'], $headers, $body, $raw );
- }
-}
-
View
127 lib/Doctrine/CouchDB/HTTP/StreamClient.php
@@ -1,127 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\HTTP;
-
-/**
- * Connection handler using PHPs stream wrappers.
- *
- * Requires PHP being compiled with --with-curlwrappers for now, since the PHPs
- * own HTTP implementation is somehow b0rked.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.com
- * @since 1.0
- * @author Kore Nordmann <kore@arbitracker.org>
- */
-class StreamClient extends AbstractHTTPClient
-{
- /**
- * Perform a request to the server and return the result
- *
- * Perform a request to the server and return the result converted into a
- * Response object. If you do not expect a JSON structure, which
- * could be converted in such a response object, set the forth parameter to
- * true, and you get a response object retuerned, containing the raw body.
- *
- * @param string $method
- * @param string $path
- * @param string $data
- * @return Response
- */
- public function request( $method, $path, $data = null, $raw = false )
- {
- $basicAuth = '';
- if ( $this->options['username'] ) {
- $basicAuth .= "{$this->options['username']}:{$this->options['password']}@";
- }
-
- // TODO SSL support?
- $httpFilePointer = @fopen(
- 'http://' . $basicAuth . $this->options['host'] . ':' . $this->options['port'] . $path,
- 'r',
- false,
- stream_context_create(
- array(
- 'http' => array(
- 'method' => $method,
- 'content' => $data,
- 'ignore_errors' => true,
- 'max_redirects' => 0,
- 'user_agent' => 'Doctrine CouchDB ODM $Revision$',
- 'timeout' => $this->options['timeout'],
- 'header' => 'Content-type: application/json',
- ),
- )
- )
- );
-
- // Check if connection has been established successfully
- if ( $httpFilePointer === false ) {
- $error = error_get_last();
- throw HTTPException::connectionFailure(
- $this->options['ip'],
- $this->options['port'],
- $error['message'],
- 0
- );
- }
-
- // Read request body
- $body = '';
- while ( !feof( $httpFilePointer ) ) {
- $body .= fgets( $httpFilePointer );
- }
-
- $metaData = stream_get_meta_data( $httpFilePointer );
- // The structure of this array differs depending on PHP compiled with
- // --enable-curlwrappers or not. Both cases are normally required.
- $rawHeaders = isset( $metaData['wrapper_data']['headers'] )
- ? $metaData['wrapper_data']['headers'] : $metaData['wrapper_data'];
-
- $headers = array();
- foreach ( $rawHeaders as $lineContent ) {
- // Extract header values
- if ( preg_match( '(^HTTP/(?P<version>\d+\.\d+)\s+(?P<status>\d+))S', $lineContent, $match ) ) {
- $headers['version'] = $match['version'];
- $headers['status'] = (int) $match['status'];
- } else {
- list( $key, $value ) = explode( ':', $lineContent, 2 );
- $headers[strtolower( $key )] = ltrim( $value );
- }
- }
-
- if ( empty($headers['status']) ) {
- throw HTTPException::readFailure(
- $this->options['ip'],
- $this->options['port'],
- 'Received an empty response or not status code',
- 0
- );
- }
-
- // Create repsonse object from couch db response
- if ( $headers['status'] >= 400 )
- {
- return new ErrorResponse( $headers['status'], $headers, $body );
- }
- return new Response( $headers['status'], $headers, $body, $raw );
- }
-}
-
View
23 lib/Doctrine/CouchDB/JsonDecodeException.php
@@ -1,23 +0,0 @@
-<?php
-
-namespace Doctrine\CouchDB;
-
-class JsonDecodeException extends \Exception
-{
- static public function fromLastJsonError()
- {
- $lastError = \json_last_error();
- switch ($lastError) {
- case \JSON_ERROR_DEPTH:
- return new self("The maximum stack depth has been exceeded");
- case \JSON_ERROR_STATE_MISMATCH:
- return new self("Invalid or malformed JSON");
- case \JSON_ERROR_CTRL_CHAR:
- return new self("Control character error, possibly incorrectly encoded");
- case \JSON_ERROR_SYNTAX:
- return new self("Syntax error");
- default:
- return new self("An unknownerror occured with code: " . $lastError);
- }
- }
-}
View
44 lib/Doctrine/CouchDB/Tools/Console/Command/CompactDatabaseCommand.php
@@ -1,44 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\Tools\Console\Command;
-
-use Symfony\Component\Console\Input\InputArgument,
- Symfony\Component\Console\Input\InputOption,
- Symfony\Component\Console\Input\InputInterface,
- Symfony\Component\Console\Output\OutputInterface,
- Symfony\Component\Console\Command\Command;
-
-class CompactDatabaseCommand extends Command
-{
- protected function configure()
- {
- $this->setName('couchdb:maintenance:compact-database')
- ->setDescription('Compact the database');
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $couchClient = $this->getHelper('couchdb')->getCouchDBClient();
- /* @var $couchClient \Doctrine\CouchDB\CouchDBClient */
-
- $data = $couchClient->compactDatabase();
- $output->writeln("Database compact started.");
- }
-}
View
47 lib/Doctrine/CouchDB/Tools/Console/Command/CompactViewCommand.php
@@ -1,47 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\Tools\Console\Command;
-
-use Symfony\Component\Console\Input\InputArgument,
- Symfony\Component\Console\Input\InputOption,
- Symfony\Component\Console\Input\InputInterface,
- Symfony\Component\Console\Output\OutputInterface,
- Symfony\Component\Console\Command\Command;
-
-class CompactViewCommand extends Command
-{
- protected function configure()
- {
- $this->setName('couchdb:maintenance:compact-view')
- ->setDescription('Compat the given view')
- ->setDefinition(array(
- new InputArgument('designdoc', InputArgument::REQUIRED, 'Design document name', null),
- ));
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $couchClient = $this->getHelper('couchdb')->getCouchDBClient();
- /* @var $couchClient \Doctrine\CouchDB\CouchDBClient */
-
- $data = $couchClient->compactView($input->getArgument('designdoc'));
- $output->writeln("View compact started.");
- }
-}
View
51 lib/Doctrine/CouchDB/Tools/Console/Command/MigrationCommand.php
@@ -1,51 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\Tools\Console\Command;
-
-
-use Symfony\Component\Console\Input\InputArgument,
- Symfony\Component\Console\Input\InputOption,
- Symfony\Component\Console\Input\InputInterface,
- Symfony\Component\Console\Output\OutputInterface,
- Symfony\Component\Console\Command\Command;
-
-class MigrationCommand extends Command
-{
- protected function configure()
- {
- $this->setName('couchdb:migrate')
- ->setDescription('Execute a migration in CouchDB.')
- ->setDefinition(array(
- new InputArgument('class', InputArgument::REQUIRED, 'Migration class name', null),
- ));
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $className = $input->getArgument('class');
- if (!class_exists($className) || !in_array('Doctrine\CouchDB\Tools\Migrations\AbstractMigration', class_parents($className))) {
- throw new \InvalidArgumentException("class passed to command has to extend 'Doctrine\CouchDB\Tools\Migrations\AbstractMigration'");
- }
- $migration = new $className($this->getHelper('couchdb')->getCouchDBClient());
- $migration->execute();
-
- $output->writeln("Migration was successfully executed!");
- }
-}
View
62 lib/Doctrine/CouchDB/Tools/Console/Command/ReplicationCancelCommand.php
@@ -1,62 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\Tools\Console\Command;
-
-use Symfony\Component\Console\Input\InputArgument,
- Symfony\Component\Console\Input\InputOption,
- Symfony\Component\Console\Input\InputInterface,
- Symfony\Component\Console\Output\OutputInterface,
- Symfony\Component\Console\Command\Command;
-
-class ReplicationCancelCommand extends Command
-{
- protected function configure()
- {
- $this->setName('couchdb:replication:cancel')
- ->setDescription('Cancel replication from a given source to target.')
- ->setDefinition(array(
- new InputArgument('source', InputArgument::REQUIRED, 'Source Database', null),
- new InputArgument('target', InputArgument::REQUIRED, 'Target Database', null),
- new InputOption('continuous', 'c', InputOption::VALUE_NONE, 'Enable continuous replication', null),
- ))->setHelp(<<<EOT
-With this command you cancel the replication between a given source and target.
-All the options to POST /db/_replicate are available. Example usage:
-
- doctrine-couchdb couchdb:replication:cancel example-source-db example-target-db
- doctrine-couchdb couchdb:replication:cancel example-source-db http://example.com:5984/example-target-db
-
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $couchClient = $this->getHelper('couchdb')->getCouchDBClient();
- /* @var $couchClient \Doctrine\CouchDB\CouchDBClient */
- $data = $couchClient->replicate(
- $input->getArgument('source'),
- $input->getArgument('target'),
- true,
- $input->getOption('continuous') ? true : false
- );
-
- $output->writeln("Replication canceled.");
- }
-}
View
67 lib/Doctrine/CouchDB/Tools/Console/Command/ReplicationStartCommand.php
@@ -1,67 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\Tools\Console\Command;
-
-use Symfony\Component\Console\Input\InputArgument,
- Symfony\Component\Console\Input\InputOption,
- Symfony\Component\Console\Input\InputInterface,
- Symfony\Component\Console\Output\OutputInterface,
- Symfony\Component\Console\Command\Command;
-
-class ReplicationStartCommand extends Command
-{
- protected function configure()
- {
- $this->setName('couchdb:replication:start')
- ->setDescription('Start replication from a given source to target.')
- ->setDefinition(array(
- new InputArgument('source', InputArgument::REQUIRED, 'Source Database', null),
- new InputArgument('target', InputArgument::REQUIRED, 'Target Database', null),
- new InputOption('continuous', 'c', InputOption::VALUE_NONE, 'Enable continuous replication', null),
- new InputOption('proxy', 'p', InputOption::VALUE_REQUIRED, 'Proxy server to replicate through', null),
- new InputOption('id', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Ids for named replication', null),
- new InputOption('filter', 'f', InputOption::VALUE_REQUIRED, 'Replication-Filter Document', null),
- ))->setHelp(<<<EOT
-With this command you start the replication between a given source and target.
-All the options to POST /db/_replicate are available. Example usage:
-
- doctrine-couchdb couchdb:replication:start example-source-db example-target-db
- doctrine-couchdb couchdb:replication:start example-source-db http://example.com:5984/example-target-db
-
-EOT
- );
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $couchClient = $this->getHelper('couchdb')->getCouchDBClient();
- /* @var $couchClient \Doctrine\CouchDB\CouchDBClient */
- $data = $couchClient->replicate(
- $input->getArgument('source'),
- $input->getArgument('target'), null,
- $input->getOption('continuous') ? true : false,
- $input->getOption('filter') ?: null,
- $input->getOption('id') ?: null,
- $input->getOption('proxy') ?: null
- );
-
- $output->writeln("Replication started.");
- }
-}
View
44 lib/Doctrine/CouchDB/Tools/Console/Command/ViewCleanupCommand.php
@@ -1,44 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\Tools\Console\Command;
-
-use Symfony\Component\Console\Input\InputArgument,
- Symfony\Component\Console\Input\InputOption,
- Symfony\Component\Console\Input\InputInterface,
- Symfony\Component\Console\Output\OutputInterface,
- Symfony\Component\Console\Command\Command;
-
-class ViewCleanupCommand extends Command
-{
- protected function configure()
- {
- $this->setName('couchdb:maintenance:view-cleanup')
- ->setDescription('Cleanup deleted views');
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $couchClient = $this->getHelper('couchdb')->getCouchDBClient();
- /* @var $couchClient \Doctrine\CouchDB\CouchDBClient */
-
- $data = $couchClient->viewCleanup();
- $output->writeln("View cleanup started.");
- }
-}
View
84 lib/Doctrine/CouchDB/Tools/Console/Helper/CouchDBHelper.php
@@ -1,84 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-
-namespace Doctrine\CouchDB\Tools\Console\Helper;
-
-use Symfony\Component\Console\Helper\Helper;
-use Doctrine\CouchDB\CouchDBClient;
-use Doctrine\ODM\CouchDB\DocumentManager;
-
-/**
- * Doctrine CLI Connection Helper.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- */
-class CouchDBHelper extends Helper
-{
- protected $couchDBClient;
-
- /**
- * @var DocumentManager
- */
- protected $dm;
-
- /**
- * Constructor
- *
- * @param CouchDBClient $couchDBClient
- * @param DocumentManager $dm
- */
- public function __construct(CouchDBClient $couchDBClient = null, DocumentManager $dm = null)
- {
- if (!$couchDBClient && $dm) {
- $couchDBClient = $dm->getCouchDBClient();
- }
-
- $this->couchDBClient = $couchDBClient;
- $this->dm = $dm;
- }
-
- /**
- * Retrieves Doctrine ODM CouchDB Manager
- *
- * @return \Doctrine\ODM\CouchDB\DocumentManager
- */
- public function getDocumentManager()
- {
- return $this->dm;
- }
-
- /**
- * @return CouchDBClient
- */
- public function getCouchDBClient()
- {
- return $this->couchDBClient;
- }
-
- /**
- * @see Helper
- */
- public function getName()
- {
- return 'couchdb';
- }
-}
View
71 lib/Doctrine/CouchDB/Tools/Migrations/AbstractMigration.php
@@ -1,71 +0,0 @@
-<?php
-/*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
-namespace Doctrine\CouchDB\Tools\Migrations;
-
-use Doctrine\CouchDB\CouchDBClient;
-
-/**
- * Migration base class
- */
-abstract class AbstractMigration
-{
- private $client;
-
- public function __construct(CouchDBClient $client)
- {
- $this->client = $client;
- }
-
- /**
- * Execute migration by iterating over all documents in batches of 100.
- *
- * @return void
- */
- public function execute()
- {
- $response = $this->client->allDocs(100);
- $lastKey = null;
-
- do {
- if ($response->status !== 200) {
- throw new \RuntimeException("Error while migrating at offset " . $offset);
- }
-
- $bulkUpdater = $this->client->createBulkUpdater();
- foreach ($response->body['rows'] AS $row) {
- $doc = $this->migrate($row['doc']);
- if ($doc) {
- $bulkUpdater->updateDocument($doc);
- }
- $lastKey = $row['key'];
- }
-
- $bulkUpdater->execute();