getFirst() public method

Gets the first part of the name, i.e. everything before the first namespace separator.
public getFirst ( ) : string
return string First part of the name
Exemplo n.º 1
0
 public function getFQCN(Name $node = null)
 {
     if ($node === null) {
         return $node;
     }
     if ($node->isFullyQualified()) {
         return $this->parseFQCN($node->toString());
     }
     $fqcn = $this->uses->find($node->getFirst());
     if ($fqcn) {
         return $fqcn;
     }
     return $this->createFQCN($node->toString());
 }
Exemplo n.º 2
0
 protected function resolveOtherName(Name $name, $type)
 {
     // fully qualified names are already resolved
     if ($name->isFullyQualified()) {
         return $name;
     }
     // resolve aliases for qualified names
     $aliasName = strtolower($name->getFirst());
     if ($name->isQualified() && isset($this->aliases[Stmt\Use_::TYPE_NORMAL][$aliasName])) {
         $name->setFirst($this->aliases[Stmt\Use_::TYPE_NORMAL][$aliasName]);
     } elseif ($name->isUnqualified()) {
         if ($type === Stmt\Use_::TYPE_CONSTANT) {
             // constant aliases are case-sensitive, function aliases case-insensitive
             $aliasName = $name->getFirst();
         }
         if (isset($this->aliases[$type][$aliasName])) {
             // resolve unqualified aliases
             $name->set($this->aliases[$type][$aliasName]);
         } else {
             // unqualified, unaliased names cannot be resolved at compile-time
             return $name;
         }
     } elseif (null !== $this->namespace) {
         // if no alias exists prepend current namespace
         $name->prepend($this->namespace);
     }
     return new Name\FullyQualified($name->parts, $name->getAttributes());
 }
Exemplo n.º 3
0
 protected function resolveOtherName(Name $name, $type)
 {
     // fully qualified names are already resolved
     if ($name->isFullyQualified()) {
         return $name;
     }
     // resolve aliases for qualified names
     $aliasName = strtolower($name->getFirst());
     if ($name->isQualified() && isset($this->aliases[Stmt\Use_::TYPE_NORMAL][$aliasName])) {
         $alias = $this->aliases[Stmt\Use_::TYPE_NORMAL][$aliasName];
         return FullyQualified::concat($alias, $name->slice(1), $name->getAttributes());
     }
     if ($name->isUnqualified()) {
         if ($type === Stmt\Use_::TYPE_CONSTANT) {
             // constant aliases are case-sensitive, function aliases case-insensitive
             $aliasName = $name->getFirst();
         }
         if (isset($this->aliases[$type][$aliasName])) {
             // resolve unqualified aliases
             return new FullyQualified($this->aliases[$type][$aliasName], $name->getAttributes());
         }
         if (null === $this->namespace) {
             // outside of a namespace unaliased unqualified is same as fully qualified
             return new FullyQualified($name, $name->getAttributes());
         }
         // unqualified names inside a namespace cannot be resolved at compile-time
         // add the namespaced version of the name as an attribute
         $name->setAttribute('namespacedName', FullyQualified::concat($this->namespace, $name, $name->getAttributes()));
         return $name;
     }
     // if no alias exists prepend current namespace
     return FullyQualified::concat($this->namespace, $name, $name->getAttributes());
 }