Example #1
0
 /**
  * Factory to create new collection by its name or instance
  *
  * @param string|Norm\Collection $collection Collection name or instance
  *
  * @return Norm\Collection Conllection created by factory
  */
 public function factory($collection)
 {
     if ($collection instanceof Collection) {
         $collectionName = $collection->getName();
     } else {
         $collectionName = $collection;
     }
     if (!isset($this->collections[$collectionName])) {
         if (!$collection instanceof Collection) {
             $collection = Norm::createCollection(array('name' => $collection, 'connection' => $this));
             $this->applyHook('norm.after.factory', $collection);
         }
         $this->collections[$collectionName] = $collection;
     }
     return $this->collections[$collectionName];
 }