1 | <?php |
||
22 | class DocumentSource extends Component implements \Countable, \IteratorAggregate |
||
23 | { |
||
24 | use SaturateTrait; |
||
25 | |||
26 | /** |
||
27 | * Linked document model. ODM can automatically index and link user sources to models based on |
||
28 | * value of this constant. |
||
29 | * |
||
30 | * Use this constant in custom source implementation in order to automatically link it to |
||
31 | * appropriate model AND be able to create source as constructor or method injection without |
||
32 | * ODM dependency. |
||
33 | */ |
||
34 | const DOCUMENT = null; |
||
35 | |||
36 | /** |
||
37 | * @var DocumentSelector |
||
38 | */ |
||
39 | private $selector; |
||
40 | |||
41 | /** |
||
42 | * Associated document class. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | private $class = null; |
||
47 | |||
48 | /** |
||
49 | * @invisible |
||
50 | * |
||
51 | * @var ODMInterface |
||
52 | */ |
||
53 | protected $odm = null; |
||
54 | |||
55 | /** |
||
56 | * @param string $class |
||
57 | * @param ODMInterface $odm |
||
58 | * |
||
59 | * @throws SourceException |
||
60 | */ |
||
61 | public function __construct(string $class = null, ODMInterface $odm = null) |
||
74 | |||
75 | /** |
||
76 | * Associated class. |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | public function getClass(): string |
||
84 | |||
85 | /** |
||
86 | * Create new DocumentEntity based on set of provided fields. |
||
87 | * |
||
88 | * @final Change static method of entity, not this one. |
||
89 | * |
||
90 | * @param array $fields |
||
91 | * @param string $class Due ODM models can be inherited you can use this argument to specify |
||
92 | * custom model class. |
||
93 | * |
||
94 | * @return CompositableInterface|Document |
||
95 | */ |
||
96 | public function create($fields = [], string $class = null) |
||
101 | |||
102 | /** |
||
103 | * Find document by it's primary key. |
||
104 | * |
||
105 | * @see findOne() |
||
106 | * |
||
107 | * @param string|\MongoId $id Primary key value. |
||
108 | * |
||
109 | * @return CompositableInterface|Document|null |
||
110 | */ |
||
111 | public function findByPK($id) |
||
115 | |||
116 | /** |
||
117 | * Select one document from mongo collection. |
||
118 | * |
||
119 | * @param array $query Fields and conditions to query by. |
||
120 | * @param array $sortBy Always specify sort by to ensure that results are stable. |
||
121 | * |
||
122 | * @return CompositableInterface|Document|null |
||
123 | */ |
||
124 | public function findOne(array $query = [], array $sortBy = []) |
||
128 | |||
129 | /** |
||
130 | * Get associated document selection with pre-configured query (if any). |
||
131 | * |
||
132 | * @param array $query |
||
133 | * |
||
134 | * @return DocumentSelector |
||
135 | */ |
||
136 | public function find(array $query = []): DocumentSelector |
||
140 | |||
141 | /** |
||
142 | * @param array $query |
||
143 | * |
||
144 | * @return int |
||
145 | */ |
||
146 | public function count(array $query = []): int |
||
150 | |||
151 | /** |
||
152 | * @return DocumentSelector |
||
153 | */ |
||
154 | public function getIterator(): DocumentSelector |
||
158 | |||
159 | /** |
||
160 | * Create source with new associated selector. |
||
161 | * |
||
162 | * @param DocumentSelector $selector |
||
163 | * |
||
164 | * @return DocumentSource |
||
165 | */ |
||
166 | public function withSelector(DocumentSelector $selector): DocumentSource |
||
173 | |||
174 | /** |
||
175 | * Set initial selector. |
||
176 | * |
||
177 | * @param DocumentSelector $selector |
||
178 | */ |
||
179 | protected function setSelector(DocumentSelector $selector) |
||
183 | |||
184 | /** |
||
185 | * Get associated selector. |
||
186 | * |
||
187 | * @return DocumentSelector |
||
188 | */ |
||
189 | protected function getSelector(): DocumentSelector |
||
198 | |||
199 | /** |
||
200 | * {@inheritdoc} |
||
201 | */ |
||
202 | protected function iocContainer() |
||
211 | } |