Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/lib/PhpParser/Builder/Use_.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 5fb285c0d0e3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace PhpParser\Builder; | |
4 | |
5 use PhpParser\BuilderAbstract; | |
6 use PhpParser\Node; | |
7 use PhpParser\Node\Stmt; | |
8 | |
9 /** | |
10 * @method $this as(string $alias) Sets alias for used name. | |
11 */ | |
12 class Use_ extends BuilderAbstract { | |
13 protected $name; | |
14 protected $type; | |
15 protected $alias = null; | |
16 | |
17 /** | |
18 * Creates a name use (alias) builder. | |
19 * | |
20 * @param Node\Name|string $name Name of the entity (namespace, class, function, constant) to alias | |
21 * @param int $type One of the Stmt\Use_::TYPE_* constants | |
22 */ | |
23 public function __construct($name, $type) { | |
24 $this->name = $this->normalizeName($name); | |
25 $this->type = $type; | |
26 } | |
27 | |
28 /** | |
29 * Sets alias for used name. | |
30 * | |
31 * @param string $alias Alias to use (last component of full name by default) | |
32 * | |
33 * @return $this The builder instance (for fluid interface) | |
34 */ | |
35 protected function as_($alias) { | |
36 $this->alias = $alias; | |
37 return $this; | |
38 } | |
39 public function __call($name, $args) { | |
40 if (method_exists($this, $name . '_')) { | |
41 return call_user_func_array(array($this, $name . '_'), $args); | |
42 } | |
43 | |
44 throw new \LogicException(sprintf('Method "%s" does not exist', $name)); | |
45 } | |
46 | |
47 /** | |
48 * Returns the built node. | |
49 * | |
50 * @return Node The built node | |
51 */ | |
52 public function getNode() { | |
53 $alias = null !== $this->alias ? $this->alias : $this->name->getLast(); | |
54 return new Stmt\Use_(array( | |
55 new Stmt\UseUse($this->name, $alias) | |
56 ), $this->type); | |
57 } | |
58 } |