| @@ 310-334 (lines=25) @@ | ||
| 307 | * @return \Sokil\Mongo\Collection |
|
| 308 | * @throws \Sokil\Mongo\Exception |
|
| 309 | */ |
|
| 310 | public function getCollection($name) |
|
| 311 | { |
|
| 312 | // return from pool |
|
| 313 | if($this->collectionPoolEnabled && isset($this->collectionPool[$name])) { |
|
| 314 | return $this->collectionPool[$name]; |
|
| 315 | } |
|
| 316 | ||
| 317 | // no object in pool - init new |
|
| 318 | $classDefinition = $this->getCollectionDefinition($name); |
|
| 319 | $className = $classDefinition->getClass(); |
|
| 320 | ||
| 321 | // create collection class |
|
| 322 | $collection = new $className($this, $name, $classDefinition); |
|
| 323 | if(!$collection instanceof \Sokil\Mongo\Collection) { |
|
| 324 | throw new Exception('Must be instance of \Sokil\Mongo\Collection'); |
|
| 325 | } |
|
| 326 | ||
| 327 | // store to pool |
|
| 328 | if($this->collectionPoolEnabled) { |
|
| 329 | $this->collectionPool[$name] = $collection; |
|
| 330 | } |
|
| 331 | ||
| 332 | // return |
|
| 333 | return $collection; |
|
| 334 | } |
|
| 335 | ||
| 336 | /** |
|
| 337 | * Get Document instance by it's reference |
|
| @@ 361-385 (lines=25) @@ | ||
| 358 | * @return \Sokil\Mongo\GridFS |
|
| 359 | * @throws \Sokil\Mongo\Exception |
|
| 360 | */ |
|
| 361 | public function getGridFS($name = 'fs') |
|
| 362 | { |
|
| 363 | // return from pool |
|
| 364 | if($this->collectionPoolEnabled && isset($this->collectionPool[$name])) { |
|
| 365 | return $this->collectionPool[$name]; |
|
| 366 | } |
|
| 367 | ||
| 368 | // no object in pool - init new |
|
| 369 | $classDefinition = $this->getCollectionDefinition($name, array('gridfs' => true)); |
|
| 370 | $className = $classDefinition->getClass(); |
|
| 371 | ||
| 372 | // create collection class |
|
| 373 | $collection = new $className($this, $name, $classDefinition); |
|
| 374 | if(!$collection instanceof \Sokil\Mongo\GridFS) { |
|
| 375 | throw new Exception('Must be instance of \Sokil\Mongo\GridFS'); |
|
| 376 | } |
|
| 377 | ||
| 378 | // store to pool |
|
| 379 | if($this->collectionPoolEnabled) { |
|
| 380 | $this->collectionPool[$name] = $collection; |
|
| 381 | } |
|
| 382 | ||
| 383 | // return |
|
| 384 | return $collection; |
|
| 385 | } |
|
| 386 | ||
| 387 | /** |
|
| 388 | * |
|