final class PhpNamespace

Represents a PHP namespace with use statements and contained class-like types and functions.

Constants

NameNormal

NameFunction

NameConstant

NAME_NORMAL

NAME_FUNCTION

NAME_CONSTANT

Methods

__construct(string $name)

No description

string
getName()

No description

setBracketedSyntax(bool $state = true)

No description

bool
hasBracketedSyntax()

No description

addUse(string $name, string|null $alias = null, string $of = self::NameNormal)

Adds a use statement for a class, function, or constant.

void
removeUse(string $name, string $of = self::NameNormal)

Removes a use statement.

addUseFunction(string $name, string|null $alias = null)

Adds a use statement for a function.

addUseConstant(string $name, string|null $alias = null)

Adds a use statement for a constant.

array
getUses(string $of = self::NameNormal)

Returns use statements, sorted alphabetically and excluding redundant aliases within the same namespace.

string
resolveName(string $name, string $of = self::NameNormal)

Resolves a relative or aliased name to its fully qualified form.

string
simplifyType(string $type, string $of = self::NameNormal)

Simplifies all class/function/constant names in a type string using current use statements.

string
simplifyName(string $name, string $of = self::NameNormal)

Simplifies a fully qualified name to the shortest possible form using current use statements.

add(GlobalFunction $item)

Adds a class-like type or function to the namespace.

addClass(string $name)

Adds a class to the namespace.

addInterface(string $name)

Adds an interface to the namespace.

addTrait(string $name)

Adds a trait to the namespace.

addEnum(string $name)

Adds an enum to the namespace.

EnumType
getClass(string $name)

Returns a class-like type by name.

array
getClasses()

No description

removeClass(string $name)

Removes a class-like type from the namespace.

addFunction(string $name)

Adds a function to the namespace.

getFunction(string $name)

Returns a function by name.

array
getFunctions()

No description

removeFunction(string $name)

Removes a function from the namespace.

string
__toString()

No description

Details

at line 52
__construct(string $name)

No description

Parameters

string $name

at line 62
string getName()

No description

Return Value

string

at line 71
PhpNamespace setBracketedSyntax(bool $state = true)

internal  
 

No description

Parameters

bool $state

Return Value

PhpNamespace

at line 78
bool hasBracketedSyntax()

No description

Return Value

bool

at line 90
PhpNamespace addUse(string $name, string|null $alias = null, string $of = self::NameNormal)

Adds a use statement for a class, function, or constant.

Auto-generates an alias if the short name conflicts with existing names.

Parameters

string $name
string|null $alias
string $of

Return Value

PhpNamespace

Exceptions

InvalidStateException

at line 134
void removeUse(string $name, string $of = self::NameNormal)

Removes a use statement.

Parameters

string $name
string $of

Return Value

void

at line 147
PhpNamespace addUseFunction(string $name, string|null $alias = null)

Adds a use statement for a function.

Parameters

string $name
string|null $alias

Return Value

PhpNamespace

at line 156
PhpNamespace addUseConstant(string $name, string|null $alias = null)

Adds a use statement for a constant.

Parameters

string $name
string|null $alias

Return Value

PhpNamespace

at line 167
array getUses(string $of = self::NameNormal)

Returns use statements, sorted alphabetically and excluding redundant aliases within the same namespace.

Parameters

string $of

Return Value

array

alias => fully qualified name

at line 182
string resolveName(string $name, string $of = self::NameNormal)

Resolves a relative or aliased name to its fully qualified form.

Parameters

string $name
string $of

Return Value

string

at line 207
string simplifyType(string $type, string $of = self::NameNormal)

Simplifies all class/function/constant names in a type string using current use statements.

Parameters

string $type
string $of

Return Value

string

at line 217
string simplifyName(string $name, string $of = self::NameNormal)

Simplifies a fully qualified name to the shortest possible form using current use statements.

Parameters

string $name
string $of

Return Value

string

at line 265
PhpNamespace add(GlobalFunction $item)

Adds a class-like type or function to the namespace.

Parameters

GlobalFunction $item

Return Value

PhpNamespace

Exceptions

InvalidStateException

at line 291
ClassType addClass(string $name)

Adds a class to the namespace.

Parameters

string $name

Return Value

ClassType

Exceptions

InvalidStateException

at line 302
InterfaceType addInterface(string $name)

Adds an interface to the namespace.

Parameters

string $name

Return Value

InterfaceType

Exceptions

InvalidStateException

at line 313
TraitType addTrait(string $name)

Adds a trait to the namespace.

Parameters

string $name

Return Value

TraitType

Exceptions

InvalidStateException

at line 324
EnumType addEnum(string $name)

Adds an enum to the namespace.

Parameters

string $name

Return Value

EnumType

Exceptions

InvalidStateException

at line 335
EnumType getClass(string $name)

Returns a class-like type by name.

Parameters

string $name

Return Value

EnumType

Exceptions

InvalidArgumentException

at line 342
array getClasses()

No description

Return Value

array

at line 358
PhpNamespace removeClass(string $name)

Removes a class-like type from the namespace.

Parameters

string $name

Return Value

PhpNamespace

at line 369
GlobalFunction addFunction(string $name)

Adds a function to the namespace.

Parameters

string $name

Return Value

GlobalFunction

Exceptions

InvalidStateException

at line 380
GlobalFunction getFunction(string $name)

Returns a function by name.

Parameters

string $name

Return Value

GlobalFunction

Exceptions

InvalidArgumentException

at line 387
array getFunctions()

No description

Return Value

array

at line 401
PhpNamespace removeFunction(string $name)

Removes a function from the namespace.

Parameters

string $name

Return Value

PhpNamespace

at line 414
string __toString()

No description

Return Value

string