Type Resolver

Context
in package

FinalYes

Provides information about the Context in which the DocBlock occurs that receives this context.

A DocBlock does not know of its own accord in which namespace it occurs and which namespace aliases are applicable for the block of code in which it is in. This information is however necessary to resolve Class names in tags since you can provide a short form or make use of namespace aliases.

The phpDocumentor Reflection component knows how to create this class but if you use the DocBlock parser from your own application it is possible to generate a Context class using the ContextFactory; this will analyze the file in which an associated class resides for its namespace and imports.

Tags
see
ContextFactory::createFromClassReflector()
see
ContextFactory::createForNamespace()
psalm-immutable

Table of Contents

Properties

$namespace  : string
$namespaceAliases  : array<string|int, string>

Methods

__construct()  : mixed
Initializes the new context and normalizes all passed namespaces to be in Qualified Namespace Name (QNN) format (without a preceding `\`).
getNamespace()  : string
Returns the Qualified Namespace Name (thus without `\` in front) where the associated element is in.
getNamespaceAliases()  : array<string|int, string>
Returns a list of Qualified Namespace Names (thus without `\` in front) that are imported, the keys represent the alias for the imported Namespace.

Properties

$namespace

private string $namespace

The current namespace.

$namespaceAliases

private array<string|int, string> $namespaceAliases

List of namespace aliases => Fully Qualified Namespace.

Tags
psalm-var

array<string, string>

Methods

__construct()

Initializes the new context and normalizes all passed namespaces to be in Qualified Namespace Name (QNN) format (without a preceding `\`).

public __construct(string $namespace[, array<string|int, string> $namespaceAliases = [] ]) : mixed
Parameters
$namespace : string

The namespace where this DocBlock resides in.

$namespaceAliases : array<string|int, string> = []

List of namespace aliases => Fully Qualified Namespace.

Tags
psalm-param

array<string, string> $namespaceAliases

getNamespace()

Returns the Qualified Namespace Name (thus without `\` in front) where the associated element is in.

public getNamespace() : string
Tags
used-by
TypeResolver::resolve()

to determine with what to prefix the type name.

Return values
string

getNamespaceAliases()

Returns a list of Qualified Namespace Names (thus without `\` in front) that are imported, the keys represent the alias for the imported Namespace.

public getNamespaceAliases() : array<string|int, string>
Tags
psalm-return

array<string, string>

used-by
TypeResolver::resolve()

to check whether the first part of the relative type name should not be replaced with another namespace.

Return values
array<string|int, string>

        
On this page

Search results