1 | <?php declare(strict_types = 1); |
||
10 | class Builder |
||
11 | { |
||
12 | /** @var Collection */ |
||
13 | private $collection; |
||
14 | /** @var Expression */ |
||
15 | private $expression; |
||
16 | /** @var array */ |
||
17 | private $options; |
||
18 | |||
19 | /** |
||
20 | * Builder constructor. |
||
21 | * |
||
22 | * @param Collection $collection |
||
23 | */ |
||
24 | 10 | public function __construct(Collection $collection) |
|
31 | |||
32 | /** |
||
33 | * @return $this |
||
34 | */ |
||
35 | 1 | public function find() |
|
36 | { |
||
37 | 1 | return $this->setType(Query::TYPE_FIND); |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * @return $this |
||
42 | */ |
||
43 | 1 | public function count() |
|
44 | { |
||
45 | 1 | return $this->setType(Query::TYPE_COUNT); |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param int $type |
||
50 | * |
||
51 | * @return $this |
||
52 | */ |
||
53 | 2 | protected function setType(int $type) |
|
54 | { |
||
55 | 2 | $this->queryType = $type; |
|
56 | |||
57 | 2 | return $this; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param array|Expression $expression |
||
62 | * |
||
63 | * @return $this |
||
64 | */ |
||
65 | public function and($expression) |
||
71 | |||
72 | /** |
||
73 | * @param array|Expression $expression |
||
74 | * |
||
75 | * @return $this |
||
76 | */ |
||
77 | 1 | public function or($expression) |
|
83 | |||
84 | /** |
||
85 | * @return Query |
||
86 | */ |
||
87 | 10 | public function getQuery(): Query |
|
96 | |||
97 | /** |
||
98 | * @return int |
||
99 | */ |
||
100 | 2 | public function getQueryType(): int |
|
104 | |||
105 | /** |
||
106 | * @param array $fields |
||
107 | * |
||
108 | * @return $this |
||
109 | */ |
||
110 | 1 | public function sort(array $fields) |
|
114 | |||
115 | /** |
||
116 | * @param int $limit |
||
117 | * |
||
118 | * @return $this |
||
119 | */ |
||
120 | 1 | public function limit(int $limit) |
|
124 | |||
125 | /** |
||
126 | * @param int $skip |
||
127 | * |
||
128 | * @return $this |
||
129 | */ |
||
130 | 1 | public function skip(int $skip) |
|
131 | { |
||
132 | 1 | return $this->setQueryOption('skip', $skip); |
|
133 | } |
||
134 | |||
135 | /** |
||
136 | * @param array $projection |
||
137 | * |
||
138 | * @return $this |
||
139 | */ |
||
140 | 1 | public function select(...$projection) |
|
150 | |||
151 | /** |
||
152 | * @param string $option |
||
153 | * @param mixed $value |
||
154 | * |
||
155 | * @return $this |
||
156 | */ |
||
157 | 5 | public function setQueryOption(string $option, $value) |
|
163 | |||
164 | /** |
||
165 | * @return Expression |
||
166 | */ |
||
167 | 2 | public function expr(): Expression |
|
171 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: