1 | <?php |
||
11 | class Collection |
||
12 | { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $name; |
||
17 | |||
18 | /** |
||
19 | * @var DocumentStore |
||
20 | */ |
||
21 | protected $store; |
||
22 | |||
23 | /** |
||
24 | * @var Database |
||
25 | */ |
||
26 | protected $database; |
||
27 | |||
28 | /** |
||
29 | * @var Parser |
||
30 | */ |
||
31 | protected $parser; |
||
32 | |||
33 | /** |
||
34 | * Construct a new collection. |
||
35 | * |
||
36 | * @param Database $database |
||
37 | * @param DocumentStore $store |
||
38 | * @param string $name |
||
39 | */ |
||
40 | 6 | public function __construct(Database $database, DocumentStore $store, $name) |
|
41 | { |
||
42 | 6 | $this->name = $name; |
|
43 | 6 | $this->store = $store; |
|
44 | 6 | $this->database = $database; |
|
45 | 6 | $this->parser = $database->getParser(); |
|
46 | 6 | } |
|
47 | |||
48 | /** |
||
49 | * Drop the collection. |
||
50 | * |
||
51 | * @return bool |
||
52 | */ |
||
53 | 1 | public function drop() |
|
54 | { |
||
55 | 1 | return $this->database->dropCollection($this->name); |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Remove all the documents from the collection. |
||
60 | * |
||
61 | * @return bool |
||
62 | */ |
||
63 | 1 | public function truncate() |
|
64 | { |
||
65 | 1 | $this->store->truncate(); |
|
66 | 1 | } |
|
67 | |||
68 | /** |
||
69 | * Insert a new document. |
||
70 | * |
||
71 | * @param Identifiable $document |
||
72 | * |
||
73 | * @return bool |
||
74 | */ |
||
75 | 1 | public function insert(Identifiable $document) |
|
76 | { |
||
77 | 1 | return $this->store->insertDocument($document); |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * Update existing documents. |
||
82 | * |
||
83 | * @param array $criteria |
||
84 | * @param Identifiable $updated |
||
85 | * @param bool $multiple |
||
86 | * |
||
87 | * @return int The count of the documents updated. |
||
88 | */ |
||
89 | public function update($criteria, Identifiable $updated, $multiple = false) |
||
98 | |||
99 | /** |
||
100 | * Remove documents from the collection. |
||
101 | * |
||
102 | * @param mixed $criteria |
||
103 | * @param bool $multiple |
||
104 | * |
||
105 | * @return int The count of the document deleted. |
||
106 | */ |
||
107 | 1 | public function remove($criteria, $multiple = false) |
|
119 | |||
120 | /** |
||
121 | * Find documents in the collection. |
||
122 | * |
||
123 | * @param array $criteria |
||
124 | * |
||
125 | * @return array The array of results. |
||
126 | */ |
||
127 | 1 | public function find($criteria) |
|
131 | |||
132 | 2 | protected function onMatch($criteria, $limit = null) |
|
141 | |||
142 | 2 | protected function newMatcher(ExpressionInterface $expression) |
|
146 | } |
||
147 |