forked from angyvolin/mongodb-php-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuery.php
74 lines (63 loc) · 1.57 KB
/
Query.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Tequila\MongoDB;
use MongoDB\Driver\ReadConcern;
use Tequila\MongoDB\Exception\UnsupportedException;
class Query implements QueryInterface
{
/**
* @var array
*/
private $filter;
/**
* @var array
*/
private $options;
/**
* @var ReadConcern
*/
private $readConcern;
/**
* @param array $filter
* @param array $options
*/
public function __construct(array $filter, array $options = [])
{
$this->filter = $filter;
$this->options = $options;
}
/**
* @return array
*/
public function getFilter()
{
return $this->filter;
}
/**
* {@inheritdoc}
*/
public function getOptions(Server $server)
{
if (isset($this->options['collation']) && !$server->supportsCollation()) {
throw new UnsupportedException(
'Option "collation" is not supported by the server.'
);
}
if (isset($this->options['readConcern'])) {
if (!$server->supportsReadConcern()) {
throw new UnsupportedException(
'Option "readConcern" is not supported by the server.'
);
}
} elseif ($this->readConcern && $server->supportsReadConcern()) {
$this->options['readConcern'] = $this->readConcern;
}
return $this->options;
}
/**
* @param ReadConcern $readConcern
*/
public function setDefaultReadConcern(ReadConcern $readConcern)
{
$this->readConcern = $readConcern;
}
}