/**
  * Constructs an alias (use) node.
  *
  * @param PHPParser_Node_Name $name       Namespace/Class to alias
  * @param null|string         $alias      Alias
  * @param array               $attributes Additional attributes
  */
 public function __construct(PHPParser_Node_Name $name, $alias = null, array $attributes = array())
 {
     if (null === $alias) {
         $alias = $name->getLast();
     }
     if ('self' == $alias || 'parent' == $alias) {
         throw new PHPParser_Error(sprintf('Cannot use "%s" as "%s" because "%2$s" is a special class name', $name, $alias));
     }
     parent::__construct(array('name' => $name, 'alias' => $alias), $attributes);
 }
 protected function resolveOtherName(PHPParser_Node_Name $name)
 {
     // fully qualified names are already resolved and we can't do anything about unqualified
     // ones at compiler-time
     if ($name->isFullyQualified() || $name->isUnqualified()) {
         return $name;
     }
     // resolve aliases for qualified names
     if ($name->isQualified() && isset($this->aliases[$name->getFirst()])) {
         $name->setFirst($this->aliases[$name->getFirst()]);
         // prepend namespace for relative names
     } elseif (null !== $this->namespace) {
         $name->prepend($this->namespace);
     }
     return new PHPParser_Node_Name_FullyQualified($name->parts, $name->getAttributes());
 }
Beispiel #3
0
 /**
  * @expectedException        InvalidArgumentException
  * @expectedExceptionMessage When changing a name you need to pass either a string, an array or a Name node
  */
 public function testInvalidArg()
 {
     $name = new PHPParser_Node_Name('foo');
     $name->set(new stdClass());
 }
Beispiel #4
0
    protected function rewriteStaticOtherLookup(PHPParser_Node_Name &$name, $type) {
        // leave the fully qualified ones alone
        if (!$name->isFullyQualified()) {
            // resolve aliases for qualified names
            if ($name->isQualified() && isset($this->aliases[$name->getFirst()])) {
                $name->setFirst($this->aliases[$name->getFirst()]);
            // prepend current namespace for qualified and relative names (and unqualified ones if
            // the function/constant is not an internal one defined globally. This isn't exactly
            // PHP's behavior, but proper resolution would require runtime code insertion.)
            } elseif (null !== $this->namespace
                      && (!$name->isUnqualified() || !isset($this->internals[$type][strtolower($name)]))
            ) {
                $name->prepend($this->namespace);
            }
        }

        // finally just replace the namespace separators with underscores
        $name->set($name->toString('__'));
        $name->type = PHPParser_Node_Name::NORMAL;
    }