PhpClass
class PhpClass extends AbstractPhpStruct implements GenerateableInterface, TraitsInterface, ConstantsInterface, PropertiesInterface
Represents a PHP class.
Traits
Methods
Sets the description, which will also be used when generating a docblock
Sets the long description
In contrast to setName(), this method accepts the fully qualified name including the namespace.
Creates a new PHP class
Adds a use statement with an optional alias
Declares a "use $fullClassName" with " as $alias" if $alias is available, and returns its alias (or not qualified classname) to be used in your actual php code.
Returns whether the given use statement is present
Returns the usable alias for a qualified name
Generates a docblock from provided information
Adds a constant
Returns the parent class name
Sets the parent class name
Details
in AbstractModel at line line 19
string
getDescription()
Returns this description
in AbstractModel at line line 29
$this
setDescription(string|array $description)
Sets the description, which will also be used when generating a docblock
in DocblockPart at line line 24
$this
setDocblock(Docblock|string $doc)
Sets the docblock
in DocblockPart at line line 39
Docblock
getDocblock()
Returns the docblock
in LongDescriptionPart at line line 21
string
getLongDescription()
Returns the long description
in LongDescriptionPart at line line 31
$this
setLongDescription(string $longDescription)
Sets the long description
in NamePart at line line 22
$this
setName(string $name)
Sets the name
in NamePart at line line 33
string
getName()
Returns the name
in QualifiedNamePart at line line 24
$this
setNamespace(string $namespace)
Sets the namespace
in QualifiedNamePart at line line 37
$this
setQualifiedName(string $name)
In contrast to setName(), this method accepts the fully qualified name including the namespace.
in QualifiedNamePart at line line 56
string
getNamespace()
Returns the namespace
in QualifiedNamePart at line line 65
string
getQualifiedName()
Returns the qualified name
in AbstractPhpStruct at line line 53
static AbstractPhpStruct
create(string $name = null)
Creates a new struct
at line line 67
__construct(string $name = null)
Creates a new PHP class
in AbstractPhpStruct at line line 76
$this
setRequiredFiles(array $files)
Sets requried files
in AbstractPhpStruct at line line 88
$this
addRequiredFile(string $file)
Adds a new required file
in AbstractPhpStruct at line line 99
Set
getRequiredFiles()
Returns required files
in AbstractPhpStruct at line line 111
$this
setUseStatements(array $useStatements)
Sets use statements
in TraitsPart at line line 25
abstract $this
addUseStatement(string $qualifiedName, null|string $alias = null)
Adds a use statement with an optional alias
in AbstractPhpStruct at line line 146
$this
clearUseStatements()
Clears all use statements
in AbstractPhpStruct at line line 158
$this
declareUses()
Declares multiple use statements at once.
in AbstractPhpStruct at line line 176
string
declareUse(string $qualifiedName, null|string $alias = null)
Declares a "use $fullClassName" with " as $alias" if $alias is available, and returns its alias (or not qualified classname) to be used in your actual php code.
If the class has already been declared you get only the set alias.
in AbstractPhpStruct at line line 190
bool
hasUseStatement(string $qualifiedName)
Returns whether the given use statement is present
in AbstractPhpStruct at line line 200
string
getUseAlias(string $qualifiedName)
Returns the usable alias for a qualified name
in TraitsPart at line line 33
abstract $this
removeUseStatement(string $qualifiedName)
Removes a use statement
in AbstractPhpStruct at line line 220
Map
getUseStatements()
Returns all use statements
in AbstractPhpStruct at line line 230
$this
setMethods(array $methods)
Sets a collection of methods
in AbstractPhpStruct at line line 249
$this
setMethod(PhpMethod $method)
Adds a method
in AbstractPhpStruct at line line 263
$this
removeMethod(string|PhpMethod $nameOrMethod)
Removes a method
in AbstractPhpStruct at line line 284
bool
hasMethod(string|PhpMethod $nameOrMethod)
Checks whether a method exists or not
in AbstractPhpStruct at line line 299
PhpMethod
getMethod(string $nameOrMethod)
Returns a method
in AbstractPhpStruct at line line 316
Map
getMethods()
Returns all methods
in AbstractPhpStruct at line line 325
Set
getMethodNames()
Returns all method names
in AbstractPhpStruct at line line 334
$this
clearMethods()
Clears all methods
at line line 95
$this
generateDocblock()
Generates a docblock from provided information
in AbstractPart at line line 21
bool
isAbstract()
Returns whether this is abstract
in AbstractPart at line line 31
$this
setAbstract(bool $bool)
Sets this to abstract
in ConstantsPart at line line 30
$this
setConstants(array $constants)
Sets a collection of constants
in ConstantsPart at line line 56
$this
setConstant($nameOrConstant, $value = null, $isExpression = false)
Adds a constant
in ConstantsPart at line line 77
$this
removeConstant(string|PhpConstant $nameOrConstant)
Removes a constant
in ConstantsPart at line line 97
bool
hasConstant(string|PhpConstant $nameOrConstant)
Checks whether a constant exists
in ConstantsPart at line line 112
PhpConstant
getConstant(string|PhpConstant $nameOrConstant)
Returns a constant.
in ConstantsPart at line line 129
Map
getConstants()
Returns all constants
in ConstantsPart at line line 138
Set
getConstantNames()
Returns all constant names
in ConstantsPart at line line 147
$this
clearConstants()
Clears all constants
in FinalPart at line line 21
bool
isFinal()
Returns whether this is final
in FinalPart at line line 31
$this
setFinal(bool $bool)
Sets this final
in InterfacesPart at line line 56
$this
addInterface(PhpInterface|string $interface)
Adds an interface.
If the interface is passed as PhpInterface object, the interface is also added as use statement.
in InterfacesPart at line line 79
Set
getInterfaces()
Returns the interfaces
in InterfacesPart at line line 88
bool
hasInterfaces()
Checks whether interfaces exists
in InterfacesPart at line line 98
bool
hasInterface(PhpInterface|string $interface)
Checks whether an interface exists
in InterfacesPart at line line 116
$this
removeInterface(PhpInterface|string $interface)
Removes an interface.
If the interface is passed as PhpInterface object, the interface is also remove from the use statements.
in InterfacesPart at line line 137
$this
setInterfaces(array $interfaces)
Sets a collection of interfaces
in PropertiesPart at line line 29
$this
setProperties(array $properties)
Sets a collection of properties
in PropertiesPart at line line 49
$this
setProperty(PhpProperty $property)
Adds a property
in PropertiesPart at line line 63
$this
removeProperty(PhpProperty|string $nameOrProperty)
Removes a property
in PropertiesPart at line line 84
bool
hasProperty(PhpProperty|string $nameOrProperty)
Checks whether a property exists
in PropertiesPart at line line 99
PhpProperty
getProperty(string $nameOrProperty)
Returns a property
in PropertiesPart at line line 116
Map
getProperties()
Returns a collection of properties
in PropertiesPart at line line 125
Set
getPropertyNames()
Returns all property names
in PropertiesPart at line line 134
$this
clearProperties()
Clears all properties
in TraitsPart at line line 51
$this
addTrait(PhpTrait|string $trait)
Adds a trait.
If the trait is passed as PhpTrait object, the trait is also added as use statement.
in TraitsPart at line line 76
string[]
getTraits()
Returns a collection of traits
in TraitsPart at line line 86
bool
hasTrait(PhpTrait|string $trait)
Checks whether a trait exists
in TraitsPart at line line 103
$this
removeTrait(PhpTrait|string $trait)
Removes a trait.
If the trait is passed as PhpTrait object, the trait is also removed from use statements.
in TraitsPart at line line 129
$this
setTraits(array $traits)
Sets a collection of traits
at line line 40
static PhpClass
fromReflection(ReflectionClass $ref)
deprecated
deprecated
Creates a PHP class from reflection
at line line 50
static PhpClass
fromFile(string $filename)
Creates a PHP class from file
at line line 79
string
getParentClassName()
Returns the parent class name
at line line 89
$this
setParentClassName(string|null $name)
Sets the parent class name