Neos\ContentRepository\Eel\FlowQueryOperations\ContextOperation::evaluate PHP Метод

evaluate() публичный Метод

public evaluate ( FlowQuery $flowQuery, array $arguments ) : void
$flowQuery Neos\Eel\FlowQuery\FlowQuery The FlowQuery object
$arguments array The arguments for this operation
Результат void
    public function evaluate(FlowQuery $flowQuery, array $arguments)
    {
        if (!isset($arguments[0]) || !is_array($arguments[0])) {
            throw new FlowQueryException('context() requires an array argument of context properties', 1398030427);
        }
        $output = array();
        foreach ($flowQuery->getContext() as $contextNode) {
            $contextProperties = $contextNode->getContext()->getProperties();
            $modifiedContext = $this->contextFactory->create(array_merge($contextProperties, $arguments[0]));
            $nodeInModifiedContext = $modifiedContext->getNodeByIdentifier($contextNode->getIdentifier());
            if ($nodeInModifiedContext !== null) {
                $output[$nodeInModifiedContext->getPath()] = $nodeInModifiedContext;
            }
        }
        $flowQuery->setContext(array_values($output));
    }

Usage Example

 /**
  * @test
  */
 public function evaluateSkipsNodesNotAvailableInModifiedContext()
 {
     $suppliedContextProperties = array('infiniteImprobabilityDrive' => true);
     $nodeContextProperties = array('infiniteImprobabilityDrive' => false, 'autoRemoveUnsuitableContent' => true);
     $nodeIdentifier = 'c575c430-c971-11e3-a6e7-14109fd7a2dd';
     $mockNode = $this->createMock(NodeInterface::class);
     $mockNode->expects($this->any())->method('getIdentifier')->will($this->returnValue($nodeIdentifier));
     $mockFlowQuery = $this->buildFlowQueryWithNodeInContext($mockNode, $nodeContextProperties);
     $modifiedNodeContext = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
     $this->mockContextFactory->expects($this->any())->method('create')->will($this->returnValue($modifiedNodeContext));
     $modifiedNodeContext->expects($this->once())->method('getNodeByIdentifier')->with($nodeIdentifier)->will($this->returnValue(null));
     $mockFlowQuery->expects($this->atLeastOnce())->method('setContext')->with(array());
     $this->operation->evaluate($mockFlowQuery, array($suppliedContextProperties));
 }
ContextOperation