Documentation

EnumGenerator extends AbstractClassGenerator
in package
uses UseTrait

Enum generator class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
6.0.0

Table of Contents

Properties

$attributes  : array<string|int, mixed>
Attributes. An indexed list, not keyed by name — attributes can legitimately repeat (Attribute::IS_REPEATABLE), so a name-keyed map would silently collapse repeats.
$backingType  : string|null
Backing type (null for a pure enum, otherwise 'int' or 'string')
$cases  : array<string|int, mixed>
Array of enum case generator objects
$constants  : array<string|int, mixed>
Array of constant generator objects
$docblock  : DocblockGenerator|null
Docblock generator object
$indent  : int
Code indent spaces
$interfaces  : array<string|int, mixed>
Interfaces that are implemented
$methods  : array<string|int, mixed>
Array of method generator objects
$name  : string|null
Name
$namespace  : NamespaceGenerator|null
Namespace generator object
$output  : string|null
Output string
$uses  : array<string|int, mixed>
Array of namespaces to use

Methods

__construct()  : mixed
Constructor
__toString()  : string
Print enum
addAttribute()  : static
Add an attribute
addAttributes()  : static
Add attributes
addCase()  : EnumGenerator
Add a case
addCases()  : EnumGenerator
Add cases
addConstant()  : AbstractClassGenerator
Add a constant
addConstants()  : AbstractClassGenerator
Add constants
addInterface()  : EnumGenerator
Add an interface
addInterfaces()  : EnumGenerator
Add interfaces
addMethod()  : EnumGenerator
Add a method (overridden to reject a constructor, which enums cannot declare)
addMethods()  : AbstractClassGenerator
Add methods
addUse()  : static
Add a namespace to use
addUses()  : static
Add namespaces to use
getAttributes()  : array<string|int, mixed>
Get all attributes
getAttributesByName()  : array<string|int, mixed>
Get all attributes with the given name (supports repeated attributes)
getBackingType()  : string|null
Get the backing type
getCase()  : EnumCaseGenerator|null
Get a case
getCases()  : array<string|int, mixed>
Get all cases
getConstant()  : ConstantGenerator|null
Get a constant
getConstants()  : array<string|int, mixed>
Get all constants
getDesc()  : string|null
Get the docblock description
getDocblock()  : DocblockGenerator|null
Access the docblock generator object
getIndent()  : int
Get the indent
getInterfaces()  : array<string|int, mixed>
Get the interfaces
getMethod()  : MethodGenerator|null
Get a method
getMethods()  : array<string|int, mixed>
Get all methods
getName()  : string|null
Get the name
getNamespace()  : NamespaceGenerator|null
Access the namespace generator object
getOutput()  : string|null
Get the output
getUses()  : array<string|int, mixed>
Get uses
hasAttribute()  : bool
Has an attribute with the given name
hasAttributes()  : bool
Has attributes
hasBackingType()  : bool
Has backing type
hasCase()  : bool
Has a case
hasCases()  : bool
Has cases
hasConstant()  : bool
Has a constant
hasConstants()  : bool
Has constants
hasDesc()  : bool
Has a docblock description
hasDocblock()  : bool
Has docblock generator object
hasIndent()  : bool
Has indent
hasInterface()  : bool
Has interface
hasInterfaces()  : bool
Has interfaces
hasMethod()  : bool
Has a method
hasMethods()  : bool
Has methods
hasName()  : bool
Get the name
hasNamespace()  : bool
Has a namespace generator object
hasOutput()  : bool
Has output
hasUse()  : bool
Has use
hasUses()  : bool
Has uses
isRendered()  : bool
Is rendered (alias to hasOutput())
printIndent()  : string
Print the indent
removeAttribute()  : static
Remove an attribute (by instance identity — there is no unique name to remove by)
removeCase()  : EnumGenerator
Remove a case
removeConstant()  : AbstractClassGenerator
Remove a constant
removeInterface()  : EnumGenerator
Remove interface
removeMethod()  : AbstractClassGenerator
Remove a method
render()  : string
Render enum
setBackingType()  : EnumGenerator
Set the backing type
setDesc()  : static
Set the docblock description
setDocblock()  : static
Set the docblock generator object
setIndent()  : AbstractGenerator
Set the indent
setName()  : static
Set the name
setNamespace()  : static
Set the namespace generator object
formatAttributes()  : string
Format the attributes
formatCases()  : string
Format the cases
formatConstants()  : string
Format the constants
formatMethods()  : string
Format the methods

Properties

$attributes

Attributes. An indexed list, not keyed by name — attributes can legitimately repeat (Attribute::IS_REPEATABLE), so a name-keyed map would silently collapse repeats.

protected array<string|int, mixed> $attributes = []

$backingType

Backing type (null for a pure enum, otherwise 'int' or 'string')

protected string|null $backingType = null

$cases

Array of enum case generator objects

protected array<string|int, mixed> $cases = []

$constants

Array of constant generator objects

protected array<string|int, mixed> $constants = []

$interfaces

Interfaces that are implemented

protected array<string|int, mixed> $interfaces = []

$name

Name

protected string|null $name = null

$uses

Array of namespaces to use

protected array<string|int, mixed> $uses = []

Methods

__construct()

Constructor

public __construct(string $name[, string|null $backingType = null ][, mixed $interface = null ]) : mixed

Instantiate the enum generator object

Parameters
$name : string
$backingType : string|null = null
$interface : mixed = null

__toString()

Print enum

public __toString() : string
Return values
string

addAttributes()

Add attributes

public addAttributes(array<string|int, mixed> $attributes) : static
Parameters
$attributes : array<string|int, mixed>
Return values
static

addUse()

Add a namespace to use

public addUse(string $use[, string|null $as = null ]) : static
Parameters
$use : string
$as : string|null = null
Return values
static

addUses()

Add namespaces to use

public addUses(array<string|int, mixed> $uses) : static
Parameters
$uses : array<string|int, mixed>
Return values
static

getAttributes()

Get all attributes

public getAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>

getAttributesByName()

Get all attributes with the given name (supports repeated attributes)

public getAttributesByName(string $name) : array<string|int, mixed>
Parameters
$name : string
Return values
array<string|int, mixed>

getBackingType()

Get the backing type

public getBackingType() : string|null
Return values
string|null

getCases()

Get all cases

public getCases() : array<string|int, mixed>
Return values
array<string|int, mixed>

getConstants()

Get all constants

public getConstants() : array<string|int, mixed>
Return values
array<string|int, mixed>

getDesc()

Get the docblock description

public getDesc() : string|null
Return values
string|null

getInterfaces()

Get the interfaces

public getInterfaces() : array<string|int, mixed>
Return values
array<string|int, mixed>

getMethods()

Get all methods

public getMethods() : array<string|int, mixed>
Return values
array<string|int, mixed>

getName()

Get the name

public getName() : string|null
Return values
string|null

getOutput()

Get the output

public getOutput() : string|null
Return values
string|null

getUses()

Get uses

public getUses() : array<string|int, mixed>
Return values
array<string|int, mixed>

hasAttribute()

Has an attribute with the given name

public hasAttribute(string $name) : bool
Parameters
$name : string
Return values
bool

hasAttributes()

Has attributes

public hasAttributes() : bool
Return values
bool

hasBackingType()

Has backing type

public hasBackingType() : bool
Return values
bool

hasCase()

Has a case

public hasCase(mixed $case) : bool
Parameters
$case : mixed
Return values
bool

hasCases()

Has cases

public hasCases() : bool
Return values
bool

hasConstant()

Has a constant

public hasConstant(mixed $constant) : bool
Parameters
$constant : mixed
Return values
bool

hasDesc()

Has a docblock description

public hasDesc() : bool
Return values
bool

hasDocblock()

Has docblock generator object

public hasDocblock() : bool
Return values
bool

hasInterface()

Has interface

public hasInterface(string $interface) : bool
Parameters
$interface : string
Return values
bool

hasInterfaces()

Has interfaces

public hasInterfaces() : bool
Return values
bool

hasMethod()

Has a method

public hasMethod(mixed $method) : bool
Parameters
$method : mixed
Return values
bool

hasName()

Get the name

public hasName() : bool
Return values
bool

hasNamespace()

Has a namespace generator object

public hasNamespace() : bool
Return values
bool

hasUse()

Has use

public hasUse(string $use) : bool
Parameters
$use : string
Return values
bool

hasUses()

Has uses

public hasUses() : bool
Return values
bool

isRendered()

Is rendered (alias to hasOutput())

public isRendered() : bool
Return values
bool

printIndent()

Print the indent

public printIndent() : string
Return values
string

setDesc()

Set the docblock description

public setDesc([string|null $desc = null ]) : static
Parameters
$desc : string|null = null
Return values
static

setName()

Set the name

public setName(string $name) : static
Parameters
$name : string
Return values
static

formatAttributes()

Format the attributes

protected formatAttributes([bool $indented = true ]) : string
Parameters
$indented : bool = true
Return values
string

formatCases()

Format the cases

protected formatCases() : string
Return values
string

formatConstants()

Format the constants

protected formatConstants() : string
Return values
string

formatMethods()

Format the methods

protected formatMethods() : string
Return values
string

        
On this page

Search results