1 | <?php |
||
32 | class MongoService implements MongoServiceInterface |
||
33 | { |
||
34 | /** |
||
35 | * @var \MongoDB |
||
36 | */ |
||
37 | protected $dbConnection; |
||
38 | |||
39 | /** |
||
40 | * @var ClassMapInterface |
||
41 | */ |
||
42 | protected $classMap; |
||
43 | |||
44 | /** |
||
45 | * @var ContainerInterface |
||
46 | */ |
||
47 | protected $container; |
||
48 | |||
49 | /** |
||
50 | * @param \MongoDB $dbConnection |
||
51 | * @param ClassMapInterface $classMap |
||
52 | * @param ContainerInterface $container |
||
53 | */ |
||
54 | public function __construct(\MongoDB $dbConnection, ClassMapInterface $classMap, ContainerInterface $container) |
||
60 | |||
61 | /** |
||
62 | * @return \MongoDB |
||
63 | */ |
||
64 | public function getDB() |
||
68 | |||
69 | /** |
||
70 | * convenience method to retrieve object by id, should be used in |
||
71 | * public static method by the derived class |
||
72 | * |
||
73 | * @param string $collection |
||
74 | * @param string $mongoId |
||
75 | * @return MongoObject |
||
76 | * @throws \MongoException |
||
77 | */ |
||
78 | public function getById($collection, $mongoId) |
||
82 | |||
83 | /** |
||
84 | * convenience method to retrieve object by criteria, should be used in |
||
85 | * public static method by the derived class |
||
86 | * |
||
87 | * @param string $collection |
||
88 | * @param array $criteria |
||
89 | * @return MongoObject |
||
90 | * @throws \MongoException |
||
91 | */ |
||
92 | public function getByCriteria($collection, $criteria) |
||
108 | |||
109 | /** |
||
110 | * @param string $collection |
||
111 | * @param array $criteria |
||
112 | * @param array $fields |
||
113 | * @return Result |
||
114 | * @throws \Exception |
||
115 | */ |
||
116 | public function find($collection, array $criteria, array $fields = []) |
||
127 | |||
128 | /** |
||
129 | * Run Aggregation through the Aggregation Pipeline |
||
130 | * |
||
131 | * @param string $collection |
||
132 | * @param array $pipeline |
||
133 | * @param array $options |
||
134 | * @return mixed |
||
135 | * @throws Exception |
||
136 | */ |
||
137 | public function aggregate($collection, array $pipeline, $options = []) |
||
146 | |||
147 | /** |
||
148 | * @param string $collection |
||
149 | * @param string $fieldname |
||
150 | * @param array $criteria |
||
151 | * @return array |
||
152 | * @throws \Exception |
||
153 | */ |
||
154 | public function distinct($collection, $fieldname, array $criteria = []) |
||
158 | |||
159 | /** |
||
160 | * returns the first found matching document |
||
161 | * |
||
162 | * @param string $collection |
||
163 | * @param array $criteria |
||
164 | * @param array $fields |
||
165 | * @return array |
||
166 | * @throws \Exception |
||
167 | */ |
||
168 | public function findOne($collection, array $criteria, array $fields = []) |
||
172 | |||
173 | /** |
||
174 | * conveniant method to create new instances |
||
175 | * @param string $collection |
||
176 | * @return MongoObject |
||
177 | * @throws \MongoException |
||
178 | */ |
||
179 | public function newObject($collection) |
||
187 | |||
188 | /** |
||
189 | * @param string $input name of the collection from which to map/reduce |
||
190 | * @param string $output name of the collection to write |
||
191 | * @param string $map map method |
||
192 | * @param string $reduce reduce method |
||
193 | * @param array $query criteria to apply |
||
194 | * @param array $additional |
||
195 | * @return mixed |
||
196 | */ |
||
197 | public function mapReduce($input, $output, $map, $reduce, $query = null, $additional = array()) |
||
217 | } |
||
218 |