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
|
|
|
|