/** * Apply processing to a single node * * @param Node $node */ public function applyToNode(Node $node) { $ref = $node->getInstruction($this); $cases = $node->getResult(); $result = $this->choose($ref, $cases); $node->setResult($result); }
/** * Apply processing to a single node * * @param Node $node */ public function applyToNode(Node $node) { $instruction = $node->getInstruction($this); $source = $node->getResult() ?: []; if (is_string($instruction->match)) { $match = ['extra' => $instruction->match, 'source' => $instruction->match]; } else { $match = (array) $instruction->match; } $extraIndexed = []; foreach ($instruction->extra as $extra) { $key = \Jasny\DotKey::on($extra)->get($match['extra']); if (!isset($key) || isset($extraIndexed[$key])) { continue; } if (!is_scalar($key)) { trigger_error("Trying to match on non-scalar type", E_WARNING); continue; } $extraIndexed[$key] = $extra; } foreach ($source as &$item) { $key = \Jasny\DotKey::on($item)->get($match['source']); if (!isset($key) || !isset($extraIndexed[$key])) { continue; } if (!is_scalar($key)) { trigger_error("Trying to match on non-scalar type", E_WARNING); continue; } $item = array_merge((array) $item, (array) $extraIndexed[$key]); } $node->setResult($source); }
/** * Apply processing to a single node * * @param Node $node */ public function applyToNode(Node $node) { $path = $node->getInstruction($this); $input = $node->getResult(); $result = jmespath_search($path, $input); static::objectivy($result); $node->setResult($result); }
/** * Apply processing to a single node * * @param Node $node */ public function applyToNode(Node $node) { $ref = $node->getInstruction($this); $check = $this->getByReference($ref, $this->source, $this->target); if (!isset($check)) { $node->setResult(null); foreach ($node as $prop => $value) { unset($node->{$prop}); // Remove all other properties, including processing instructions } } else { $result = $node->getResult(); unset($result->{$this->property}); $node->setResult($result); } }
/** * Apply processing to a single node * * @param Node $node */ public function applyToNode(Node $node) { $expression = $node->getInstruction($this); $ast = $this->getParser()->parse($expression); $variables = $node->getResult() ?: []; $arithmetic = new Hoa\Math\Visitor\Arithmetic(); foreach ($variables as $name => $value) { // Constants are upper case and variables lower case. We don't really care, so using a workaround. if (preg_match('/^[A-Z_][A-Z0-9_]*$/', $name)) { $arithmetic->addConstant($name, $value); } else { $arithmetic->addVariable($name, function () use($value) { return $value; }); } } $result = $arithmetic->visit($ast); $node->setResult($result); }