final class PhpNamespace

Namespaced part of a PHP file.

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 classes, functions or constants.

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 functions.

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

Adds a use statement to the namespace for constants.

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

No description

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

Resolves name to full name.

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

Simplifies type hint using aliases.

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

Simplifies class, function or constant full name to alias.

add(EnumType $class)

Adds a class 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 inteface 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.

removeClass(string $name)

No description

addFunction(string $name)

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

removeFunction(string $name)

No description

array
getClasses()

No description

array
getFunctions()

No description

string
__toString()

No description

Details

at line 58
__construct(string $name)

No description

Parameters

string $name

at line 68
string getName()

No description

Return Value

string

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

internal  
 

No description

Parameters

bool $state

Return Value

PhpNamespace

at line 84
bool hasBracketedSyntax()

No description

Return Value

bool

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

Adds a use statement to the namespace for classes, functions or constants.

Parameters

string $name
string|null $alias
string $of

Return Value

PhpNamespace

Exceptions

InvalidStateException

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

No description

Parameters

string $name
string $of

Return Value

void

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

Adds a use statement to the namespace for functions.

Parameters

string $name
string|null $alias

Return Value

PhpNamespace

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

Adds a use statement to the namespace for constants.

Parameters

string $name
string|null $alias

Return Value

PhpNamespace

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

No description

Parameters

string $of

Return Value

array

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

Resolves name to full name.

Parameters

string $name
string $of

Return Value

string

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

Simplifies type hint using aliases.

Parameters

string $type
string $of

Return Value

string

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

Simplifies class, function or constant full name to alias.

Parameters

string $name
string $of

Return Value

string

at line 257
PhpNamespace add(EnumType $class)

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

Parameters

EnumType $class

Return Value

PhpNamespace

at line 279
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 289
InterfaceType addInterface(string $name)

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

Parameters

string $name

Return Value

InterfaceType

at line 299
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 309
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 316
PhpNamespace removeClass(string $name)

No description

Parameters

string $name

Return Value

PhpNamespace

at line 326
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 339
PhpNamespace removeFunction(string $name)

No description

Parameters

string $name

Return Value

PhpNamespace

at line 347
array getClasses()

No description

Return Value

array

at line 359
array getFunctions()

No description

Return Value

array

at line 376
string __toString()

No description

Return Value

string