@@ 336-360 (lines=25) @@ | ||
333 | * @return \Sokil\Mongo\Collection |
|
334 | * @throws \Sokil\Mongo\Exception |
|
335 | */ |
|
336 | public function getCollection($name) |
|
337 | { |
|
338 | // return from pool |
|
339 | if ($this->collectionPoolEnabled && isset($this->collectionPool[$name])) { |
|
340 | return $this->collectionPool[$name]; |
|
341 | } |
|
342 | ||
343 | // no object in pool - init new |
|
344 | $classDefinition = $this->getCollectionDefinition($name); |
|
345 | $className = $classDefinition->getClass(); |
|
346 | ||
347 | // create collection class |
|
348 | $collection = new $className($this, $name, $classDefinition); |
|
349 | if (!$collection instanceof Collection) { |
|
350 | throw new Exception('Must be instance of \Sokil\Mongo\Collection'); |
|
351 | } |
|
352 | ||
353 | // store to pool |
|
354 | if ($this->collectionPoolEnabled) { |
|
355 | $this->collectionPool[$name] = $collection; |
|
356 | } |
|
357 | ||
358 | // return |
|
359 | return $collection; |
|
360 | } |
|
361 | ||
362 | /** |
|
363 | * Get Document instance by it's reference |
|
@@ 387-411 (lines=25) @@ | ||
384 | * @return \Sokil\Mongo\GridFS |
|
385 | * @throws \Sokil\Mongo\Exception |
|
386 | */ |
|
387 | public function getGridFS($name = 'fs') |
|
388 | { |
|
389 | // return from pool |
|
390 | if ($this->collectionPoolEnabled && isset($this->collectionPool[$name])) { |
|
391 | return $this->collectionPool[$name]; |
|
392 | } |
|
393 | ||
394 | // no object in pool - init new |
|
395 | $classDefinition = $this->getCollectionDefinition($name, array('gridfs' => true)); |
|
396 | $className = $classDefinition->getClass(); |
|
397 | ||
398 | // create collection class |
|
399 | $collection = new $className($this, $name, $classDefinition); |
|
400 | if (!$collection instanceof \Sokil\Mongo\GridFS) { |
|
401 | throw new Exception('Must be instance of \Sokil\Mongo\GridFS'); |
|
402 | } |
|
403 | ||
404 | // store to pool |
|
405 | if ($this->collectionPoolEnabled) { |
|
406 | $this->collectionPool[$name] = $collection; |
|
407 | } |
|
408 | ||
409 | // return |
|
410 | return $collection; |
|
411 | } |
|
412 | ||
413 | /** |
|
414 | * |