Neos\Flow\Aop\Pointcut\RuntimeExpressionEvaluator::evaluate PHP Method

evaluate() public method

Evaluate an expression with the given JoinPoint
public evaluate ( string $privilegeIdentifier, Neos\Flow\Aop\JoinPointInterface $joinPoint ) : mixed
$privilegeIdentifier string MD5 hash that identifies a privilege
$joinPoint Neos\Flow\Aop\JoinPointInterface
return mixed
    public function evaluate($privilegeIdentifier, JoinPointInterface $joinPoint)
    {
        $functionName = $this->generateExpressionFunctionName($privilegeIdentifier);
        if (!$this->runtimeExpressions[$functionName] instanceof \Closure) {
            throw new Exception('Runtime expression "' . $functionName . '" does not exist.', 1428694144);
        }
        return $this->runtimeExpressions[$functionName]->__invoke($joinPoint, $this->objectManager);
    }

Usage Example

 /**
  * Returns TRUE, if this privilege covers the given subject (join point)
  *
  * @param PrivilegeSubjectInterface $subject
  * @return boolean
  * @throws InvalidPrivilegeTypeException
  */
 public function matchesSubject(PrivilegeSubjectInterface $subject)
 {
     if ($subject instanceof MethodPrivilegeSubject === false) {
         throw new InvalidPrivilegeTypeException(sprintf('Privileges of type "%s" only support subjects of type "%s", but we got a subject of type: "%s".', MethodPrivilegeInterface::class, MethodPrivilegeSubject::class, get_class($subject)), 1416241148);
     }
     $this->initialize();
     $joinPoint = $subject->getJoinPoint();
     $methodIdentifier = strtolower($joinPoint->getClassName() . '->' . $joinPoint->getMethodName());
     if (isset(static::$methodPermissions[$methodIdentifier][$this->getCacheEntryIdentifier()])) {
         if (static::$methodPermissions[$methodIdentifier][$this->getCacheEntryIdentifier()]['hasRuntimeEvaluations']) {
             if ($this->runtimeExpressionEvaluator->evaluate($this->getCacheEntryIdentifier(), $joinPoint) === false) {
                 return false;
             }
         }
         return true;
     }
     return false;
 }