Ejemplo n.º 1
0
 public function testIs()
 {
     $name = new PHPParser_Node_Name('foo');
     $this->assertTrue($name->isUnqualified());
     $this->assertFalse($name->isQualified());
     $this->assertFalse($name->isFullyQualified());
     $this->assertFalse($name->isRelative());
     $name = new PHPParser_Node_Name('foo\\bar');
     $this->assertFalse($name->isUnqualified());
     $this->assertTrue($name->isQualified());
     $this->assertFalse($name->isFullyQualified());
     $this->assertFalse($name->isRelative());
     $name = new PHPParser_Node_Name_FullyQualified('foo');
     $this->assertFalse($name->isUnqualified());
     $this->assertFalse($name->isQualified());
     $this->assertTrue($name->isFullyQualified());
     $this->assertFalse($name->isRelative());
     $name = new PHPParser_Node_Name_Relative('foo');
     $this->assertFalse($name->isUnqualified());
     $this->assertFalse($name->isQualified());
     $this->assertFalse($name->isFullyQualified());
     $this->assertTrue($name->isRelative());
 }
 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());
 }
Ejemplo n.º 3
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;
    }