/**
* @param PrivilegeSubjectInterface|PropertyAwareNodePrivilegeSubject|MethodPrivilegeSubject $subject
* @return boolean
* @throws InvalidPrivilegeTypeException
*/
public function matchesSubject(PrivilegeSubjectInterface $subject)
{
if ($subject instanceof PropertyAwareNodePrivilegeSubject === false && $subject instanceof MethodPrivilegeSubject === false) {
throw new InvalidPrivilegeTypeException(sprintf('Privileges of type "%s" only support subjects of type "%s" or "%s", but we got a subject of type: "%s".', ReadNodePropertyPrivilege::class, PropertyAwareNodePrivilegeSubject::class, MethodPrivilegeSubject::class, get_class($subject)), 1417018448);
}
$this->initialize();
if ($subject instanceof MethodPrivilegeSubject) {
if ($this->methodPrivilege->matchesSubject($subject) === false) {
return false;
}
$joinPoint = $subject->getJoinPoint();
// if the context isn't restricted to certain properties, it matches *all* properties
if ($this->nodeContext->hasProperties()) {
$methodName = $joinPoint->getMethodName();
$actualPropertyName = null;
if (isset($this->methodNameToPropertyMapping[$methodName])) {
$propertyName = $this->methodNameToPropertyMapping[$methodName];
} else {
$propertyName = $joinPoint->getMethodArgument('propertyName');
}
if (!in_array($propertyName, $this->nodeContext->getNodePropertyNames())) {
return false;
}
}
/** @var NodeInterface $node */
$node = $joinPoint->getProxy();
$nodePrivilegeSubject = new NodePrivilegeSubject($node);
return parent::matchesSubject($nodePrivilegeSubject);
}
if ($subject->hasPropertyName() && in_array($subject->getPropertyName(), $this->nodeContext->getNodePropertyNames()) === false) {
return false;
}
return parent::matchesSubject($subject);
}