Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonvn committed Apr 30, 2018
2 parents 7cd29b7 + 3f4b3eb commit 0654638
Show file tree
Hide file tree
Showing 45 changed files with 13,071 additions and 877 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
language: php

dist: trusty
sudo: required
services:
- couchdb
- docker

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1

before_script:
- docker pull robsonvn/couchdb-ssl
- docker run -d -p 5984:5984 -p 6984:6984 robsonvn/couchdb-ssl
- sleep 10
- curl -X PUT localhost:5984/doctrine_test_database
- composer install

Expand Down
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Doctrine CouchDB Client
# Doctrine CouchDB v2.x Client

[![Build Status](https://travis-ci.org/doctrine/couchdb-client.png?branch=master)](https://travis-ci.org/doctrine/couchdb-client)
[![StyleCI](https://styleci.io/repos/90809440/shield?style=flat)](https://styleci.io/repos/90809440)

Simple API that wraps around CouchDBs HTTP API.

Simple API that wraps around CouchDBs v2.x HTTP API.

## Features

Expand All @@ -18,6 +20,7 @@ Simple API that wraps around CouchDBs HTTP API.
* Compaction Info and Triggering APIs
* Replication API
* Symfony Console Commands
* Find Documents using Mango Query

## Installation

Expand Down Expand Up @@ -62,6 +65,27 @@ $client->deleteDocument($id, $rev);

// Delete a database.
$client->deleteDatabase($client->getDatabase());

//Search documents using Mango Query CouchDB v2.x

$selector = ['_id'=>['$gt'=>null]];
$options = ['limit'=>1,'skip'=>1,'use_index'=>['_design/doc','index'],'sort'=>[['_id'=>'desc']]];
$query = new \Doctrine\CouchDB\Mango\MangoQuery($selector,$options);
$docs = $client->find($query);

$query = new \Doctrine\CouchDB\Mango\MangoQuery();
$query->select(['_id', 'name'])->where(['$and'=> [
[
'name'=> [
'$eq'=> 'Under the Dome',
],
'genres'=> [
'$in'=> ['Drama','Comedy'],
],
],
])->sort([['_id'=>'desc']])->limit(1)->skip(1)->use_index(['_design/doc','index']);
$docs = $client->find($query);

```

### Views
Expand Down Expand Up @@ -131,4 +155,4 @@ foreach ($result as $row) {
}
// Author Alice has written 1 articles
// Author Bob has written 2 articles
```
```
36 changes: 21 additions & 15 deletions lib/Doctrine/CouchDB/Attachment.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Doctrine\CouchDB;

use Doctrine\CouchDB\HTTP\Client;
Expand All @@ -14,14 +13,16 @@
* binary and base64 data of everything if possible to ease the API.
*
* @license http://www.opensource.org/licenses/mit-license.php MIT
*
* @link www.doctrine-project.com
* @since 1.0
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class Attachment
{
/**
* Content-Type of the 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.
Expand Down Expand Up @@ -96,6 +97,7 @@ public function getLength()
if (!$this->stub && !is_int($this->length)) {
$this->length = strlen($this->data);
}

return $this->length;
}

Expand All @@ -122,7 +124,7 @@ public function getBase64EncodedData()
}

/**
* Lazy Load Data from CouchDB if necessary
* Lazy Load Data from CouchDB if necessary.
*
* @return void
*/
Expand Down Expand Up @@ -165,22 +167,23 @@ public function getRevPos()
public function toArray()
{
if ($this->stub) {
$json = array('stub' => true);
$json = ['stub' => true];
} else {
$json = array('data' => $this->getBase64EncodedData());
$json = ['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 int $length
* @param int $revPos
* @param Client $httpClient
* @param string $path
*/
Expand All @@ -189,7 +192,7 @@ final private function __construct($binaryData = null, $base64Data = null, $cont
if ($binaryData || $base64Data) {
$this->binaryData = $binaryData;
$this->data = $base64Data;
$this->stub = false;
$this->stub = false;
} else {
$this->stub = true;
}
Expand All @@ -206,10 +209,11 @@ final private function __construct($binaryData = null, $base64Data = null, $cont
* WARNING: Changes to the file handle after calling this method will *NOT* be recognized anymore.
*
* @param string|resource $data
* @param string $contentType
* @param string $contentType
*
* @return Attachment
*/
static public function createFromBinaryData($data, $contentType = false)
public static function createFromBinaryData($data, $contentType = false)
{
if (\is_resource($data)) {
$data = \stream_get_contents($data);
Expand All @@ -223,10 +227,11 @@ static public function createFromBinaryData($data, $contentType = false)
*
* @param string $data
* @param string $contentType
* @param int $revpos
* @param int $revpos
*
* @return Attachment
*/
static public function createFromBase64Data($data, $contentType = false, $revpos = false)
public static function createFromBase64Data($data, $contentType = false, $revpos = false)
{
return new self(\base64_decode($data), $data, $contentType, false, $revpos);
}
Expand All @@ -235,13 +240,14 @@ static public function createFromBase64Data($data, $contentType = false, $revpos
* Create a stub attachment that has lazy loading capabilities.
*
* @param string $contentType
* @param int $length
* @param int $revPos
* @param int $length
* @param int $revPos
* @param Client $httpClient
* @param string $path
*
* @return Attachment
*/
static public function createStub($contentType, $length, $revPos, Client $httpClient, $path)
public static function createStub($contentType, $length, $revPos, Client $httpClient, $path)
{
return new self(null, null, $contentType, $length, $revPos, $httpClient, $path);
}
Expand Down
Loading

0 comments on commit 0654638

Please sign in to comment.