/** * 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); }
/** * Evaluate an Eel expression * * @param string $expression The Eel expression to evaluate * @param \Neos\Fusion\TypoScriptObjects\AbstractTypoScriptObject $contextObject An optional object for the "this" value inside the context * @return mixed The result of the evaluated Eel expression * @throws Exception */ protected function evaluateEelExpression($expression, AbstractTypoScriptObject $contextObject = null) { if ($expression[0] !== '$' || $expression[1] !== '{') { // We still assume this is an EEL expression and wrap the markers for backwards compatibility. $expression = '${' . $expression . '}'; } $contextVariables = array_merge($this->getDefaultContextVariables(), $this->getCurrentContext()); if (isset($contextVariables['this'])) { throw new Exception('Context variable "this" not allowed, as it is already reserved for a pointer to the current TypoScript object.', 1344325044); } $contextVariables['this'] = $contextObject; if ($this->eelEvaluator instanceof \Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy) { $this->eelEvaluator->_activateDependency(); } return EelUtility::evaluateEelExpression($expression, $this->eelEvaluator, $contextVariables); }
/** * @test */ public function methodCallToNullValueDoesNotThrowNotAllowedException() { $context = new ProtectedContext([]); $evaluator = new CompilingEvaluator(); $result = $evaluator->evaluate('unknown.someMethod()', $context); $this->assertEquals(null, $result); }