evaluate() public method

Evaluate an expression under a given context
public evaluate ( string $expression, Context $context ) : mixed
$expression string
$context Context
return mixed
 /**
  * This method walks through the view configuration and applies
  * matching configurations in the order of their specifity score.
  * Possible options are currently the viewObjectName to specify
  * a different class that will be used to create the view and
  * an array of options that will be set on the view object.
  *
  * @param ActionRequest $request
  * @return array
  */
 public function getViewConfiguration(ActionRequest $request)
 {
     $cacheIdentifier = $this->createCacheIdentifier($request);
     $viewConfiguration = $this->cache->get($cacheIdentifier);
     if ($viewConfiguration === false) {
         $configurations = $this->configurationManager->getConfiguration('Views');
         $requestMatcher = new RequestMatcher($request);
         $context = new Context($requestMatcher);
         $viewConfiguration = [];
         $highestWeight = -1;
         foreach ($configurations as $order => $configuration) {
             $requestMatcher->resetWeight();
             if (!isset($configuration['requestFilter'])) {
                 $weight = $order;
             } else {
                 $result = $this->eelEvaluator->evaluate($configuration['requestFilter'], $context);
                 if ($result === false) {
                     continue;
                 }
                 $weight = $requestMatcher->getWeight() + $order;
             }
             if ($weight > $highestWeight) {
                 $viewConfiguration = $configuration;
                 $highestWeight = $weight;
             }
         }
         $this->cache->set($cacheIdentifier, $viewConfiguration);
     }
     return $viewConfiguration;
 }
 /**
  * @param PrivilegeSubjectInterface $subject
  * @return boolean
  * @throws InvalidPrivilegeTypeException
  */
 public function matchesSubject(PrivilegeSubjectInterface $subject)
 {
     if (!$subject instanceof NodePrivilegeSubject) {
         throw new InvalidPrivilegeTypeException(sprintf('Privileges of type "%s" only support subjects of type "%s", but we got a subject of type: "%s".', static::class, NodePrivilegeSubject::class, get_class($subject)), 1465979693);
     }
     $nodeContext = new NodePrivilegeContext($subject->getNode());
     $eelContext = new Context($nodeContext);
     $eelCompilingEvaluator = new CompilingEvaluator();
     $eelCompilingEvaluator->evaluate($this->getParsedMatcher(), $eelContext);
     return $eelCompilingEvaluator->evaluate($this->getParsedMatcher(), $eelContext);
 }
 /**
  * @test
  */
 public function loopedExpressions()
 {
     $this->markTestSkipped('Enable for benchmark');
     $evaluator = new CompilingEvaluator();
     $expression = 'foo.bar=="Test"||foo.baz=="Test"||reverse(foo).bar=="Test"';
     $context = new Context(['foo' => ['bar' => 'Test1', 'baz' => 'Test2'], 'reverse' => function ($array) {
         return array_reverse($array, true);
     }]);
     for ($i = 0; $i < 10000; $i++) {
         $evaluator->evaluate($expression, $context);
     }
 }
 /**
  * @param PrivilegeSubjectInterface|NodePrivilegeSubject|MethodPrivilegeSubject $subject (one of NodePrivilegeSubject or MethodPrivilegeSubject)
  * @return boolean
  * @throws InvalidPrivilegeTypeException
  */
 public function matchesSubject(PrivilegeSubjectInterface $subject)
 {
     if ($subject instanceof NodePrivilegeSubject === 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".', AbstractNodePrivilege::class, NodePrivilegeSubject::class, MethodPrivilegeSubject::class, get_class($subject)), 1417014368);
     }
     $this->initialize();
     if ($subject instanceof MethodPrivilegeSubject) {
         return $this->methodPrivilege->matchesSubject($subject);
     }
     $nodeContext = new $this->nodeContextClassName($subject->getNode());
     $eelContext = new Context($nodeContext);
     return $this->eelCompilingEvaluator->evaluate($this->getParsedMatcher(), $eelContext);
 }
 /**
  * @test
  */
 public function methodCallToNullValueDoesNotThrowNotAllowedException()
 {
     $context = new ProtectedContext([]);
     $evaluator = new CompilingEvaluator();
     $result = $evaluator->evaluate('unknown.someMethod()', $context);
     $this->assertEquals(null, $result);
 }