public function setMixins(array $mixinNames)
{
$toRemove = array();
if ($this->hasProperty('jcr:mixinTypes')) {
foreach ($this->getPropertyValue('jcr:mixinTypes') as $mixin) {
if (false !== ($key = array_search($mixin, $mixinNames))) {
unset($mixinNames[$key]);
} else {
$toRemove[] = $mixin;
}
}
}
if (!(count($toRemove) || count($mixinNames))) {
return;
// nothing to do
}
// make sure the new types actually exist before we add anything
$ntm = $this->session->getWorkspace()->getNodeTypeManager();
foreach ($mixinNames as $mixinName) {
$nodeType = $ntm->getNodeType($mixinName);
if (!$nodeType->isMixin()) {
throw new ConstraintViolationException("Trying to add a mixin '{$mixinName}' that is a primary type");
}
}
foreach ($mixinNames as $type) {
$this->addMixin($type);
}
foreach ($toRemove as $type) {
$this->removeMixin($type);
}
}