Permalink
Browse files

Move Doctrine\CouchDB namespace into its own library

  • Loading branch information...
1 parent 46f3565 commit 3e3b263524df5358c746436d88c0f338493d343f @beberlei beberlei committed Mar 4, 2012
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
@@ -4,3 +4,4 @@ tests/phpunit.xml
build.properties
build/
dist/
+vendor/
View
@@ -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
@@ -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": []
+}
@@ -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);
- }
-}
Oops, something went wrong.

0 comments on commit 3e3b263

Please sign in to comment.