2011-06-05 18:40:04 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser\Node\Stmt;
|
|
|
|
|
|
|
|
use PhpParser\Node;
|
|
|
|
use PhpParser\Error;
|
|
|
|
|
|
|
|
class UseUse extends Node\Stmt
|
2011-06-05 18:40:04 +02:00
|
|
|
{
|
2015-02-28 18:44:28 +01:00
|
|
|
/** @var Node\Name Namespace, class, function or constant to alias */
|
|
|
|
public $name;
|
|
|
|
/** @var string Alias */
|
|
|
|
public $alias;
|
|
|
|
|
2011-10-15 19:28:15 +02:00
|
|
|
/**
|
|
|
|
* Constructs an alias (use) node.
|
|
|
|
*
|
2014-02-06 14:44:16 +01:00
|
|
|
* @param Node\Name $name Namespace/Class to alias
|
|
|
|
* @param null|string $alias Alias
|
|
|
|
* @param array $attributes Additional attributes
|
2011-10-15 19:28:15 +02:00
|
|
|
*/
|
2014-02-06 14:44:16 +01:00
|
|
|
public function __construct(Node\Name $name, $alias = null, array $attributes = array()) {
|
2011-10-15 19:28:15 +02:00
|
|
|
if (null === $alias) {
|
|
|
|
$alias = $name->getLast();
|
2011-08-04 12:58:12 +02:00
|
|
|
}
|
|
|
|
|
2015-04-26 23:13:08 +02:00
|
|
|
if ('self' == strtolower($alias) || 'parent' == strtolower($alias)) {
|
2014-02-06 14:44:16 +01:00
|
|
|
throw new Error(sprintf(
|
2014-01-23 13:33:02 +01:00
|
|
|
'Cannot use %s as %s because \'%2$s\' is a special class name',
|
2011-10-15 19:28:15 +02:00
|
|
|
$name, $alias
|
2011-08-04 12:58:12 +02:00
|
|
|
));
|
|
|
|
}
|
2011-10-15 19:28:15 +02:00
|
|
|
|
2015-05-02 22:17:34 +02:00
|
|
|
parent::__construct($attributes);
|
2015-02-28 18:44:28 +01:00
|
|
|
$this->name = $name;
|
|
|
|
$this->alias = $alias;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSubNodeNames() {
|
|
|
|
return array('name', 'alias');
|
2011-08-04 12:58:12 +02:00
|
|
|
}
|
2014-01-23 13:33:02 +01:00
|
|
|
}
|