Neos\Eel\FlowQuery\Operations\SliceOperation::evaluate PHP Method

evaluate() public method

public evaluate ( FlowQuery $flowQuery, array $arguments ) : void
$flowQuery Neos\Eel\FlowQuery\FlowQuery the FlowQuery object
$arguments array A mandatory start and optional end index in the context, negative indices indicate an offset from the start or end respectively
return void
    public function evaluate(FlowQuery $flowQuery, array $arguments)
    {
        $context = $flowQuery->getContext();
        if ($context instanceof \Iterator) {
            $context = iterator_to_array($context);
        }
        if (isset($arguments[0]) && isset($arguments[1])) {
            $context = array_slice($context, (int) $arguments[0], (int) $arguments[1] - (int) $arguments[0]);
        } elseif (isset($arguments[0])) {
            $context = array_slice($context, (int) $arguments[0]);
        }
        $flowQuery->setContext($context);
    }

Usage Example

 /**
  * @test
  * @dataProvider sliceExamples
  */
 public function evaluateSetsTheCorrectPartOfTheContextArray($value, $arguments, $expected)
 {
     $flowQuery = new \Neos\Eel\FlowQuery\FlowQuery($value);
     $operation = new SliceOperation();
     $operation->evaluate($flowQuery, $arguments);
     $this->assertEquals($expected, $flowQuery->getContext());
 }
SliceOperation