2017-08-18 22:57:27 +02:00
|
|
|
<?php declare(strict_types=1);
|
2011-06-05 18:40:04 +02:00
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser\Node\Stmt;
|
|
|
|
|
|
|
|
use PhpParser\Node;
|
2017-04-28 19:09:39 +02:00
|
|
|
use PhpParser\Node\Identifier;
|
2014-02-06 14:44:16 +01:00
|
|
|
|
|
|
|
class UseUse extends Node\Stmt
|
2011-06-05 18:40:04 +02:00
|
|
|
{
|
2015-06-13 11:27:38 +02:00
|
|
|
/** @var int One of the Stmt\Use_::TYPE_* constants. Will only differ from TYPE_UNKNOWN for mixed group uses */
|
|
|
|
public $type;
|
2015-02-28 18:44:28 +01:00
|
|
|
/** @var Node\Name Namespace, class, function or constant to alias */
|
|
|
|
public $name;
|
2017-04-28 21:05:01 +02:00
|
|
|
/** @var Identifier|null Alias */
|
2015-02-28 18:44:28 +01:00
|
|
|
public $alias;
|
|
|
|
|
2011-10-15 19:28:15 +02:00
|
|
|
/**
|
|
|
|
* Constructs an alias (use) node.
|
|
|
|
*
|
2017-04-28 19:09:39 +02:00
|
|
|
* @param Node\Name $name Namespace/Class to alias
|
|
|
|
* @param null|string|Identifier $alias Alias
|
|
|
|
* @param int $type Type of the use element (for mixed group use only)
|
|
|
|
* @param array $attributes Additional attributes
|
2011-10-15 19:28:15 +02:00
|
|
|
*/
|
2017-08-13 14:06:08 +02:00
|
|
|
public function __construct(Node\Name $name, $alias = null, int $type = Use_::TYPE_UNKNOWN, array $attributes = []) {
|
2015-05-02 22:17:34 +02:00
|
|
|
parent::__construct($attributes);
|
2015-06-13 11:27:38 +02:00
|
|
|
$this->type = $type;
|
2015-02-28 18:44:28 +01:00
|
|
|
$this->name = $name;
|
2017-04-28 19:09:39 +02:00
|
|
|
$this->alias = \is_string($alias) ? new Identifier($alias) : $alias;
|
2015-02-28 18:44:28 +01:00
|
|
|
}
|
|
|
|
|
2017-04-28 21:40:59 +02:00
|
|
|
public function getSubNodeNames() : array {
|
2017-08-13 14:06:08 +02:00
|
|
|
return ['type', 'name', 'alias'];
|
2011-08-04 12:58:12 +02:00
|
|
|
}
|
2017-04-28 21:05:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get alias. If not explicitly given this is the last component of the used name.
|
|
|
|
*
|
|
|
|
* @return Identifier
|
|
|
|
*/
|
2017-04-28 21:40:59 +02:00
|
|
|
public function getAlias() : Identifier {
|
2017-04-28 21:05:01 +02:00
|
|
|
if (null !== $this->alias) {
|
|
|
|
return $this->alias;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Identifier($this->name->getLast());
|
|
|
|
}
|
2014-01-23 13:33:02 +01:00
|
|
|
}
|