public function setProperty($name, $value, $type = PropertyType::UNDEFINED, $validate = true)
{
$this->checkState();
if ($validate && 'jcr:uuid' === $name && !$this->isNodeType('mix:referenceable')) {
throw new ConstraintViolationException('You can only change the uuid of newly created nodes that have "referenceable" mixin.');
}
if ($validate) {
if (is_array($value)) {
foreach ($value as $key => $v) {
if (null === $v) {
unset($value[$key]);
}
}
}
$types = $this->getMixinNodeTypes();
array_push($types, $this->getPrimaryNodeType());
if (null !== $value) {
$exception = null;
foreach ($types as $nt) {
/** @var $nt NodeType */
try {
$nt->canSetProperty($name, $value, true);
$exception = null;
break;
// exit loop, we found a valid definition
} catch (RepositoryException $e) {
if (null === $exception) {
$exception = $e;
}
}
}
if (null !== $exception) {
throw $exception;
}
} else {
// $value is null for property removal
// if any type forbids, throw exception
foreach ($types as $nt) {
/** @var $nt \Jackalope\NodeType\NodeType */
$nt->canRemoveProperty($name, true);
}
}
}
//try to get a namespace for the set property
if (strpos($name, ':') !== false) {
list($prefix) = explode(':', $name);
//Check if the namespace exists. If not, throw an NamespaceException
$this->session->getNamespaceURI($prefix);
}
if (is_null($value)) {
if (isset($this->properties[$name])) {
$this->properties[$name]->remove();
}
return null;
}
return $this->_setProperty($name, $value, $type, false);
}