/** * 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); }
/** * Get the URL from a node * * @param Node $node * @return string */ protected function getUrl($node) { $url = $node->getInstruction($this); $type = (is_object($url) ? get_class($url) . ' ' : '') . gettype($url); if (!assert(is_string($url), "Expected '{$this->property}' to be a string, but got a {$type}")) { return null; } return $url; }
public function testGetIntructionDeepReferenceTwice() { $refNode2 = $this->createMock(Node::class); $refNode2->expects($this->atLeastOnce())->method('getResult')->willReturn('foo'); $refNode1 = $this->createMock(Node::class); $refNode1->expects($this->atLeastOnce())->method('getResult')->willReturn(['cool' => $refNode2]); $node = new Node((object) ['<process>' => (object) ['value' => $refNode1]]); $instruction = $node->getInstruction($this->processor); $this->assertEquals((object) ['value' => ['cool' => 'foo']], $instruction); }
/** * Apply processing to a single node * * @param Node $node */ public function applyToNode(Node $node) { $instruction = $node->getInstruction($this); $list = $this->resolve($instruction); if (isset($list) && !is_array($list)) { throw new \Exception("Unable to apply {$this->property} processing instruction:" . " Expected an array, got a " . (is_object($list) ? get_class($list) . ' ' : '') . gettype($list)); } $result = $this->merge((array) $list); $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); }
/** * Apply processing to a single node * * @param Node $node */ public function applyToNode(Node $node) { $transformations = (array) $node->getInstruction($this); if (!isset($node->input)) { return; } $value = $node->input; if ($value instanceof Node) { $value = $value->getResult(); } foreach ($transformations as $transformation) { list($key, $arg) = explode(':', $transformation) + [null]; if (!isset($this->functions[$key])) { trigger_error("Unknown transformation '{$transformation}'", E_USER_WARNING); continue; } $fn = $this->functions[$key]; $value = isset($arg) ? call_user_func($fn, $arg, $value) : call_user_func($fn, $value); } $node->setResult($value); }
/** * Apply reference processing to a single node * * @param Node $node */ public function applyToNode(Node $node) { $ref = $node->getInstruction($this); $result = $this->getByReference($ref, $this->source, $this->target); $node->setResult($result); }
/** * Apply processing to a single node * * @param Node $node */ public function applyToNode(Node $node) { $template = $node->getInstruction($this); $result = $this->parse($template); $node->setResult($result); }