Add mutable generators to the mutates collection

@param mixed $objects
@return $this

@throws \InvalidArgumentException
346210
public function mutate($objects)
	{
		$objects = call_user_func_array(array($this, 'flattenArguments'), func_get_args());
		$collect = [];

		foreach ($objects as $obj) {
			if ($obj instanceof AbstractGenerator) {
				array_push($collect, $obj);
				continue;
			}

			throw new InvalidArgumentException(sprintf('Mutable objects must be instances of %s.', AbstractGenerator::class));
		}
		
		$this->mutates = array_merge(static::objectDiffInArrays($this->mutates, $collect), $collect);
		
		return $this;
	}
757903
public function offsetUnset($object)
    {
        if (!$object instanceof ObjectHandlable) {
            throw new \InvalidArgumentException('Object needs to implement ObjectHandlable');
        }

        unset($this->__data[$object->getHandle()]);
        return $this;
    }
114241
public function freeze($object, array &$objects = array())
    {
        if (!is_object($object)) {
            throw new InvalidArgumentException(1, 'object');
        }

        if ($object instanceof LazyProxy) {
            if ($object->isThawed()) {
                $object = $object->getObject();
            } else {
                return array('root' => $object->getId());
            }
        }

        // If the object has not been frozen before, generate a new UUID and
        // store it in the "special" __freezer_uuid property.
        if (!isset($object->{$this->idProperty})) {
            $object->{$this->idProperty} = $this->generateId();
        }

        if (!isset($object->__freezer)) {
            $object->__freezer = array();
        }

        $isDirty = $this->isDirty($object, true);
        $id      = (string)$object->{$this->idProperty};

        if (!isset($objects[$id])) {
            $objects[$id] = array(
                'class'   => get_class($object),
                'isDirty' => $isDirty,
                'state'   => array()
            );

            // Iterate over the properties of the object.
            $properties = call_user_func($this->propertyReader, $object);

            foreach ($properties as $name => $value) {
                if ($name !== $this->idProperty) {
                    if (is_array($value)) {
                        $this->freezeArray($value, $objects);
                    } elseif (is_object($value)) {
                        // Freeze the aggregated object.
                        $this->freeze($value, $objects);

                        // Replace $v with the aggregated object's id.
                        $value = '__freezer_' . $value->{$this->idProperty};
                    } elseif (is_resource($value)) {
                        $value = null;
                    }

                    // Store the attribute in the object's state array.
                    $objects[$id]['state'][$name] = $value;
                }
            }
        }

        return array('root' => $id, 'objects' => $objects);
    }
1286404
public static function createFromObject($object)
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException('Object was expected.');
        }

        $className = get_class($object);

        return new self($className);
    }
992053
public function immutable($props)
	{
		$props = call_user_func_array(array($this, 'flattenArguments'), func_get_args());
		
		$this->mutables = array_diff($this->mutables, $props);
		
		return $this;
	}
120715
private function addObjects($objects, &$container)
    {
        if (!is_array($objects))
        {
            $objects = [$objects];
        }
        foreach ($objects as $object)
        {
            if ($object->getObjectId() == null)
            {
                $container['null'][] = $object;
            } else
            {
                $container[$object->getObjectID()] = $object;
            }
        }
    }
159217
public function mergeWith(self $objects): self
    {
        $clone = clone $this;
        foreach ($objects->objects as $reference => $object) {
            $clone->objects[$reference] = $object;
            $clone->array[$reference] = $object->getInstance();
        }
        
        return $clone;
    }
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;
    }
106588
public function setParent($object) {
		
		if (! is_object($object)) {
			throw new \InvalidArgumentException("Expecting object, given: ".gettype($object));
		}
		
		$this->parent = $object;
		return $this;
	}
255017
public function sortObjects($objects)
    {
        $collection = new HierarchicalCollection($objects, false);
        $collection->sortTree();

        return $collection->all();
    }
1302282
public function addRules($rules)
    {
        if ($rules instanceof RiskyRulesAwareInterface && $rules->isRisky()) {
            $this->setRiskyAllowed(true);
        }

        if ($rules instanceof \Traversable) {
            $rules = iterator_to_array($rules);
        }

        if (!is_array($rules)) {
            throw new \InvalidArgumentException('Expected rules to be an iterable.');
        }

        $rules = array_replace($this->getRules(), $rules);

        $this->setRules($rules);

        return $this;
    }
881682
public function push($object): self
    {
        $this->internalDataListUpdate();
        array_push($this->internalDataListData, $object);
        return $this;
    }
1351738
public function setObjects(array $objects)
    {
        foreach ($objects as $object) {
            $this->checkType(ObjectDataInterface::class, $object);
        }

        $this->objects = $objects;
    }
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);
                }
            }
        }
    }
1165193
public function addCollection(PermissionCollection $permissions)
    {
        if ($permissions->getObjectType() !== $this->getObjectType()) {
            throw new InvalidArgumentException('Mismating object types.');
        }

        foreach ($permissions->all() as $permission) {
            $this->add($permission);
        }

        return $this;
    }
1302263
public function addRepositories($repositories)
    {
        if (!is_array($repositories) && (!is_object($repositories) || !$repositories instanceof \Traversable)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid argument provided for $repositories, expecting either an array or Traversable object, but' .
                ' "%s" given',
                is_object($repositories) ? get_class($repositories) : gettype($repositories)
            ));
        }
        foreach ($repositories as $repo) {
            $this->addRepository($repo);
        }
    }
661343
public function setObjects(array $objects)
    {
        $this->objects = $objects;
        $this->objects[ObjectManagerInterface::class]['i'] = $this;
        $this->objects[get_class($this)]['i'] = $this;
    }