Documentation

ConstantGenerator extends AbstractClassElementGenerator
in package

Constant 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

Constants

VALID_VISIBILITIES  = ['public', 'protected', 'private']
Valid visibility values

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.
$docblock  : DocblockGenerator|null
Docblock generator object
$indent  : int
Code indent spaces
$name  : string|null
Name
$output  : string|null
Output string
$static  : bool
Static flag
$type  : string|null
Constant type
$typed  : bool
Typed-signature flag: when true and a type is set, render() emits the type in the signature
$value  : mixed
Constant value
$visibility  : string
Visibility

Methods

__construct()  : mixed
Constructor
__toString()  : string
Print constant
addAttribute()  : static
Add an attribute
addAttributes()  : static
Add attributes
getAttributes()  : array<string|int, mixed>
Get all attributes
getAttributesByName()  : array<string|int, mixed>
Get all attributes with the given name (supports repeated attributes)
getDesc()  : string|null
Get the docblock description
getDocblock()  : DocblockGenerator|null
Access the docblock generator object
getIndent()  : int
Get the indent
getName()  : string|null
Get the name
getOutput()  : string|null
Get the output
getType()  : string
Get the constant type
getValue()  : mixed
Get the constant value
getVisibility()  : string
Get the visibility
hasAttribute()  : bool
Has an attribute with the given name
hasAttributes()  : bool
Has attributes
hasDesc()  : bool
Has a docblock description
hasDocblock()  : bool
Has docblock generator object
hasIndent()  : bool
Has indent
hasName()  : bool
Get the name
hasOutput()  : bool
Has output
hasValue()  : bool
Has constant value
isPrivate()  : bool
Set the visibility to private
isProtected()  : bool
Set the visibility to protected
isPublic()  : bool
Is visibility public
isRendered()  : bool
Is rendered (alias to hasOutput())
isStatic()  : bool
Get the static flag
isTyped()  : bool
Determine if the declared type is rendered in the signature
printIndent()  : string
Print the indent
removeAttribute()  : static
Remove an attribute (by instance identity — there is no unique name to remove by)
render()  : string
Render constant
setAsPrivate()  : AbstractClassElementGenerator
Set the visibility to public
setAsProtected()  : AbstractClassElementGenerator
Set the visibility to protected
setAsPublic()  : AbstractClassElementGenerator
Set the visibility to public
setAsStatic()  : AbstractClassElementGenerator
Set the static flag
setDesc()  : static
Set the docblock description
setDocblock()  : static
Set the docblock generator object
setIndent()  : AbstractGenerator
Set the indent
setName()  : static
Set the name
setType()  : ConstantGenerator
Set the constant type
setTyped()  : ConstantGenerator
Set whether the declared type is rendered in the signature (PHP 8.3+ typed constants)
setValue()  : ConstantGenerator
Set the constant value
setVisibility()  : AbstractClassElementGenerator
Set the visibility
formatAttributes()  : string
Format the attributes

Constants

VALID_VISIBILITIES

Valid visibility values

protected array<string|int, mixed> VALID_VISIBILITIES = ['public', 'protected', 'private']

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 = []

$name

Name

protected string|null $name = null

$typed

Typed-signature flag: when true and a type is set, render() emits the type in the signature

protected bool $typed = false

Methods

__construct()

Constructor

public __construct(string $name, string $type[, mixed $value = null ]) : mixed

Instantiate the constant generator object

Parameters
$name : string
$type : string
$value : mixed = null

__toString()

Print constant

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

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>

getDesc()

Get the docblock description

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

getName()

Get the name

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

getOutput()

Get the output

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

getType()

Get the constant type

public getType() : string
Return values
string

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

hasDesc()

Has a docblock description

public hasDesc() : bool
Return values
bool

hasDocblock()

Has docblock generator object

public hasDocblock() : bool
Return values
bool

hasName()

Get the name

public hasName() : bool
Return values
bool

isRendered()

Is rendered (alias to hasOutput())

public isRendered() : bool
Return values
bool

isTyped()

Determine if the declared type is rendered in the signature

public isTyped() : 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

        
On this page

Search results