Documentation

ClassGenerator extends AbstractGenerator
in package
implements TraitUsageInterface

Table of Contents

Interfaces

TraitUsageInterface

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

IMPLEMENTS_KEYWORD

public mixed IMPLEMENTS_KEYWORD = 'implements'

Properties

$extendedClass

protected string|null $extendedClass = null
Tags
psalm-var

?class-string

$implementedInterfaces

Array of implemented interface names

protected array<string|int, string> $implementedInterfaces = []
Tags
psalm-var

array

$sourceContent

TODO: Type should be changed to "string" in the next major version. Nullable for BC

protected string|null $sourceContent = null

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
psalm-param

array $interfaces

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
throws
InvalidArgumentException
Return values
static

addConstants()

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
static

addFlag()

public addFlag(int $flag) : static
Parameters
$flag : int
Return values
static

addMethod()

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
throws
InvalidArgumentException
Return values
static

addMethods()

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
static

addProperties()

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
static

addProperty()

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
throws
InvalidArgumentException
Return values
static

addTrait()

Add trait takes an array of trait options or string as arguments.

public addTrait(mixed $trait) : self
Parameters
$trait : mixed
Tags
inheritDoc
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
inheritDoc

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
inheritDoc

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
inheritDoc
Return values
self

addUse()

Add a class to "use" classes

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

fromArray()

Generate from array

public static fromArray(array<string|int, mixed> $array) : static
Parameters
$array : array<string|int, mixed>
Tags
configkey

name string [required] Class Name

configkey

filegenerator FileGenerator File generator that holds this class

configkey

namespacename string The namespace for this class

configkey

docblock string The docblock information

configkey

flags int Flags, one of ClassGenerator::FLAG_ABSTRACT ClassGenerator::FLAG_FINAL

configkey

extendedclass string Class which this class is extending

configkey

implementedinterfaces

configkey

properties

configkey

methods

throws
InvalidArgumentException
Return values
static

fromReflection()

Build a Code Generation Php Object from a Class Reflection

public static fromReflection(ClassReflection $classReflection) : static
Parameters
$classReflection : ClassReflection
Return values
static

getExtendedClass()

public getExtendedClass() : string|null
Tags
psalm-return

?class-string

Return values
string|null

getImplementedInterfaces()

public getImplementedInterfaces() : array<string|int, string>
Tags
psalm-return

array

Return values
array<string|int, string>

getNamespaceName()

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

getSourceContent()

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

getTraitAliases()

public getTraitAliases() : array<string|int, mixed>
Tags
inheritDoc
Return values
array<string|int, mixed>

getTraitOverrides()

Return trait overrides

public getTraitOverrides() : array<string|int, mixed>
Tags
inheritDoc
Return values
array<string|int, mixed>

getTraits()

Get a list of trait names

public getTraits() : array<string|int, mixed>
Tags
inheritDoc
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
Tags
psalm-param

class-string $implementedInterface

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
inheritDoc
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

isSourceDirty()

public isSourceDirty() : bool
Return values
bool

removeConstant()

public removeConstant(string $constantName) : static
Parameters
$constantName : string
Return values
static

removeExtentedClass()

public removeExtentedClass() : static
Return values
static

removeFlag()

public removeFlag(int $flag) : static
Parameters
$flag : int
Return values
static

removeImplementedInterface()

public removeImplementedInterface(string $implementedInterface) : static
Parameters
$implementedInterface : string
Tags
psalm-param

class-string $implementedInterface

Return values
static

removeMethod()

public removeMethod(string $methodName) : static
Parameters
$methodName : string
Return values
static

removeProperty()

public removeProperty(string $propertyName) : static
Parameters
$propertyName : string
Return values
static

removeTrait()

Remove a trait by its name

public removeTrait(mixed $traitName) : mixed
Parameters
$traitName : mixed
Tags
inheritDoc

removeTraitOverride()

Remove an override for a given trait::method

public removeTraitOverride(mixed $method[, mixed $overridesToRemove = null ]) : self
Parameters
$method : mixed
$overridesToRemove : mixed = null
Tags
inheritDoc
Return values
self

removeUse()

public removeUse(string $use) : static
Parameters
$use : string
Return values
static

removeUseAlias()

public removeUseAlias(string $use) : static
Parameters
$use : string
Return values
static

setAbstract()

public setAbstract(bool $isAbstract) : static
Parameters
$isAbstract : bool
Return values
static

setExtendedClass()

public setExtendedClass(string|null $extendedClass) : static
Parameters
$extendedClass : string|null
Tags
psalm-param

?class-string $extendedClass

Return values
static

setFinal()

public setFinal(bool $isFinal) : static
Parameters
$isFinal : bool
Return values
static

setFlags()

public setFlags(array<string|int, int>|int $flags) : static
Parameters
$flags : array<string|int, int>|int
Return values
static

setImplementedInterfaces()

public setImplementedInterfaces(array<string|int, string> $implementedInterfaces) : static
Parameters
$implementedInterfaces : array<string|int, string>
Tags
psalm-param

array $implementedInterfaces

Return values
static

setName()

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

setNamespaceName()

public setNamespaceName(string|null $namespaceName) : static
Parameters
$namespaceName : string|null
Return values
static

generateShortOrCompleteClassname()

private generateShortOrCompleteClassname(string $fqnClassName) : string
Parameters
$fqnClassName : string
Return values
string

        
On this page

Search results