final class PhpNamespace

Definition of a PHP namespace.

Generates:

  • namespace statement
  • variable amount of use statements
  • one or more class declarations

Constants

NameNormal

NameFunction

NameConstant

deprecated NAME_NORMAL

deprecated NAME_FUNCTION

deprecated 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 to the namespace for class, function or constant.

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

No description

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

Adds a use statement to the namespace for function.

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

Adds a use statement to the namespace for constant.

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

No description

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

Resolves relative name to full name.

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

Simplifies type hint with relative names.

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

Simplifies the full name of a class, function, or constant to a relative name.

add(EnumType $class)

Adds a class-like type to the namespace. If it already exists, throws an exception.

addClass(string $name)

Adds a class to the namespace. If it already exists, throws an exception.

addInterface(string $name)

Adds an interface to the namespace. If it already exists, throws an exception.

addTrait(string $name)

Adds a trait to the namespace. If it already exists, throws an exception.

addEnum(string $name)

Adds an enum to the namespace. If it already exists, throws an exception.

EnumType
getClass(string $name)

Returns a class-like type from the namespace.

array
getClasses()

Returns all class-like types in the namespace.

removeClass(string $name)

Removes a class-like type from namespace.

addFunction(string $name)

Adds a function to the namespace. If it already exists, throws an exception.

getFunction(string $name)

Returns a function from the namespace.

array
getFunctions()

Returns all functions in the namespace.

removeFunction(string $name)

Removes a function type from namespace.

string
__toString()

No description

Details

at line 60
__construct(string $name)

No description

Parameters

string $name

at line 70
string getName()

No description

Return Value

string

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

internal  
 

No description

Parameters

bool $state

Return Value

PhpNamespace

at line 86
bool hasBracketedSyntax()

No description

Return Value

bool

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

Adds a use statement to the namespace for class, function or constant.

Parameters

string $name
string|null $alias
string $of

Return Value

PhpNamespace

Exceptions

InvalidStateException

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

No description

Parameters

string $name
string $of

Return Value

void

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

Adds a use statement to the namespace for function.

Parameters

string $name
string|null $alias

Return Value

PhpNamespace

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

Adds a use statement to the namespace for constant.

Parameters

string $name
string|null $alias

Return Value

PhpNamespace

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

No description

Parameters

string $of

Return Value

array

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

Resolves relative name to full name.

Parameters

string $name
string $of

Return Value

string

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

Simplifies type hint with relative names.

Parameters

string $type
string $of

Return Value

string

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

Simplifies the full name of a class, function, or constant to a relative name.

Parameters

string $name
string $of

Return Value

string

at line 259
PhpNamespace add(EnumType $class)

Adds a class-like type to the namespace. If it already exists, throws an exception.

Parameters

EnumType $class

Return Value

PhpNamespace

at line 281
ClassType addClass(string $name)

Adds a class to the namespace. If it already exists, throws an exception.

Parameters

string $name

Return Value

ClassType

at line 291
InterfaceType addInterface(string $name)

Adds an interface to the namespace. If it already exists, throws an exception.

Parameters

string $name

Return Value

InterfaceType

at line 301
TraitType addTrait(string $name)

Adds a trait to the namespace. If it already exists, throws an exception.

Parameters

string $name

Return Value

TraitType

at line 311
EnumType addEnum(string $name)

Adds an enum to the namespace. If it already exists, throws an exception.

Parameters

string $name

Return Value

EnumType

at line 321
EnumType getClass(string $name)

Returns a class-like type from the namespace.

Parameters

string $name

Return Value

EnumType

at line 331
array getClasses()

Returns all class-like types in the namespace.

Return Value

array

at line 345
PhpNamespace removeClass(string $name)

Removes a class-like type from namespace.

Parameters

string $name

Return Value

PhpNamespace

at line 355
GlobalFunction addFunction(string $name)

Adds a function to the namespace. If it already exists, throws an exception.

Parameters

string $name

Return Value

GlobalFunction

at line 371
GlobalFunction getFunction(string $name)

Returns a function from the namespace.

Parameters

string $name

Return Value

GlobalFunction

at line 381
array getFunctions()

Returns all functions in the namespace.

Return Value

array

at line 395
PhpNamespace removeFunction(string $name)

Removes a function type from namespace.

Parameters

string $name

Return Value

PhpNamespace

at line 408
string __toString()

No description

Return Value

string