Completed
Push — master ( 0f46ff...89eb26 )
by yuuki
11s
created

View::from()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
10
 * THE SOFTWARE.
11
 */
12
13
namespace Ytake\LaravelCouchbase\Query;
14
15
use CouchbaseBucket;
16
use CouchbaseViewQuery;
17
use Illuminate\Contracts\Events\Dispatcher;
18
use Ytake\LaravelCouchbase\Events\ViewQuerying;
19
20
/**
21
 * Class View.
22
 *
23
 * @see    http://developer.couchbase.com/documentation/server/4.1/developer-guide/views-intro.html
24
 *
25
 * @author Yuuki Takezawa<[email protected]>
26
 */
27
class View
28
{
29
    /** @var CouchbaseBucket */
30
    protected $bucket;
31
32
    /** @var Dispatcher */
33
    protected $dispatcher;
34
35
    /**
36
     * View constructor.
37
     *
38
     * @param CouchbaseBucket $bucket
39
     * @param Dispatcher|null $dispatcher
40
     */
41 1
    public function __construct(CouchbaseBucket $bucket, Dispatcher $dispatcher = null)
42
    {
43 1
        $this->bucket = $bucket;
44 1
        $this->dispatcher = $dispatcher;
45 1
    }
46
47
    /**
48
     * @param $designDoc
49
     * @param $name
50
     *
51
     * @return \_CouchbaseDefaultViewQuery
52
     */
53 1
    public function from($designDoc, $name)
54
    {
55 1
        return CouchbaseViewQuery::from($designDoc, $name);
56
    }
57
58
    /**
59
     * @param $designDoc
60
     * @param $name
61
     *
62
     * @return \_CouchbaseSpatialViewQuery
63
     */
64
    public function fromSpatial($designDoc, $name)
65
    {
66
        return CouchbaseViewQuery::fromSpatial($designDoc, $name);
67
    }
68
69
    /**
70
     * @param CouchbaseViewQuery $viewQuery
71
     * @param bool               $jsonAsArray
72
     *
73
     * @return mixed
74
     */
75 1
    public function execute(CouchbaseViewQuery $viewQuery, $jsonAsArray = false)
76
    {
77 1
        if (isset($this->dispatcher)) {
78 1
            $this->dispatcher->fire(new ViewQuerying($viewQuery));
79
        }
80
81 1
        return $this->bucket->query($viewQuery, $jsonAsArray);
82
    }
83
}
84