If a collection for this resource has already begun (i.e. multiple
resources share this type of resource), then merge with the existing collection
@param  mixed $collection
@param  object $object
@return void
5119
private function mergeRootCollection(&$collection, $object)
    {
        if (is_array($object)) {
            foreach ($object as $resource) {
                $this->addResourceToRootCollectionIfNonExistant($collection, $resource);
            }
        } elseif ($object instanceof Collection) {
            $object->each(function ($resource) use (&$collection) {
                $this->addResourceToRootCollectionIfNonExistant($collection, $resource);
            });
        }
    }
30645
public function clean($collection)
    {
        $entry = $this->manifest->get($collection);

        // If the collection exists on the environment then we'll proceed with cleaning the filesystem
        // This removes any double-up production and development builds.
        if (isset($this->environment[$collection]))
        {
            $this->cleanFilesystem($this->environment[$collection], $entry);
        }

        // If the collection does not exist on the environment then we'll instrcut the manifest to
        // forget this collection.
        else
        {
            $this->manifest->forget($collection);
        }

        // Cleaning the manifest is important as it will also remove unnecessary files from the
        // filesystem if a collection has been removed.
        $this->cleanManifestFiles($collection, $entry);

        $this->manifest->save();
    }
566964
public function newObject($collection)
    {
        /** @var MongoObject $obj */
        $obj =$this->container->get($this->classMap->getClassForResult($collection, []));
        $obj->setCollection($collection);

        return $obj;
    }
1142659
private function addResourceToRootCollectionIfNonExistant(&$collection, $resource)
    {
        $identifier = Utility::getProperty($resource, 'id');
        $exists = false;

        $copy = $collection instanceof Collection ? $collection->toArray() : $collection;

        foreach ($copy as $rootResource) {
            if ((int) Utility::getProperty($rootResource, 'id') === (int) $identifier) {
                $exists = true;
                break;
            }
        }

        if ($exists === false) {
            if (is_array($collection)) {
                $collection[] = $resource;
            } elseif ($collection instanceof Collection) {
                $collection->push($resource);
            }
        }
    }
509658
public function preRemove($object): void
    {
        /** @var BlockAdmin $block */
        $block = $this->blockManager->get($object);
        $block->preRemove($object);
    }
259647
public function loadFromArrayForGroups($object)
    {
        parent::loadFromArray($object);

        if (!empty($object->items)) {
            foreach($object->items AS &$item) {
                $Group = new Group();
                $Group->loadFromArray($item);

                $item = $Group;
            }
        }
70411
protected function preUpdateManyToManyManager($object)
    {
        $this->configureManyToManyManager();

        $rc = new \ReflectionClass($this->getClass());
        $remove_method = 'remove' . ucfirst($rc->getShortName());

        foreach ($this->manyToManyCollections as $fieldname) {
            $get_method = 'get' . ucfirst($fieldname);
            $orig_collection = $object->$get_method()->getSnapshot();
            $new_collection = $object->$get_method();
            foreach ($orig_collection as $entity) {
                if (!$new_collection->contains($entity)) {
                    $entity->$remove_method($object);
                    $this->getModelManager()->update($entity);
                }
            }
        }
    }
894465
public function initialize($object)
    {
        if (!is_object($object)) {
            return;
        }

        foreach ($this->knownDependencies as $interface => $dependencyInfo) {
            list($setterMethod, $serviceId) = $dependencyInfo;

            if (is_a($object, $interface)) {
                $object->$setterMethod($this->container->get($serviceId));
            }
        }
    }
833499
public function collections(array $collections) : void {
        foreach ($collections as $name => $callback) {
            $this->make($name, $callback);
        }
    }
348378
private function _collection($collection) {
    return (!is_array($collection) && !is_object($collection)) ? str_split((string) $collection) : $collection;
  }
74071
public function addCollection(RequirementCollection $collection)
    {
        $this->requirements = array_merge($this->requirements, $collection->all());
    }
1306987
public function mergeValues($object) {
        $values = $object->__toArray();
        foreach ($values as $k => $v) {
            $this->values[$k] = $v;
        }
        if ($object->id) $this->id = $object->id;

        $this->dirty_values = [];
    }
1092024
public function republishCommand(string $collection = 'persistent'): void
    {
        $collectionName = $collection;
        $collection = $this->resourceManager->getCollection($collectionName);
        if (!$collection) {
            $this->outputLine('<error>The collection %s does not exist.</error>', [$collectionName]);
            exit(1);
        }

        $target = $collection->getTarget();
        if (!$target instanceof GcsTarget) {
            $this->outputLine('<error>The target defined in collection %s is not a Google Cloud Storage target.</error>', [$collectionName]);
            exit(1);
        }

        $this->outputLine('Republishing collection ...');
        $this->output->progressStart();
        try {
            foreach ($collection->getObjects() as $object) {
                /** @var StorageObject $object */
                $resource = $this->resourceManager->getResourceBySha1($object->getSha1());
                if ($resource) {
                    $target->publishResource($resource, $collection);
                }
                $this->output->progressAdvance();
            }
        } catch (\Exception $e) {
            $this->outputLine('<error>Publishing failed</error>');
            $this->outputLine($e->getMessage());
            $this->outputLine(get_class($e));
            exit(2);
        }
        $this->output->progressFinish();
        $this->outputLine();
    }
948166
public function loadFromArray ($object)
    {
        parent::loadFromArray($object);

        if (!empty($this->recipients->items)) {
            foreach($this->recipients->items AS &$item) {
                $Recipient = new Recipient();
                $Recipient->loadFromArray($item);

                $item = $Recipient;
            }
        }
84164
public function update($object)
    {
        if ($this->isNewObject($object)) {
            throw new UnknownObjectException('The object of type "' . get_class($object) . '" (identifier: "' . $this->getIdentifierByObject($object) . '") which was passed to EntityManager->update() is not a previously persisted object. Check the code which updates this entity and make sure that only objects are updated which were persisted before. Alternatively use add() for persisting new objects."', 1313663277);
        }
        try {
            $this->entityManager->persist($object);
        } catch (\Exception $exception) {
            throw new PersistenceException('Could not merge object of type "' . get_class($object) . '"', 1297778180, $exception);
        }
    }
994556
public function preUpdate($object)
    {
        $this->blockManager->get($object)->preUpdate($object);

        // fix weird bug with setter object not being call
        $object->setChildren($object->getChildren());

        if ($object->getPage() instanceof PageInterface) {
            $object->getPage()->setEdited(true);
        }
    }
193285
protected function configureRoutes(RouteCollection $collection)
    {
        parent::configureRoutes($collection);
        if (!$this->getAllowToAdd()) {
            $collection->remove('create');
        }
    }