Phan\Language\Context::getNamespaceMapFor PHP Method

getNamespaceMapFor() public method

public getNamespaceMapFor ( integer $flags, string $name ) : FullyQualifiedGlobalStructuralElement
$flags integer
$name string
return Phan\Language\FQSEN\FullyQualifiedGlobalStructuralElement The namespace mapped name for the given flags and name
    public function getNamespaceMapFor(int $flags, string $name) : FullyQualifiedGlobalStructuralElement
    {
        $name = strtolower($name);
        // Look for the mapping on the part before a
        // slash
        $name_parts = explode('\\', $name, 2);
        $suffix = '';
        if (count($name_parts) > 1) {
            $name = $name_parts[0];
            $suffix = $name_parts[1];
        }
        assert(!empty($this->namespace_map[$flags][$name]), "No namespace defined for name");
        assert($this->namespace_map[$flags][$name] instanceof FQSEN, "Namespace map was not an FQSEN");
        $fqsen = $this->namespace_map[$flags][$name];
        if (!$suffix) {
            return $fqsen;
        }
        switch ($flags) {
            case \ast\flags\USE_NORMAL:
                return FullyQualifiedClassName::fromFullyQualifiedString((string) $fqsen . '\\' . $suffix);
            case \ast\flags\USE_FUNCTION:
                return FullyQualifiedFunctionName::fromFullyQualifiedString((string) $fqsen . '\\' . $suffix);
        }
        assert(false, "Unknown flag {$flags}");
        return $fqsen;
    }

Usage Example

Example #1
0
 /**
  * Visit a node with kind `\ast\AST_CALL`
  *
  * @param Node $node
  * A node of the type indicated by the method name that we'd
  * like to figure out the type that it produces.
  *
  * @return UnionType
  * The set of types that are possibly produced by the
  * given node
  */
 public function visitCall(Node $node) : UnionType
 {
     if ($node->children['expr']->kind !== \ast\AST_NAME) {
         // Things like `$func()`
         return new UnionType();
     }
     $function_name = $node->children['expr']->children['name'];
     $function_fqsen = null;
     // If its not fully qualified
     if ($node->children['expr']->flags & \ast\flags\NAME_NOT_FQ) {
         // Check to see if we have a mapped name
         if ($this->context->hasNamespaceMapFor(T_FUNCTION, $function_name)) {
             $function_fqsen = $this->context->getNamespaceMapFor(T_FUNCTION, $function_name);
         } else {
             $function_fqsen = FullyQualifiedFunctionName::fromStringInContext($function_name, $this->context);
         }
         // If the name is fully qualified
     } else {
         $function_fqsen = FullyQualifiedFunctionName::fromFullyQualifiedString($function_name);
     }
     // If the function doesn't exist, check to see if its
     // a call to a builtin method
     if (!$this->code_base->hasMethod($function_fqsen)) {
         $function_fqsen = FullyQualifiedFunctionName::make('', $function_name);
     }
     if (!$this->code_base->hasMethod($function_fqsen)) {
         // Missing internal (bulitin) method.
         return new UnionType();
     }
     $function = $this->code_base->getMethod($function_fqsen);
     // If this is an internal function, see if we can get
     // its types from the static dataset.
     if ($function->getContext()->isInternal() && $function->getUnionType()->isEmpty()) {
         $map = UnionType::internalFunctionSignatureMapForFQSEN($function_fqsen);
         return $map[$function_name] ?? new UnionType();
     }
     return $function->getUnionType();
 }
All Usage Examples Of Phan\Language\Context::getNamespaceMapFor