3 namespace PhpParser\Builder;
5 use PhpParser\BuilderAbstract;
7 use PhpParser\Node\Stmt;
10 * @method $this as(string $alias) Sets alias for used name.
12 class Use_ extends BuilderAbstract {
15 protected $alias = null;
18 * Creates a name use (alias) builder.
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
23 public function __construct($name, $type) {
24 $this->name = $this->normalizeName($name);
29 * Sets alias for used name.
31 * @param string $alias Alias to use (last component of full name by default)
33 * @return $this The builder instance (for fluid interface)
35 protected function as_($alias) {
36 $this->alias = $alias;
39 public function __call($name, $args) {
40 if (method_exists($this, $name . '_')) {
41 return call_user_func_array(array($this, $name . '_'), $args);
44 throw new \LogicException(sprintf('Method "%s" does not exist', $name));
48 * Returns the built node.
50 * @return Node The built node
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)