public function testCreate() { $member = ClassMemberNode::create('lancelot'); $this->assertInstanceOf('\\Pharborist\\Objects\\ClassMemberListNode', $member); $this->assertEquals('public $lancelot;', $member->getText()); $member = ClassMemberNode::create('robin', StringNode::create("'cowardly'"), 'protected'); $this->assertInstanceOf('\\Pharborist\\Objects\\ClassMemberListNode', $member); $this->assertEquals('protected $robin = \'cowardly\';', $member->getText()); }
/** * {@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]); }
public function testGetValue() { $string = StringNode::create('\'Goodbye, cruel world!\''); $this->assertEquals('Goodbye, cruel world!', $string->toValue()); $string = StringNode::create('"I\'ll harrr to that!"'); $this->assertEquals("I'll harrr to that!", $string->toValue()); // Test escaped characters in double quoted string. $string = <<<'EOF' "h\145llo\\n\nw\x6Frld" EOF; $this->assertEquals("hello\\n\nworld", StringNode::create($string)->toValue()); // Test escaped characters in single quoted string. $string = <<<'EOF' 'it\'s \a\\\'live' EOF; $this->assertEquals("it's \\a\\'live", StringNode::create($string)->toValue()); }
/** * {@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'); }
/** * Sets the test's $profile property. * * @param \Pharborist\Objects\ClassNode $test */ private function setProfile(ClassNode $test) { if (!$test->hasProperty('profile')) { $test->appendProperty(ClassMemberNode::create('profile', StringNode::create("'standard'"), 'protected')); } }
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()); }
/** * Creates a Node from a php value. * * @param string|integer|float|boolean|array|null $value * The value to create a node for. * * @return FloatNode|IntegerNode|StringNode|BooleanNode|NullNode|ArrayNode * * @throws \InvalidArgumentException if $value is not a scalar. */ public static function fromValue($value) { if (is_array($value)) { $elements = []; foreach ($value as $k => $v) { $elements[] = ArrayPairNode::create(static::fromValue($k), static::fromValue($v)); } return ArrayNode::create($elements); } elseif (is_string($value)) { return StringNode::create(var_export($value, TRUE)); } elseif (is_integer($value)) { return new IntegerNode(T_LNUMBER, $value); } elseif (is_float($value)) { return new FloatNode(T_DNUMBER, $value); } elseif (is_bool($value)) { return BooleanNode::create($value); } elseif (is_null($value)) { return NullNode::create('NULL'); } else { throw new \InvalidArgumentException(); } }