TraitGenerator
extends ClassGenerator
in package
Table of Contents
- FLAG_ABSTRACT = 0x1
- FLAG_FINAL = 0x2
- IMPLEMENTS_KEYWORD = 'implements'
- LINE_FEED = "\n"
- Line feed to use in place of EOL
- OBJECT_TYPE = 'trait'
- $constants : array<string|int, PropertyGenerator>
- $containingFileGenerator : FileGenerator
- $docBlock : DocBlockGenerator
- $extendedClass : string
- $flags : bool
- $implementedInterfaces : array<string|int, mixed>
- $indentation : int|string
- $isSourceDirty : bool
- $methods : array<string|int, MethodGenerator>
- $name : string
- $namespaceName : string
- $properties : array<string|int, PropertyGenerator>
- $sourceContent : string
- $traitUsageGenerator : TraitUsageGenerator
- __construct() : mixed
- addConstant() : self
- Add Constant
- addConstantFromGenerator() : self
- Add constant from PropertyGenerator
- addConstants() : self
- addFlag() : self
- addMethod() : self
- Add Method from scalars
- addMethodFromGenerator() : self
- Add Method from MethodGenerator
- addMethods() : self
- addProperties() : self
- addProperty() : self
- Add Property from scalars
- addPropertyFromGenerator() : self
- 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() : self
- Add a class to "use" classes
- fromArray() : TraitGenerator
- Generate from array
- fromReflection() : TraitGenerator
- Build a Code Generation Php Object from a Class Reflection
- generate() : mixed
- getConstant() : PropertyGenerator|false
- getConstants() : array<string|int, PropertyGenerator>
- getContainingFileGenerator() : FileGenerator
- getDocBlock() : DocBlockGenerator
- getExtendedClass() : string
- getImplementedInterfaces() : array<string|int, mixed>
- getIndentation() : string
- getMethod() : MethodGenerator|false
- getMethods() : array<string|int, MethodGenerator>
- getName() : string
- getNamespaceName() : string
- getProperties() : array<string|int, PropertyGenerator>
- getProperty() : PropertyGenerator|false
- getSourceContent() : string
- 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() : self
- removeExtentedClass() : self
- removeFlag() : self
- removeImplementedInterface() : self
- removeMethod() : self
- removeProperty() : self
- removeTrait() : mixed
- Remove a trait by its name
- removeTraitOverride() : self
- Remove an override for a given trait::method
- removeUse() : self
- removeUseAlias() : self
- setAbstract() : self
- setContainingFileGenerator() : self
- setDocBlock() : self
- setExtendedClass() : self
- setFinal() : self
- setFlags() : self
- setImplementedInterfaces() : self
- setIndentation() : AbstractGenerator
- setName() : self
- setNamespaceName() : self
- 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
= 'trait'
Properties
$constants
protected
array<string|int, PropertyGenerator>
$constants
= []
Array of constants
$containingFileGenerator
protected
FileGenerator
$containingFileGenerator
$docBlock
protected
DocBlockGenerator
$docBlock
$extendedClass
protected
string
$extendedClass
$flags
protected
bool
$flags
= 0x0
$implementedInterfaces
protected
array<string|int, mixed>
$implementedInterfaces
= []
Array of string names
$indentation
protected
int|string
$indentation
= ' '
4 spaces by default
$isSourceDirty
protected
bool
$isSourceDirty
= true
$methods
protected
array<string|int, MethodGenerator>
$methods
= []
Array of methods
$name
protected
string
$name
$namespaceName
protected
string
$namespaceName
$properties
protected
array<string|int, PropertyGenerator>
$properties
= []
Array of properties
$sourceContent
protected
string
$sourceContent
$traitUsageGenerator
protected
TraitUsageGenerator
$traitUsageGenerator
Object to encapsulate trait usage logic
Methods
__construct()
public
__construct([array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $options : array<string|int, mixed> = []
Return values
mixed —addConstant()
Add Constant
public
addConstant(string $name, string|int|null|float|array<string|int, mixed> $value) : self
Parameters
- $name : string
-
Non-empty string
- $value : string|int|null|float|array<string|int, mixed>
-
Scalar
Tags
Return values
self —addConstantFromGenerator()
Add constant from PropertyGenerator
public
addConstantFromGenerator(PropertyGenerator $constant) : self
Parameters
- $constant : PropertyGenerator
Tags
Return values
self —addConstants()
public
addConstants(array<string|int, PropertyGenerator>|array<string|int, array<string|int, mixed>> $constants) : self
Parameters
- $constants : array<string|int, PropertyGenerator>|array<string|int, array<string|int, mixed>>
Return values
self —addFlag()
public
addFlag(string $flag) : self
Parameters
- $flag : string
Return values
self —addMethod()
Add Method from scalars
public
addMethod(string $name[, array<string|int, mixed> $parameters = [] ][, int $flags = MethodGenerator::FLAG_PUBLIC ][, string $body = null ][, string $docBlock = null ]) : self
Parameters
- $name : string
- $parameters : array<string|int, mixed> = []
- $flags : int = MethodGenerator::FLAG_PUBLIC
- $body : string = null
- $docBlock : string = null
Tags
Return values
self —addMethodFromGenerator()
Add Method from MethodGenerator
public
addMethodFromGenerator(MethodGenerator $method) : self
Parameters
- $method : MethodGenerator
Tags
Return values
self —addMethods()
public
addMethods(array<string|int, mixed> $methods) : self
Parameters
- $methods : array<string|int, mixed>
Return values
self —addProperties()
public
addProperties(array<string|int, mixed> $properties) : self
Parameters
- $properties : array<string|int, mixed>
Return values
self —addProperty()
Add Property from scalars
public
addProperty(string $name[, string|array<string|int, mixed> $defaultValue = null ][, int $flags = PropertyGenerator::FLAG_PUBLIC ]) : self
Parameters
- $name : string
- $defaultValue : string|array<string|int, mixed> = null
- $flags : int = PropertyGenerator::FLAG_PUBLIC
Tags
Return values
self —addPropertyFromGenerator()
Add property from PropertyGenerator
public
addPropertyFromGenerator(PropertyGenerator $property) : self
Parameters
- $property : PropertyGenerator
Tags
Return values
self —addTrait()
Add trait takes an array of trait options or string as arguments.
public
addTrait(mixed $trait) : self
Parameters
- $trait : mixed
-
String | Array
Tags
Return values
self —addTraitAlias()
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
Return values
mixed —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
Return values
mixed —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
self —addUse()
Add a class to "use" classes
public
addUse(string $use[, string|null $useAlias = null ]) : self
Parameters
- $use : string
- $useAlias : string|null = null
Return values
self —fromArray()
Generate from array
public
static fromArray(array<string|int, mixed> $array) : TraitGenerator
Parameters
- $array : array<string|int, mixed>
Tags
Return values
TraitGenerator —fromReflection()
Build a Code Generation Php Object from a Class Reflection
public
static fromReflection(ClassReflection $classReflection) : TraitGenerator
Parameters
- $classReflection : ClassReflection
Return values
TraitGenerator —generate()
public
generate() : mixed
Tags
Return values
mixed —getConstant()
public
getConstant(string $constantName) : PropertyGenerator|false
Parameters
- $constantName : string
Return values
PropertyGenerator|false —getConstants()
public
getConstants() : array<string|int, PropertyGenerator>
Return values
array<string|int, PropertyGenerator> —indexed by constant name
getContainingFileGenerator()
public
getContainingFileGenerator() : FileGenerator
Return values
FileGenerator —getDocBlock()
public
getDocBlock() : DocBlockGenerator
Return values
DocBlockGenerator —getExtendedClass()
public
getExtendedClass() : string
Return values
string —getImplementedInterfaces()
public
getImplementedInterfaces() : array<string|int, mixed>
Return values
array<string|int, mixed> —getIndentation()
public
getIndentation() : string
Return values
string —getMethod()
public
getMethod(string $methodName) : MethodGenerator|false
Parameters
- $methodName : string
Return values
MethodGenerator|false —getMethods()
public
getMethods() : array<string|int, MethodGenerator>
Return values
array<string|int, MethodGenerator> —getName()
public
getName() : string
Return values
string —getNamespaceName()
public
getNamespaceName() : string
Return values
string —getProperties()
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|false —getSourceContent()
public
getSourceContent() : string
Return values
string —getTraitAliases()
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
bool —hasExtentedClass()
public
hasExtentedClass() : bool
Return values
bool —hasImplementedInterface()
public
hasImplementedInterface(string $implementedInterface) : bool
Parameters
- $implementedInterface : string
Return values
bool —hasMethod()
public
hasMethod(string $methodName) : bool
Parameters
- $methodName : string
Return values
bool —hasProperty()
public
hasProperty(string $propertyName) : bool
Parameters
- $propertyName : string
Return values
bool —hasTrait()
Check to see if the class has a trait defined
public
hasTrait(mixed $traitName) : bool
Parameters
- $traitName : mixed
Tags
Return values
bool —hasUse()
public
hasUse(string $use) : bool
Parameters
- $use : string
Return values
bool —hasUseAlias()
public
hasUseAlias(string $use) : bool
Parameters
- $use : string
Return values
bool —isAbstract()
public
isAbstract() : bool
Return values
bool —isFinal()
public
isFinal() : bool
Return values
bool —isSourceDirty()
public
isSourceDirty() : bool
Return values
bool —removeConstant()
public
removeConstant(string $constantName) : self
Parameters
- $constantName : string
Return values
self —removeExtentedClass()
public
removeExtentedClass() : self
Return values
self —removeFlag()
public
removeFlag(string $flag) : self
Parameters
- $flag : string
Return values
self —removeImplementedInterface()
public
removeImplementedInterface(string $implementedInterface) : self
Parameters
- $implementedInterface : string
Return values
self —removeMethod()
public
removeMethod(string $methodName) : self
Parameters
- $methodName : string
Return values
self —removeProperty()
public
removeProperty(string $propertyName) : self
Parameters
- $propertyName : string
Return values
self —removeTrait()
Remove a trait by its name
public
removeTrait(mixed $traitName) : mixed
Parameters
- $traitName : mixed
Tags
Return values
mixed —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
self —removeUse()
public
removeUse(string $use) : self
Parameters
- $use : string
Return values
self —removeUseAlias()
public
removeUseAlias(string $use) : self
Parameters
- $use : string
Return values
self —setAbstract()
public
setAbstract(bool $isAbstract) : self
Parameters
- $isAbstract : bool
Return values
self —setContainingFileGenerator()
public
setContainingFileGenerator(FileGenerator $fileGenerator) : self
Parameters
- $fileGenerator : FileGenerator
Return values
self —setDocBlock()
public
setDocBlock(DocBlockGenerator $docBlock) : self
Parameters
- $docBlock : DocBlockGenerator
Return values
self —setExtendedClass()
public
setExtendedClass(string $extendedClass) : self
Parameters
- $extendedClass : string
Return values
self —setFinal()
public
setFinal(bool $isFinal) : self
Parameters
- $isFinal : bool
Return values
self —setFlags()
public
setFlags(array<string|int, mixed>|string $flags) : self
Parameters
- $flags : array<string|int, mixed>|string
Return values
self —setImplementedInterfaces()
public
setImplementedInterfaces(array<string|int, mixed> $implementedInterfaces) : self
Parameters
- $implementedInterfaces : array<string|int, mixed>
Return values
self —setIndentation()
public
setIndentation(string $indentation) : AbstractGenerator
Parameters
- $indentation : string
Return values
AbstractGenerator —setName()
public
setName(string $name) : self
Parameters
- $name : string
Return values
self —setNamespaceName()
public
setNamespaceName(string $namespaceName) : self
Parameters
- $namespaceName : string
Return values
self —setOptions()
public
setOptions(array<string|int, mixed>|Traversable $options) : AbstractGenerator
Parameters
- $options : array<string|int, mixed>|Traversable
Tags
Return values
AbstractGenerator —setSourceContent()
public
setSourceContent(string $sourceContent) : AbstractGenerator
Parameters
- $sourceContent : string
Return values
AbstractGenerator —setSourceDirty()
public
setSourceDirty([bool $isSourceDirty = true ]) : AbstractGenerator
Parameters
- $isSourceDirty : bool = true
Return values
AbstractGenerator —generateShortOrCompleteClassname()
private
generateShortOrCompleteClassname(string $fqnClassName) : string
Parameters
- $fqnClassName : string
Return values
string —validateConstantValue()
private
validateConstantValue(mixed $value) : void
Parameters
- $value : mixed