public function setValue($value, $type = PropertyType::UNDEFINED)
{
$this->checkState();
// need to determine type to avoid unnecessary modification
// don't try to determine if the value changed anyway (i.e. null to delete)
if (PropertyType::UNDEFINED === $type && $this->value === $value) {
$type = $this->valueConverter->determineType($value);
}
// Need to check both value and type, as native php type string is used for a number of phpcr types
if ($this->value !== $value || $this->type !== $type) {
if ($this->getDefinition()->isProtected()) {
$violation = true;
if ('jcr:mixinTypes' === $this->getDefinition()->getName()) {
// check that the jcr:mixinTypes are in sync with the mixin node types
$mixins = array();
foreach ($this->getParent()->getMixinNodeTypes() as $mixin) {
$mixins[] = $mixin->getName();
}
$violation = (bool) array_diff($mixins, $this->value);
}
if ($violation) {
$msg = sprintf("Property '%s' of node type '%s' is protected and cannot be modified", $this->name, $this->getDefinition()->getDeclaringNodeType()->getName());
throw new ConstraintViolationException($msg);
}
}
$this->setModified();
}
// The _setValue call MUST BE after the check to see if the value or type changed
$this->_setValue($value, $type);
}