/** * Set value. * * @param string $key * @param mixed $value * * @throws \InvalidArgumentException */ public function setValue($key, $value) { /* @var Property $property */ $property = $this->properties->get($key); $v = $this->getPropertyValue($key); if ($property->multiple) { if ($value !== null && !is_array($value) && !$value instanceof Collection) { throw new \InvalidArgumentException('Value must be array'); } $this->queuedDelete($property); $this->getPropertyValues($key)->put($property->name, new Collection()); if ($value !== null) { foreach ($value as $val) { $this->addValue($property, $val); } } } else { /* @var Value $value */ if ($v !== null) { if ($value === null) { $this->queuedDelete($property); } else { $v->setAttribute('value', $value); } } elseif ($value !== null) { $this->addValue($property, $value); } } $this->updateValue($key); }