ClassGenerator
extends AbstractGenerator
in package
implements
TraitUsageInterface
Table of Contents
Interfaces
Constants
- FLAG_ABSTRACT = 0x1
- FLAG_FINAL = 0x2
- IMPLEMENTS_KEYWORD = 'implements'
- LINE_FEED = "\n"
- Line feed to use in place of EOL
- OBJECT_TYPE = 'class'
- CONSTRUCTOR_NAME = '__construct'
Properties
- $constants : array<string|int, PropertyGenerator>
- $containingFileGenerator : FileGenerator|null
- $docBlock : DocBlockGenerator|null
- $extendedClass : string|null
- $flags : int
- $implementedInterfaces : array<string|int, string>
- Array of implemented interface names
- $indentation : string
- $isSourceDirty : bool
- $methods : array<string|int, MethodGenerator>
- $name : string
- $namespaceName : string|null
- $properties : array<string|int, PropertyGenerator>
- $sourceContent : string|null
- TODO: Type should be changed to "string" in the next major version. Nullable for BC
- $traitUsageGenerator : TraitUsageGenerator
Methods
- __construct() : mixed
- addConstant() : static
- Add Constant
- addConstantFromGenerator() : static
- Add constant from PropertyGenerator
- addConstants() : static
- addFlag() : static
- addMethod() : static
- Add Method from scalars
- addMethodFromGenerator() : static
- Add Method from MethodGenerator
- addMethods() : static
- addProperties() : static
- addProperty() : static
- Add Property from scalars
- addPropertyFromGenerator() : static
- Add property from PropertyGenerator
- addTrait() : self
- Add trait takes an array of trait options or string as arguments.
- addTraitAlias() : mixed
- Add a trait alias. This will be used to generate the AS portion of the use statement.
- addTraitOverride() : mixed
- Add a trait method override. This will be used to generate the INSTEADOF portion of the use statement.
- addTraits() : self
- Add multiple traits. Trait can be an array of trait names or array of trait configurations
- addUse() : static
- Add a class to "use" classes
- fromArray() : static
- Generate from array
- fromReflection() : static
- Build a Code Generation Php Object from a Class Reflection
- generate() : mixed
- getConstant() : PropertyGenerator|false
- getConstants() : array<string|int, PropertyGenerator>
- getContainingFileGenerator() : FileGenerator|null
- getDocBlock() : DocBlockGenerator|null
- getExtendedClass() : string|null
- getImplementedInterfaces() : array<string|int, string>
- getIndentation() : string
- getMethod() : MethodGenerator|false
- getMethods() : array<string|int, MethodGenerator>
- getName() : string
- getNamespaceName() : string|null
- getProperties() : array<string|int, PropertyGenerator>
- getProperty() : PropertyGenerator|false
- getSourceContent() : string|null
- getTraitAliases() : array<string|int, mixed>
- getTraitOverrides() : array<string|int, mixed>
- Return trait overrides
- getTraits() : array<string|int, mixed>
- Get a list of trait names
- getUses() : array<string|int, mixed>
- Returns the "use" classes
- hasConstant() : bool
- hasExtentedClass() : bool
- hasImplementedInterface() : bool
- hasMethod() : bool
- hasProperty() : bool
- hasTrait() : bool
- Check to see if the class has a trait defined
- hasUse() : bool
- hasUseAlias() : bool
- isAbstract() : bool
- isFinal() : bool
- isSourceDirty() : bool
- removeConstant() : static
- removeExtentedClass() : static
- removeFlag() : static
- removeImplementedInterface() : static
- removeMethod() : static
- removeProperty() : static
- removeTrait() : mixed
- Remove a trait by its name
- removeTraitOverride() : self
- Remove an override for a given trait::method
- removeUse() : static
- removeUseAlias() : static
- setAbstract() : static
- setContainingFileGenerator() : static
- setDocBlock() : static
- setExtendedClass() : static
- setFinal() : static
- setFlags() : static
- setImplementedInterfaces() : static
- setIndentation() : AbstractGenerator
- setName() : static
- setNamespaceName() : static
- setOptions() : AbstractGenerator
- setSourceContent() : AbstractGenerator
- setSourceDirty() : AbstractGenerator
- generateShortOrCompleteClassname() : string
- validateConstantValue() : void
Constants
FLAG_ABSTRACT
public
mixed
FLAG_ABSTRACT
= 0x1
FLAG_FINAL
public
mixed
FLAG_FINAL
= 0x2
IMPLEMENTS_KEYWORD
public
mixed
IMPLEMENTS_KEYWORD
= 'implements'
LINE_FEED
Line feed to use in place of EOL
public
mixed
LINE_FEED
= "\n"
OBJECT_TYPE
public
mixed
OBJECT_TYPE
= 'class'
CONSTRUCTOR_NAME
private
mixed
CONSTRUCTOR_NAME
= '__construct'
Properties
$constants
protected
array<string|int, PropertyGenerator>
$constants
= []
$containingFileGenerator
protected
FileGenerator|null
$containingFileGenerator
= null
$docBlock
protected
DocBlockGenerator|null
$docBlock
= null
$extendedClass
protected
string|null
$extendedClass
= null
Tags
$flags
protected
int
$flags
= 0x0
$implementedInterfaces
Array of implemented interface names
protected
array<string|int, string>
$implementedInterfaces
= []
Tags
$indentation
protected
string
$indentation
= ' '
4 spaces by default
$isSourceDirty
protected
bool
$isSourceDirty
= true
$methods
protected
array<string|int, MethodGenerator>
$methods
= []
$name
protected
string
$name
= ''
$namespaceName
protected
string|null
$namespaceName
= null
$properties
protected
array<string|int, PropertyGenerator>
$properties
= []
$sourceContent
TODO: Type should be changed to "string" in the next major version. Nullable for BC
protected
string|null
$sourceContent
= null
$traitUsageGenerator
protected
TraitUsageGenerator
$traitUsageGenerator
Object to encapsulate trait usage logic
Methods
__construct()
public
__construct([string $name = null ][, string $namespaceName = null ][, int|array<string|int, int>|null $flags = null ][, class-string|null $extends = null ][, array<string|int, string> $interfaces = [] ][, array<string|int, PropertyGenerator>|array<string|int, string>|array<string|int, array<string|int, mixed>> $properties = [] ][, array<string|int, MethodGenerator>|array<string|int, string>|array<string|int, array<string|int, mixed>> $methods = [] ][, DocBlockGenerator $docBlock = null ]) : mixed
Parameters
- $name : string = null
- $namespaceName : string = null
- $flags : int|array<string|int, int>|null = null
- $extends : class-string|null = null
- $interfaces : array<string|int, string> = []
- $properties : array<string|int, PropertyGenerator>|array<string|int, string>|array<string|int, array<string|int, mixed>> = []
- $methods : array<string|int, MethodGenerator>|array<string|int, string>|array<string|int, array<string|int, mixed>> = []
- $docBlock : DocBlockGenerator = null
Tags
addConstant()
Add Constant
public
addConstant(string $name, string|int|null|float|array<string|int, mixed> $value[, bool $isFinal = false ]) : static
Parameters
- $name : string
-
Non-empty string
- $value : string|int|null|float|array<string|int, mixed>
-
Scalar
- $isFinal : bool = false
Tags
Return values
staticaddConstantFromGenerator()
Add constant from PropertyGenerator
public
addConstantFromGenerator(PropertyGenerator $constant) : static
Parameters
- $constant : PropertyGenerator
Tags
Return values
staticaddConstants()
public
addConstants(array<string|int, PropertyGenerator>|array<string|int, array<string|int, mixed>> $constants) : static
Parameters
- $constants : array<string|int, PropertyGenerator>|array<string|int, array<string|int, mixed>>
Return values
staticaddFlag()
public
addFlag(int $flag) : static
Parameters
- $flag : int
Return values
staticaddMethod()
Add Method from scalars
public
addMethod(string $name[, array<string|int, ParameterGenerator>|array<string|int, array<string|int, mixed>>|array<string|int, string> $parameters = [] ][, int $flags = MethodGenerator::FLAG_PUBLIC ][, string $body = null ][, string $docBlock = null ]) : static
Parameters
- $name : string
- $parameters : array<string|int, ParameterGenerator>|array<string|int, array<string|int, mixed>>|array<string|int, string> = []
- $flags : int = MethodGenerator::FLAG_PUBLIC
- $body : string = null
- $docBlock : string = null
Tags
Return values
staticaddMethodFromGenerator()
Add Method from MethodGenerator
public
addMethodFromGenerator(MethodGenerator $method) : static
Parameters
- $method : MethodGenerator
Tags
Return values
staticaddMethods()
public
addMethods(array<string|int, MethodGenerator>|array<string|int, string>|array<string|int, array<string|int, mixed>> $methods) : static
Parameters
- $methods : array<string|int, MethodGenerator>|array<string|int, string>|array<string|int, array<string|int, mixed>>
Return values
staticaddProperties()
public
addProperties(array<string|int, PropertyGenerator>|array<string|int, string>|array<string|int, array<string|int, mixed>> $properties) : static
Parameters
- $properties : array<string|int, PropertyGenerator>|array<string|int, string>|array<string|int, array<string|int, mixed>>
Return values
staticaddProperty()
Add Property from scalars
public
addProperty(string $name[, string|array<string|int, mixed> $defaultValue = null ][, int $flags = PropertyGenerator::FLAG_PUBLIC ]) : static
Parameters
- $name : string
- $defaultValue : string|array<string|int, mixed> = null
- $flags : int = PropertyGenerator::FLAG_PUBLIC
Tags
Return values
staticaddPropertyFromGenerator()
Add property from PropertyGenerator
public
addPropertyFromGenerator(PropertyGenerator $property) : static
Parameters
- $property : PropertyGenerator
Tags
Return values
staticaddTrait()
Add trait takes an array of trait options or string as arguments.
public
addTrait(mixed $trait) : self
Parameters
- $trait : mixed
Tags
Return values
selfaddTraitAlias()
Add a trait alias. This will be used to generate the AS portion of the use statement.
public
addTraitAlias(mixed $method, mixed $alias[, mixed $visibility = null ]) : mixed
Parameters
- $method : mixed
-
String or Array
- $alias : mixed
- $visibility : mixed = null
Tags
addTraitOverride()
Add a trait method override. This will be used to generate the INSTEADOF portion of the use statement.
public
addTraitOverride(mixed $method, mixed $traitsToReplace) : mixed
Parameters
- $method : mixed
- $traitsToReplace : mixed
Tags
addTraits()
Add multiple traits. Trait can be an array of trait names or array of trait configurations
public
addTraits(array<string|int, mixed> $traits) : self
Parameters
- $traits : array<string|int, mixed>
-
Array of string names or configurations (@see addTrait)
Tags
Return values
selfaddUse()
Add a class to "use" classes
public
addUse(string $use[, string|null $useAlias = null ]) : static
Parameters
- $use : string
- $useAlias : string|null = null
Return values
staticfromArray()
Generate from array
public
static fromArray(array<string|int, mixed> $array) : static
Parameters
- $array : array<string|int, mixed>
Tags
Return values
staticfromReflection()
Build a Code Generation Php Object from a Class Reflection
public
static fromReflection(ClassReflection $classReflection) : static
Parameters
- $classReflection : ClassReflection
Return values
staticgenerate()
public
generate() : mixed
Tags
getConstant()
public
getConstant(string $constantName) : PropertyGenerator|false
Parameters
- $constantName : string
Return values
PropertyGenerator|falsegetConstants()
public
getConstants() : array<string|int, PropertyGenerator>
Return values
array<string|int, PropertyGenerator> —indexed by constant name
getContainingFileGenerator()
public
getContainingFileGenerator() : FileGenerator|null
Return values
FileGenerator|nullgetDocBlock()
public
getDocBlock() : DocBlockGenerator|null
Return values
DocBlockGenerator|nullgetExtendedClass()
public
getExtendedClass() : string|null
Tags
Return values
string|nullgetImplementedInterfaces()
public
getImplementedInterfaces() : array<string|int, string>
Tags
Return values
array<string|int, string>getIndentation()
public
getIndentation() : string
Return values
stringgetMethod()
public
getMethod(string $methodName) : MethodGenerator|false
Parameters
- $methodName : string
Return values
MethodGenerator|falsegetMethods()
public
getMethods() : array<string|int, MethodGenerator>
Return values
array<string|int, MethodGenerator>getName()
public
getName() : string
Return values
stringgetNamespaceName()
public
getNamespaceName() : string|null
Return values
string|nullgetProperties()
public
getProperties() : array<string|int, PropertyGenerator>
Return values
array<string|int, PropertyGenerator>getProperty()
public
getProperty(string $propertyName) : PropertyGenerator|false
Parameters
- $propertyName : string
Return values
PropertyGenerator|falsegetSourceContent()
public
getSourceContent() : string|null
Return values
string|nullgetTraitAliases()
public
getTraitAliases() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getTraitOverrides()
Return trait overrides
public
getTraitOverrides() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getTraits()
Get a list of trait names
public
getTraits() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getUses()
Returns the "use" classes
public
getUses() : array<string|int, mixed>
Return values
array<string|int, mixed>hasConstant()
public
hasConstant(string $constantName) : bool
Parameters
- $constantName : string
Return values
boolhasExtentedClass()
public
hasExtentedClass() : bool
Return values
boolhasImplementedInterface()
public
hasImplementedInterface(string $implementedInterface) : bool
Parameters
- $implementedInterface : string
Tags
Return values
boolhasMethod()
public
hasMethod(string $methodName) : bool
Parameters
- $methodName : string
Return values
boolhasProperty()
public
hasProperty(string $propertyName) : bool
Parameters
- $propertyName : string
Return values
boolhasTrait()
Check to see if the class has a trait defined
public
hasTrait(mixed $traitName) : bool
Parameters
- $traitName : mixed
Tags
Return values
boolhasUse()
public
hasUse(string $use) : bool
Parameters
- $use : string
Return values
boolhasUseAlias()
public
hasUseAlias(string $use) : bool
Parameters
- $use : string
Return values
boolisAbstract()
public
isAbstract() : bool
Return values
boolisFinal()
public
isFinal() : bool
Return values
boolisSourceDirty()
public
isSourceDirty() : bool
Return values
boolremoveConstant()
public
removeConstant(string $constantName) : static
Parameters
- $constantName : string
Return values
staticremoveExtentedClass()
public
removeExtentedClass() : static
Return values
staticremoveFlag()
public
removeFlag(int $flag) : static
Parameters
- $flag : int
Return values
staticremoveImplementedInterface()
public
removeImplementedInterface(string $implementedInterface) : static
Parameters
- $implementedInterface : string
Tags
Return values
staticremoveMethod()
public
removeMethod(string $methodName) : static
Parameters
- $methodName : string
Return values
staticremoveProperty()
public
removeProperty(string $propertyName) : static
Parameters
- $propertyName : string
Return values
staticremoveTrait()
Remove a trait by its name
public
removeTrait(mixed $traitName) : mixed
Parameters
- $traitName : mixed
Tags
removeTraitOverride()
Remove an override for a given trait::method
public
removeTraitOverride(mixed $method[, mixed $overridesToRemove = null ]) : self
Parameters
- $method : mixed
- $overridesToRemove : mixed = null
Tags
Return values
selfremoveUse()
public
removeUse(string $use) : static
Parameters
- $use : string
Return values
staticremoveUseAlias()
public
removeUseAlias(string $use) : static
Parameters
- $use : string
Return values
staticsetAbstract()
public
setAbstract(bool $isAbstract) : static
Parameters
- $isAbstract : bool
Return values
staticsetContainingFileGenerator()
public
setContainingFileGenerator(FileGenerator $fileGenerator) : static
Parameters
- $fileGenerator : FileGenerator
Return values
staticsetDocBlock()
public
setDocBlock(DocBlockGenerator $docBlock) : static
Parameters
- $docBlock : DocBlockGenerator
Return values
staticsetExtendedClass()
public
setExtendedClass(string|null $extendedClass) : static
Parameters
- $extendedClass : string|null
Tags
Return values
staticsetFinal()
public
setFinal(bool $isFinal) : static
Parameters
- $isFinal : bool
Return values
staticsetFlags()
public
setFlags(array<string|int, int>|int $flags) : static
Parameters
- $flags : array<string|int, int>|int
Return values
staticsetImplementedInterfaces()
public
setImplementedInterfaces(array<string|int, string> $implementedInterfaces) : static
Parameters
- $implementedInterfaces : array<string|int, string>
Tags
Return values
staticsetIndentation()
public
setIndentation(string $indentation) : AbstractGenerator
Parameters
- $indentation : string
Return values
AbstractGeneratorsetName()
public
setName(string $name) : static
Parameters
- $name : string
Return values
staticsetNamespaceName()
public
setNamespaceName(string|null $namespaceName) : static
Parameters
- $namespaceName : string|null
Return values
staticsetOptions()
public
setOptions(array<string|int, mixed>|Traversable $options) : AbstractGenerator
Parameters
- $options : array<string|int, mixed>|Traversable
Tags
Return values
AbstractGeneratorsetSourceContent()
public
setSourceContent(string|null $sourceContent) : AbstractGenerator
Parameters
- $sourceContent : string|null
Return values
AbstractGeneratorsetSourceDirty()
public
setSourceDirty([bool $isSourceDirty = true ]) : AbstractGenerator
Parameters
- $isSourceDirty : bool = true
Return values
AbstractGeneratorgenerateShortOrCompleteClassname()
private
generateShortOrCompleteClassname(string $fqnClassName) : string
Parameters
- $fqnClassName : string
Return values
stringvalidateConstantValue()
private
validateConstantValue(mixed $value) : void
Parameters
- $value : mixed