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
355947
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];
    }
294662
public function addPermissions($collection)
    {
        $newCollection = collect([]);

        $customActions = $this->crudeSetup->getCustomActions();

        $collection->each(function ($model) use ($newCollection, $customActions) {
            if ($this->permissionView($model)) {
                $model = $this->addPermissionsForModel($model, $customActions);
                $newCollection->push($model);
            }
        });

        return $newCollection;
    }
309912
public function grabFromCollection($collection, $criteria = [])
    {
        $collection = $this->driver->getDbh()->selectCollection($collection);
        return $collection->findOne($criteria);
    }
75398
public function add($collection)
    {
        if (!is_array($collection) and !($collection instanceof \Traversable)) {
            throw new \InvalidArgumentException(self::MSG_NOT_ITERABLE, 230);
        }
        
        foreach ($collection as $name => $closure) {
            $this->set($name, $closure);
        }
        
        return $this;
    }
319106
protected function loadDefaultWith(EloquentCollection $collection): self
    {
        if ($collection->isEmpty()) {
            return $this;
        }

        $model = $collection->first();
        $reflection = new ReflectionClass($model);
        $withProperty = $reflection->getProperty('with');
        $withProperty->setAccessible(true);

        $with = array_filter((array) $withProperty->getValue($model), function ($relation) use ($model) {
            return ! $model->relationLoaded($relation);
        });

        if (! empty($with)) {
            $collection->load($with);
        }

        return $this;
    }
1322887
public function hydrateCollection(array $collection)
    {
        $records = array();

        foreach ($collection as $key => $record) {
            if ($record instanceof \stdClass) {
                $records[$key] = $this->hydrate($record);
            } else {
                $records[$key] = $this->hydrateRid(new Rid($record));
            }
        }

        return new ArrayCollection($records);
    }
609699
public function createMany(): Collection
	{
		$collection = new Collection();

		foreach ($this->getInput() as $item) {
			$repository = clone $this;
			$repository->setInput($item);
			$collection->add($repository->create());
		}

		return $collection;
	}
1224695
public function collection(Collection $collection)
    {
        $entries = new Entries();

        foreach ($collection as $category) {
            $entry = new Entry($category);

            $entry
                ->field('id')
                ->field('label')
                ->field('slug')
                ->field('parent')
                ->field('position')
            ;

            $entries->addEntry($entry);
        }

        return $entries->toArray();
    }
565590
public function get($collection)
    {
        $collection = $this->makeCollection($collection);

        $url      = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collection]);
        $response = $this->getConnection()->get($url);

        $data = $response->getJson();

        return Collection::createFromArray($data);
    }
141832
public function transform($collection)
    {
        if ($collection && !is_array($collection) && !($collection instanceof \ArrayAccess)) {
            // in case of single entity, we have to make sure it's managed
            if (!$this->er->getManager()->contains($collection)) {
                $collection = $this->er->getManager()->merge($collection);
            }
        }
        return $collection;
    }
484075
public function union( common_Collection $collection)
    {
        $returnValue = null;

        
        $returnValue = new core_kernel_classes_ContainerCollection($this);     
        $returnValue->sequence = array_merge($this->sequence, $collection->sequence );      
        

        return $returnValue;
    }
764856
protected function createCustomCollection($data = [], $class, $collection)
    {
        if (is_object($class)) {
            $class = get_class($class);
        }

        if (null === $data) {
            return $collection;
        }

        foreach ($data as $item) {
            $collection->add(null, $this->hydrate(new $class(), $item));
        }

        return $collection;
    }
1200784
public static function toList($collection) {
		$list = new ArrayList();
		foreach ($collection as $v) {
			$list->add(self::toCollection($v));
		}
		return $list;
	}
1078026
public function transformCollection($collection, $meta = [])
    {
        return $this->getFractalFactory()->makeCollection($collection, $meta, $this->getTransformer());
    }
1106069
public function merge(ObjectCollectionInterface $collection)
    {
        $this->items = array_merge(
            $this->getItems(),
            $collection->getItems()
        );

        return $this;
    }
496208
public function fillCollectionWithRelations(CollectionInterface $collection)
    {
        if (!$collection->count()) {
            return $collection;
        }

        foreach ($this->getWith() as $relation) {
            $relation->fillCollection($collection);
        }

        return $collection;
    }
859867
public static function create($collection, $id = null, $database = null)
    {
        if ($collection instanceof \Phalcon\Mvc\Collection) {
            $id = $collection->getId();
            $collection = $collection->getSource();
        }
        if ($id instanceof \Phalcon\Mvc\Collection) {
            $id = $id->getId();
        }
        if (!$id instanceof \MongoId && $id !== null) {
            $id = new \MongoId($id);
        }

        return parent::create($collection, $id, $database);
    }