| @@ 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 instance of GridFS |
|
| @@ 343-367 (lines=25) @@ | ||
| 340 | * @return \Sokil\Mongo\GridFS |
|
| 341 | * @throws \Sokil\Mongo\Exception |
|
| 342 | */ |
|
| 343 | public function getGridFS($name = 'fs') |
|
| 344 | { |
|
| 345 | // return from pool |
|
| 346 | if($this->collectionPoolEnabled && isset($this->collectionPool[$name])) { |
|
| 347 | return $this->collectionPool[$name]; |
|
| 348 | } |
|
| 349 | ||
| 350 | // no object in pool - init new |
|
| 351 | $classDefinition = $this->getCollectionDefinition($name, array('gridfs' => true)); |
|
| 352 | $className = $classDefinition->getClass(); |
|
| 353 | ||
| 354 | // create collection class |
|
| 355 | $collection = new $className($this, $name, $classDefinition); |
|
| 356 | if(!$collection instanceof \Sokil\Mongo\GridFS) { |
|
| 357 | throw new Exception('Must be instance of \Sokil\Mongo\GridFS'); |
|
| 358 | } |
|
| 359 | ||
| 360 | // store to pool |
|
| 361 | if($this->collectionPoolEnabled) { |
|
| 362 | $this->collectionPool[$name] = $collection; |
|
| 363 | } |
|
| 364 | ||
| 365 | // return |
|
| 366 | return $collection; |
|
| 367 | } |
|
| 368 | ||
| 369 | /** |
|
| 370 | * |
|