PhpClass extends AbstractPhpStruct implements GenerateableInterface, TraitsInterface, ConstantsInterface, PropertiesInterface Uses AbstractPart, ConstantsPart, FinalPart, InterfacesPart, PropertiesPart, TraitsPart
Represents a PHP class.
Tags
Interfaces, Classes and Traits
- GenerateableInterface
- Represents all models that can be generated with a code generator.
- TraitsInterface
- Represents models that can have traits.
- ConstantsInterface
- Interface to all php structs that can have constants.
- PropertiesInterface
Table of Contents
- $description : string
- $abstract : bool
- $constants : Map
- $docblock : Docblock
- $final : bool
- $interfaces : Set
- $longDescription : string
- $methods : Map
- $namespace : string
- $parentClassName : string
- $properties : Map
- $requiredFiles : Set
- $traits : Set
- $useStatements : Map
- __construct() : mixed
- Creates a new PHP class.
- addInterface() : $this
- Adds an interface.
- addRequiredFile() : $this
- Adds a new required file.
- addTrait() : $this
- Adds a trait.
- addUseStatement() : $this
- Adds a use statement with an optional alias.
- clearConstants() : $this
- Clears all constants.
- clearMethods() : $this
- Clears all methods.
- clearProperties() : $this
- Clears all properties.
- clearUseStatements() : $this
- Clears all use statements.
- create() : static
- Creates a new struct.
- declareUse() : string
- 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.
- declareUses() : $this
- Declares multiple use statements at once.
- generateDocblock() : $this
- Generates a docblock from provided information.
- getConstant() : PhpConstant
- Returns a constant.
- getConstantNames() : Set
- Returns all constant names.
- getConstants() : Map
- Returns all constants.
- getDescription() : string
- Returns this description.
- getDocblock() : Docblock
- Returns the docblock.
- getInterfaces() : Set
- Returns the interfaces.
- getLongDescription() : string
- Returns the long description.
- getMethod() : PhpMethod
- Returns a method.
- getMethodByName() : PhpMethod
- Returns amethod.
- getMethodNames() : Set
- Returns all method names.
- getMethods() : Map
- Returns all methods.
- getNamespace() : string
- Returns the namespace.
- getParentClassName() : string
- Returns the parent class name.
- getProperties() : Map
- Returns a collection of properties.
- getProperty() : PhpProperty
- Returns a property.
- getPropertyNames() : Set
- Returns all property names.
- getQualifiedName() : string
- Returns the qualified name.
- getRequiredFiles() : Set
- Returns required files.
- getTraits() : Set
- Returns a collection of traits.
- getUseAlias() : string
- Returns the usable alias for a qualified name.
- getUseStatements() : Map
- Returns all use statements.
- hasConstant() : bool
- Checks whether a constant exists.
- hasConstantByName() : bool
- Checks whether a constant exists.
- hasInterface() : bool
- Checks whether an interface exists.
- hasInterfaceByName() : bool
- Checks whether an interface exists.
- hasInterfaces() : bool
- Checks whether interfaces exists.
- hasMethod() : bool
- Checks whether a method exists or not.
- hasMethodByName() : bool
- Checks whether a method exists or not.
- hasProperty() : bool
- Checks whether a property exists.
- hasPropertyByName() : bool
- Checks whether a property exists.
- hasTrait() : bool
- Checks whether a trait exists.
- hasTraitByName() : bool
- Checks whether a trait exists.
- hasUseStatement() : bool
- Returns whether the given use statement is present.
- isAbstract() : bool
- Returns whether this is abstract.
- isFinal() : bool
- Returns whether this is final.
- removeConstant() : $this
- Removes a constant.
- removeConstantByName() : $this
- Removes a constant.
- removeInterface() : $this
- Removes an interface.
- removeInterfaceByName() : $this
- Removes an interface.
- removeMethod() : $this
- Removes a method.
- removeMethodByName() : $this
- Removes a method.
- removeProperty() : $this
- Removes a property.
- removePropertyByName() : $this
- Removes a property.
- removeTrait() : $this
- Removes a trait.
- removeTraitByName() : $this
- Removes a trait.
- removeUseStatement() : $this
- Removes a use statement.
- setAbstract() : $this
- Sets this to abstract.
- setConstant() : $this
- Add a PhpConstant object.
- setConstantByName() : $this
- Create a PhpConstant instance and adds it to the constants Map.
- setConstants() : $this
- Sets a collection of constants.
- setDescription() : $this
- Sets the description, which will also be used when generating a docblock.
- setDocblock() : $this
- Sets the docblock.
- setFinal() : $this
- Sets this final.
- setInterfaces() : $this
- Sets a collection of interfaces.
- setLongDescription() : $this
- Sets the long description.
- setMethod() : $this
- Adds a method.
- setMethods() : $this
- Sets a collection of methods.
- setMultilineDescription() : $this
- Sets a multi-line description, which will also be used when generating a docblock.
- setNamespace() : $this
- Sets the namespace.
- setParentClassName() : $this
- Sets the parent class name.
- setProperties() : $this
- Sets a collection of properties.
- setProperty() : $this
- Adds a property.
- setQualifiedName() : $this
- In contrast to setName(), this method accepts the fully qualified name including the namespace.
- setRequiredFiles() : $this
- Sets requried files.
- setTraits() : $this
- Sets a collection of traits.
- setUseStatements() : $this
- Sets use statements.
- initConstants() : void
- initInterfaces() : void
- initProperties() : void
- initTraits() : void
Properties
$description
protected
string
$description
= ''
$abstract
private
bool
$abstract
= false
$constants
private
Map
$constants
$docblock
private
Docblock
$docblock
$final
private
bool
$final
= false
$interfaces
private
Set
$interfaces
$longDescription
private
string
$longDescription
= ''
$methods
private
Map
$methods
$namespace
private
string
$namespace
= ''
$parentClassName
private
string
$parentClassName
= ''
$properties
private
Map
$properties
$requiredFiles
private
Set
$requiredFiles
$traits
private
Set
$traits
$useStatements
private
Map
$useStatements
Methods
__construct()
Creates a new PHP class.
public
final __construct([string $name = '' ]) : mixed
Parameters
- $name : string = ''
-
the qualified name
Return values
mixed —addInterface()
Adds an interface.
public
addInterface(PhpInterface|string $interface) : $this
If the interface is passed as PhpInterface object, the interface is also added as use statement.
Parameters
- $interface : PhpInterface|string
-
interface or qualified name
Return values
$this —addRequiredFile()
Adds a new required file.
public
addRequiredFile(string $file) : $this
Parameters
- $file : string
Return values
$this —addTrait()
Adds a trait.
public
addTrait(PhpTrait $trait) : $this
If the trait is passed as PhpTrait object, the trait is also added as use statement.
Parameters
- $trait : PhpTrait
-
trait or qualified name
Return values
$this —addUseStatement()
Adds a use statement with an optional alias.
public
addUseStatement(string $qualifiedName[, string|null $alias = null ]) : $this
Parameters
- $qualifiedName : string
- $alias : string|null = null
Return values
$this —clearConstants()
Clears all constants.
public
clearConstants() : $this
Return values
$this —clearMethods()
Clears all methods.
public
clearMethods() : $this
Return values
$this —clearProperties()
Clears all properties.
public
clearProperties() : $this
Return values
$this —clearUseStatements()
Clears all use statements.
public
clearUseStatements() : $this
Return values
$this —create()
Creates a new struct.
public
static create([string $name = '' ]) : static
Parameters
- $name : string = ''
-
the fqcn
Return values
static —declareUse()
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.
public
declareUse(string $qualifiedName[, string|null $alias = null ]) : string
If the class has already been declared you get only the set alias.
Parameters
- $qualifiedName : string
- $alias : string|null = null
Return values
string —the used alias
declareUses()
Declares multiple use statements at once.
public
declareUses() : $this
Return values
$this —generateDocblock()
Generates a docblock from provided information.
public
generateDocblock() : $this
Return values
$this —getConstant()
Returns a constant.
public
getConstant(string $name) : PhpConstant
Parameters
- $name : string
-
constant name
Tags
Return values
PhpConstant —getConstantNames()
Returns all constant names.
public
getConstantNames() : Set
Return values
Set —getConstants()
Returns all constants.
public
getConstants() : Map
Return values
Map —getDescription()
Returns this description.
public
getDescription() : string
Return values
string —getDocblock()
Returns the docblock.
public
getDocblock() : Docblock
Return values
Docblock —getInterfaces()
Returns the interfaces.
public
getInterfaces() : Set
Return values
Set —getLongDescription()
Returns the long description.
public
getLongDescription() : string
Return values
string —getMethod()
Returns a method.
public
getMethod(PhpMethod $method) : PhpMethod
Parameters
- $method : PhpMethod
Tags
Return values
PhpMethod —getMethodByName()
Returns amethod.
public
getMethodByName(string $name) : PhpMethod
Parameters
- $name : string
Tags
Return values
PhpMethod —getMethodNames()
Returns all method names.
public
getMethodNames() : Set
Return values
Set —getMethods()
Returns all methods.
public
getMethods() : Map
Return values
Map —collection of methods
getNamespace()
Returns the namespace.
public
getNamespace() : string
Return values
string —getParentClassName()
Returns the parent class name.
public
getParentClassName() : string
Return values
string —getProperties()
Returns a collection of properties.
public
getProperties() : Map
Return values
Map —getProperty()
Returns a property.
public
getProperty(string $name) : PhpProperty
Parameters
- $name : string
-
property name
Tags
Return values
PhpProperty —getPropertyNames()
Returns all property names.
public
getPropertyNames() : Set
Return values
Set —getQualifiedName()
Returns the qualified name.
public
getQualifiedName() : string
Return values
string —getRequiredFiles()
Returns required files.
public
getRequiredFiles() : Set
Return values
Set —collection of filenames
getTraits()
Returns a collection of traits.
public
getTraits() : Set
Return values
Set —getUseAlias()
Returns the usable alias for a qualified name.
public
getUseAlias(string $qualifiedName) : string
Parameters
- $qualifiedName : string
Return values
string —the alias
getUseStatements()
Returns all use statements.
public
getUseStatements() : Map
Return values
Map —collection of use statements
hasConstant()
Checks whether a constant exists.
public
hasConstant(PhpConstant $constant) : bool
Parameters
- $constant : PhpConstant
Return values
bool —hasConstantByName()
Checks whether a constant exists.
public
hasConstantByName(string $name) : bool
Parameters
- $name : string
-
constant name
Return values
bool —hasInterface()
Checks whether an interface exists.
public
hasInterface(PhpInterface $interface) : bool
Parameters
- $interface : PhpInterface
Return values
bool —hasInterfaceByName()
Checks whether an interface exists.
public
hasInterfaceByName(string $name) : bool
Parameters
- $name : string
-
interface name
Return values
bool —hasInterfaces()
Checks whether interfaces exists.
public
hasInterfaces() : bool
Return values
bool —true
if interfaces are available and false
if not
hasMethod()
Checks whether a method exists or not.
public
hasMethod(PhpMethod $method) : bool
Parameters
- $method : PhpMethod
Return values
bool —true
if it exists and false
if not
hasMethodByName()
Checks whether a method exists or not.
public
hasMethodByName(string $name) : bool
Parameters
- $name : string
Return values
bool —hasProperty()
Checks whether a property exists.
public
hasProperty(PhpProperty $property) : bool
Parameters
- $property : PhpProperty
Return values
bool —true
if a property exists and false
if not
hasPropertyByName()
Checks whether a property exists.
public
hasPropertyByName(string $name) : bool
Parameters
- $name : string
-
property name
Return values
bool —true
if a property exists and false
if not
hasTrait()
Checks whether a trait exists.
public
hasTrait(PhpTrait $trait) : bool
Parameters
- $trait : PhpTrait
Return values
bool —true
if it exists and false
if not
hasTraitByName()
Checks whether a trait exists.
public
hasTraitByName(string $name) : bool
Parameters
- $name : string
Tags
Return values
bool —true
if it exists and false
if not
hasUseStatement()
Returns whether the given use statement is present.
public
hasUseStatement(string $qualifiedName) : bool
Parameters
- $qualifiedName : string
Return values
bool —isAbstract()
Returns whether this is abstract.
public
isAbstract() : bool
Return values
bool —true
for abstract and false
if not
isFinal()
Returns whether this is final.
public
isFinal() : bool
Return values
bool —true
for final and false
if not
removeConstant()
Removes a constant.
public
removeConstant(PhpConstant $constant) : $this
Parameters
- $constant : PhpConstant
Tags
Return values
$this —removeConstantByName()
Removes a constant.
public
removeConstantByName(string $name) : $this
Parameters
- $name : string
-
constant name
Tags
Return values
$this —removeInterface()
Removes an interface.
public
removeInterface(PhpInterface $interface) : $this
If the interface is passed as PhpInterface object, the interface is also remove from the use statements.
Parameters
- $interface : PhpInterface
-
interface or qualified name
Return values
$this —removeInterfaceByName()
Removes an interface.
public
removeInterfaceByName(string $name) : $this
If the interface is passed as PhpInterface object, the interface is also remove from the use statements.
Parameters
- $name : string
-
interface qualified name
Return values
$this —removeMethod()
Removes a method.
public
removeMethod(PhpMethod $method) : $this
Parameters
- $method : PhpMethod
-
Method instance
Return values
$this —removeMethodByName()
Removes a method.
public
removeMethodByName(string $name) : $this
Parameters
- $name : string
-
method name or Method instance
Tags
Return values
$this —removeProperty()
Removes a property.
public
removeProperty(PhpProperty $property) : $this
Parameters
- $property : PhpProperty
Tags
Return values
$this —removePropertyByName()
Removes a property.
public
removePropertyByName(string $name) : $this
Parameters
- $name : string
-
property name
Tags
Return values
$this —removeTrait()
Removes a trait.
public
removeTrait(PhpTrait $trait) : $this
If the trait is passed as PhpTrait object, the trait is also removed from use statements.
Parameters
- $trait : PhpTrait
-
trait or qualified name
Return values
$this —removeTraitByName()
Removes a trait.
public
removeTraitByName(string $traitName) : $this
If the trait is passed as PhpTrait object, the trait is also removed from use statements.
Parameters
- $traitName : string
-
trait qualified name
Tags
Return values
$this —removeUseStatement()
Removes a use statement.
public
removeUseStatement(string $qualifiedName) : $this
Parameters
- $qualifiedName : string
Return values
$this —setAbstract()
Sets this to abstract.
public
setAbstract(bool $bool) : $this
Parameters
- $bool : bool
-
true
for abstract andfalse
if not
Return values
$this —setConstant()
Add a PhpConstant object.
public
setConstant(PhpConstant $constant) : $this
Parameters
- $constant : PhpConstant
Return values
$this —setConstantByName()
Create a PhpConstant instance and adds it to the constants Map.
public
setConstantByName(string $name[, mixed $value = null ][, bool $isExpression = false ]) : $this
Parameters
- $name : string
-
constant name
- $value : mixed = null
- $isExpression : bool = false
Return values
$this —setConstants()
Sets a collection of constants.
public
setConstants(array<string|int, mixed>|array<string|int, PhpConstant> $constants) : $this
Parameters
- $constants : array<string|int, mixed>|array<string|int, PhpConstant>
Return values
$this —setDescription()
Sets the description, which will also be used when generating a docblock.
public
setDescription(string $description) : $this
Parameters
- $description : string
Return values
$this —setDocblock()
Sets the docblock.
public
setDocblock(Docblock|string $doc) : $this
Parameters
- $doc : Docblock|string
Return values
$this —setFinal()
Sets this final.
public
setFinal(bool $bool) : $this
Parameters
- $bool : bool
-
true
for final andfalse
if not
Return values
$this —setInterfaces()
Sets a collection of interfaces.
public
setInterfaces(array<string|int, PhpInterface> $interfaces) : $this
Parameters
- $interfaces : array<string|int, PhpInterface>
Return values
$this —setLongDescription()
Sets the long description.
public
setLongDescription(string $longDescription) : $this
Parameters
- $longDescription : string
Return values
$this —setMethod()
Adds a method.
public
setMethod(PhpMethod $method) : $this
Parameters
- $method : PhpMethod
Return values
$this —setMethods()
Sets a collection of methods.
public
setMethods(array<string|int, PhpMethod> $methods) : $this
Parameters
- $methods : array<string|int, PhpMethod>
Return values
$this —setMultilineDescription()
Sets a multi-line description, which will also be used when generating a docblock.
public
setMultilineDescription(array<string|int, mixed> $description) : $this
Each line is a value of the $description
array.
Parameters
- $description : array<string|int, mixed>
Return values
$this —setNamespace()
Sets the namespace.
public
setNamespace(string $namespace) : $this
Parameters
- $namespace : string
Return values
$this —setParentClassName()
Sets the parent class name.
public
setParentClassName([string $name = '' ]) : $this
Parameters
- $name : string = ''
-
the new parent
Return values
$this —setProperties()
Sets a collection of properties.
public
setProperties(array<string|int, PhpProperty> $properties) : $this
Parameters
- $properties : array<string|int, PhpProperty>
Return values
$this —setProperty()
Adds a property.
public
setProperty(PhpProperty $property) : $this
Parameters
- $property : PhpProperty
Return values
$this —setQualifiedName()
In contrast to setName(), this method accepts the fully qualified name including the namespace.
public
setQualifiedName(string $name) : $this
Parameters
- $name : string
Return values
$this —setRequiredFiles()
Sets requried files.
public
setRequiredFiles(array<string|int, mixed> $files) : $this
Parameters
- $files : array<string|int, mixed>
Return values
$this —setTraits()
Sets a collection of traits.
public
setTraits(array<string|int, mixed> $traits) : $this
Parameters
- $traits : array<string|int, mixed>
Tags
Return values
$this —setUseStatements()
Sets use statements.
public
setUseStatements(array<string|int, mixed> $useStatements) : $this
Parameters
- $useStatements : array<string|int, mixed>
Tags
Return values
$this —initConstants()
private
initConstants() : void
Return values
void —initInterfaces()
private
initInterfaces() : void
Return values
void —initProperties()
private
initProperties() : void
Return values
void —initTraits()
private
initTraits() : void