Neos\Eel\FlowQuery\Operations\AddOperation::evaluate PHP Метод

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

public evaluate ( FlowQuery $flowQuery, array $arguments ) : void
$flowQuery Neos\Eel\FlowQuery\FlowQuery the FlowQuery object
$arguments array the elements to add (as array in index 0)
Результат void
    public function evaluate(FlowQuery $flowQuery, array $arguments)
    {
        $output = [];
        foreach ($flowQuery->getContext() as $element) {
            $output[] = $element;
        }
        if (isset($arguments[0])) {
            if (is_array($arguments[0]) || $arguments[0] instanceof \Traversable) {
                foreach ($arguments[0] as $element) {
                    $output[] = $element;
                }
            } else {
                $output[] = $arguments[0];
            }
        }
        $flowQuery->setContext($output);
    }

Usage Example

 /**
  * This corresponds to ${q(node).add([someOtherNode, ...]))}
  *
  * @test
  */
 public function addWithArrayArgumentAppendsToCurrentContext()
 {
     $object1 = new \stdClass();
     $object2 = new \stdClass();
     $flowQuery = new FlowQuery([$object1]);
     $arrayArgument = [$object2];
     $arguments = [$arrayArgument];
     $operation = new AddOperation();
     $operation->evaluate($flowQuery, $arguments);
     $this->assertSame([$object1, $object2], $flowQuery->getContext());
 }
AddOperation