/** * {@inheritdoc} */ public function rewrite(FunctionCallNode $call, TargetInterface $target) { $arguments = $call->getArguments(); if ($arguments[0] instanceof StringNode) { $path = $arguments[0]->toValue(); // If the URL has a scheme (e.g., http://), it's external. if (parse_url($path, PHP_URL_SCHEME)) { return ClassMethodCallNode::create('\\Drupal\\Core\\Url', 'fromUri')->appendArgument(clone $arguments[0]); } elseif ($this->routeExists($path)) { $route = $this->routeProvider->getRoutesByPattern('/' . $path)->getIterator()->key(); return ClassMethodCallNode::create('\\Drupal\\Core\\Url', 'fromRoute')->appendArgument(StringNode::fromValue($route)); } } }
public function testPrependArgument() { /** @var \Pharborist\Functions\FunctionCallNode $call */ $call = Parser::parseExpression('foo()'); $call->prependArgument('wozwoz'); $arguments = $call->getArguments(); $this->assertCount(1, $arguments); $this->assertInstanceOf('\\Pharborist\\Types\\StringNode', $arguments[0]); $bazbaz = StringNode::fromValue('bazbaz'); $call->prependArgument($bazbaz); $arguments = $call->getArguments(); $this->assertCount(2, $arguments); $this->assertSame($bazbaz, $arguments[0]); }
/** * {@inheritdoc} */ public function rewrite(FunctionCallNode $call, TargetInterface $target) { $arguments = $call->getArguments()->toArray(); return ClassMethodCallNode::create('\\Drupal', 'service')->appendArgument(StringNode::fromValue('theme.registry'))->appendMethodCall($arguments && $arguments[0] instanceof FalseNode ? 'getRuntime' : 'get'); }
public function testAddTo() { $c1 = new NodeCollection([StringNode::fromValue('foo')]); $c2 = new NodeCollection([IntegerNode::fromValue(30)]); $union = $c1->addTo($c2); $this->assertCount(2, $union); $this->assertSame($union, $c2); }
/** * {@inheritdoc} */ public function rewrite(FunctionCallNode $call, TargetInterface $target) { return StringNode::fromValue('t'); }
public function testGetValueNoArgument() { $this->parameter->setValue(StringNode::fromValue('har')); $path = new PathUtility('foo/%node'); $binding = new ParameterBinding($path, $this->parameter); $this->assertEquals('har', $binding->getValue()); }