NamespaceImportResolver
in package
Namespace import resolver class
Tracks which short class names have already been claimed by a use-import within one
*Reflection::parse() call, and decides -- for each new fully-qualified class name a parent
class, interface, or attribute needs to reference -- whether it can be imported (and rendered
by its bare short name) or must be referenced by its fully-qualified name instead, because
another class with the same short name from a different namespace already claimed it. Two
use statements for different classes sharing one short name is a PHP fatal error ("Cannot use
X as Y because the name is already in use"), so the second one must fall back to its FQCN
instead of colliding.
One instance is meant to live for the duration of a single *Reflection::parse() call, shared across every parent/interface/attribute reference that call detects, so a collision between (for example) the parent class's short name and an attribute's short name is caught too, not just collisions among attributes alone.
Tags
Table of Contents
Properties
- $claimed : array<string|int, mixed>
- Short names already claimed by this resolver, each mapped to the FQCN that claimed it
Methods
- resolve() : array<string|int, mixed>
- Resolve a fully-qualified class name into [reference, needsImport]
Properties
$claimed
Short names already claimed by this resolver, each mapped to the FQCN that claimed it
protected
array<string|int, mixed>
$claimed
= []
Methods
resolve()
Resolve a fully-qualified class name into [reference, needsImport]
public
resolve(string $fqcn, string $ownNamespace) : array<string|int, mixed>
$reference is what should be rendered in place of the class name (a bare short name, or
a fully-qualified name with a leading backslash). $needsImport is whether the caller
should add a use $fqcn; import for it.
Parameters
- $fqcn : string
- $ownNamespace : string
-
the namespace of the construct being reflected