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

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

public evaluate ( FlowQuery $flowQuery, array $arguments ) : void
$flowQuery Neos\Eel\FlowQuery\FlowQuery the FlowQuery object
$arguments array the filter expression to use (in index 0)
Результат void
    public function evaluate(FlowQuery $flowQuery, array $arguments)
    {
        if (!isset($arguments[0]) || empty($arguments[0])) {
            return;
        }
        if (!is_string($arguments[0])) {
            throw new FizzleException('filter operation expects string argument', 1332489625);
        }
        $filter = $arguments[0];
        $parsedFilter = FizzleParser::parseFilterGroup($filter);
        $filteredContext = [];
        $context = $flowQuery->getContext();
        foreach ($context as $element) {
            if ($this->matchesFilterGroup($element, $parsedFilter)) {
                $filteredContext[] = $element;
            }
        }
        $flowQuery->setContext($filteredContext);
    }

Usage Example

 /**
  * {@inheritdoc}
  *
  * @param FlowQuery $flowQuery
  * @param array $arguments
  * @return void
  */
 public function evaluate(FlowQuery $flowQuery, array $arguments)
 {
     if (!isset($arguments[0]) || empty($arguments[0])) {
         return;
     }
     if ($arguments[0] instanceof NodeInterface) {
         $filteredContext = array();
         $context = $flowQuery->getContext();
         foreach ($context as $element) {
             if ($element === $arguments[0]) {
                 $filteredContext[] = $element;
                 break;
             }
         }
         $flowQuery->setContext($filteredContext);
     } else {
         parent::evaluate($flowQuery, $arguments);
     }
 }