class PhpClass extends AbstractPhpStruct implements GenerateableInterface, TraitsInterface, ConstantsInterface, PropertiesInterface

Represents a PHP class.

Traits

Abstract Part
Constants part
Abstract Part
Interfaces part
Properties part
Traits part
Docblock Part
Long description part
Qualified name part
Name part

Methods

string
getDescription()

Returns this description

$this
setDescription(string|array $description)

Sets the description, which will also be used when generating a docblock

$this
setDocblock(Docblock|string $doc)

Sets the docblock

Docblock
getDocblock()

Returns the docblock

string
getLongDescription()

Returns the long description

$this
setLongDescription(string $longDescription)

Sets the long description

$this
setName(string $name)

Sets the name

from NamePart
string
getName()

Returns the name

from NamePart
$this
setNamespace(string $namespace)

Sets the namespace

$this
setQualifiedName(string $name)

In contrast to setName(), this method accepts the fully qualified name including the namespace.

string
getNamespace()

Returns the namespace

string
getQualifiedName()

Returns the qualified name

create(string $name = null)

Creates a new struct

__construct(string $name = null)

Creates a new PHP class

$this
setRequiredFiles(array $files)

Sets requried files

$this
addRequiredFile(string $file)

Adds a new required file

Set
getRequiredFiles()

Returns required files

$this
setUseStatements(array $useStatements)

Sets use statements

$this
addUseStatement(string $qualifiedName, null|string $alias = null)

Adds a use statement with an optional alias

$this
clearUseStatements()

Clears all use statements

$this
declareUses()

Declares multiple use statements at once.

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.

bool
hasUseStatement(string $qualifiedName)

Returns whether the given use statement is present

string
getUseAlias(string $qualifiedName)

Returns the usable alias for a qualified name

$this
removeUseStatement(string $qualifiedName)

Removes a use statement

Map
getUseStatements()

Returns all use statements

$this
setMethods(array $methods)

Sets a collection of methods

$this
setMethod(PhpMethod $method)

Adds a method

$this
removeMethod(string|PhpMethod $nameOrMethod)

Removes a method

bool
hasMethod(string|PhpMethod $nameOrMethod)

Checks whether a method exists or not

getMethod(string $nameOrMethod)

Returns a method

Map
getMethods()

Returns all methods

Set
getMethodNames()

Returns all method names

$this
clearMethods()

Clears all methods

$this
generateDocblock()

Generates a docblock from provided information

bool
isAbstract()

Returns whether this is abstract

$this
setAbstract(bool $bool)

Sets this to abstract

$this
setConstants(array $constants)

Sets a collection of constants

$this
setConstant($nameOrConstant, $value = null, $isExpression = false)

Adds a constant

$this
removeConstant(string|PhpConstant $nameOrConstant)

Removes a constant

bool
hasConstant(string|PhpConstant $nameOrConstant)

Checks whether a constant exists

getConstant(string|PhpConstant $nameOrConstant)

Returns a constant.

Map
getConstants()

Returns all constants

Set
getConstantNames()

Returns all constant names

$this
clearConstants()

Clears all constants

bool
isFinal()

Returns whether this is final

from FinalPart
$this
setFinal(bool $bool)

Sets this final

from FinalPart
$this
addInterface(PhpInterface|string $interface)

Adds an interface.

Set
getInterfaces()

Returns the interfaces

bool
hasInterfaces()

Checks whether interfaces exists

bool
hasInterface(PhpInterface|string $interface)

Checks whether an interface exists

$this
removeInterface(PhpInterface|string $interface)

Removes an interface.

$this
setInterfaces(array $interfaces)

Sets a collection of interfaces

$this
setProperties(array $properties)

Sets a collection of properties

$this
setProperty(PhpProperty $property)

Adds a property

$this
removeProperty(PhpProperty|string $nameOrProperty)

Removes a property

bool
hasProperty(PhpProperty|string $nameOrProperty)

Checks whether a property exists

getProperty(string $nameOrProperty)

Returns a property

Map
getProperties()

Returns a collection of properties

Set
getPropertyNames()

Returns all property names

$this
clearProperties()

Clears all properties

$this
addTrait(PhpTrait|string $trait)

Adds a trait.

string[]
getTraits()

Returns a collection of traits

bool
hasTrait(PhpTrait|string $trait)

Checks whether a trait exists

$this
removeTrait(PhpTrait|string $trait)

Removes a trait.

$this
setTraits(array $traits)

Sets a collection of traits

static PhpClass
fromReflection(ReflectionClass $ref) deprecated

Creates a PHP class from reflection

static PhpClass
fromFile(string $filename)

Creates a PHP class from file

string
getParentClassName()

Returns the parent class name

$this
setParentClassName(string|null $name)

Sets the parent class name

Details

in AbstractModel at line line 19
string getDescription()

Returns this description

Return Value

string

in AbstractModel at line line 29
$this setDescription(string|array $description)

Sets the description, which will also be used when generating a docblock

Parameters

string|array $description

Return Value

$this

in DocblockPart at line line 24
$this setDocblock(Docblock|string $doc)

Sets the docblock

Parameters

Docblock|string $doc

Return Value

$this

in DocblockPart at line line 39
Docblock getDocblock()

Returns the docblock

Return Value

Docblock

in LongDescriptionPart at line line 21
string getLongDescription()

Returns the long description

Return Value

string

in LongDescriptionPart at line line 31
$this setLongDescription(string $longDescription)

Sets the long description

Parameters

string $longDescription

Return Value

$this

in NamePart at line line 22
$this setName(string $name)

Sets the name

Parameters

string $name

Return Value

$this

in NamePart at line line 33
string getName()

Returns the name

Return Value

string

in QualifiedNamePart at line line 24
$this setNamespace(string $namespace)

Sets the namespace

Parameters

string $namespace

Return Value

$this

in QualifiedNamePart at line line 37
$this setQualifiedName(string $name)

In contrast to setName(), this method accepts the fully qualified name including the namespace.

Parameters

string $name

Return Value

$this

in QualifiedNamePart at line line 56
string getNamespace()

Returns the namespace

Return Value

string

in QualifiedNamePart at line line 65
string getQualifiedName()

Returns the qualified name

Return Value

string

in AbstractPhpStruct at line line 53
static AbstractPhpStruct create(string $name = null)

Creates a new struct

Parameters

string $name the fqcn

Return Value

AbstractPhpStruct

at line line 67
__construct(string $name = null)

Creates a new PHP class

Parameters

string $name the fqcn

in AbstractPhpStruct at line line 76
$this setRequiredFiles(array $files)

Sets requried files

Parameters

array $files

Return Value

$this

in AbstractPhpStruct at line line 88
$this addRequiredFile(string $file)

Adds a new required file

Parameters

string $file

Return Value

$this

in AbstractPhpStruct at line line 99
Set getRequiredFiles()

Returns required files

Return Value

Set collection of filenames

in AbstractPhpStruct at line line 111
$this setUseStatements(array $useStatements)

Sets use statements

Parameters

array $useStatements

Return Value

$this

See also

#addUseStatement
#declareUses()

in TraitsPart at line line 25
abstract $this addUseStatement(string $qualifiedName, null|string $alias = null)

Adds a use statement with an optional alias

Parameters

string $qualifiedName
null|string $alias

Return Value

$this

in AbstractPhpStruct at line line 146
$this clearUseStatements()

Clears all use statements

Return Value

$this

in AbstractPhpStruct at line line 158
$this declareUses()

Declares multiple use statements at once.

Return Value

$this

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.

Parameters

string $qualifiedName
null|string $alias

Return Value

string the used alias

in AbstractPhpStruct at line line 190
bool hasUseStatement(string $qualifiedName)

Returns whether the given use statement is present

Parameters

string $qualifiedName

Return Value

bool

in AbstractPhpStruct at line line 200
string getUseAlias(string $qualifiedName)

Returns the usable alias for a qualified name

Parameters

string $qualifiedName

Return Value

string the alias

in TraitsPart at line line 33
abstract $this removeUseStatement(string $qualifiedName)

Removes a use statement

Parameters

string $qualifiedName

Return Value

$this

in AbstractPhpStruct at line line 220
Map getUseStatements()

Returns all use statements

Return Value

Map collection of use statements

in AbstractPhpStruct at line line 230
$this setMethods(array $methods)

Sets a collection of methods

Parameters

array $methods

Return Value

$this

in AbstractPhpStruct at line line 249
$this setMethod(PhpMethod $method)

Adds a method

Parameters

PhpMethod $method

Return Value

$this

in AbstractPhpStruct at line line 263
$this removeMethod(string|PhpMethod $nameOrMethod)

Removes a method

Parameters

string|PhpMethod $nameOrMethod method name or Method instance

Return Value

$this

Exceptions

InvalidArgumentException if the method cannot be found

in AbstractPhpStruct at line line 284
bool hasMethod(string|PhpMethod $nameOrMethod)

Checks whether a method exists or not

Parameters

string|PhpMethod $nameOrMethod method name or Method instance

Return Value

bool true if it exists and false if not

in AbstractPhpStruct at line line 299
PhpMethod getMethod(string $nameOrMethod)

Returns a method

Parameters

string $nameOrMethod the methods name

Return Value

PhpMethod

Exceptions

InvalidArgumentException if the method cannot be found

in AbstractPhpStruct at line line 316
Map getMethods()

Returns all methods

Return Value

Map collection of methods

in AbstractPhpStruct at line line 325
Set getMethodNames()

Returns all method names

Return Value

Set

in AbstractPhpStruct at line line 334
$this clearMethods()

Clears all methods

Return Value

$this

at line line 95
$this generateDocblock()

Generates a docblock from provided information

Return Value

$this

in AbstractPart at line line 21
bool isAbstract()

Returns whether this is abstract

Return Value

bool true for abstract and false if not

in AbstractPart at line line 31
$this setAbstract(bool $bool)

Sets this to abstract

Parameters

bool $bool true for abstract and false if not

Return Value

$this

in ConstantsPart at line line 30
$this setConstants(array $constants)

Sets a collection of constants

Parameters

array $constants

Return Value

$this

in ConstantsPart at line line 56
$this setConstant($nameOrConstant, $value = null, $isExpression = false)

Adds a constant

Parameters

$nameOrConstant
$value
$isExpression

Return Value

$this

in ConstantsPart at line line 77
$this removeConstant(string|PhpConstant $nameOrConstant)

Removes a constant

Parameters

string|PhpConstant $nameOrConstant constant name

Return Value

$this

Exceptions

InvalidArgumentException If the constant cannot be found

in ConstantsPart at line line 97
bool hasConstant(string|PhpConstant $nameOrConstant)

Checks whether a constant exists

Parameters

string|PhpConstant $nameOrConstant

Return Value

bool

in ConstantsPart at line line 112
PhpConstant getConstant(string|PhpConstant $nameOrConstant)

Returns a constant.

Parameters

string|PhpConstant $nameOrConstant

Return Value

PhpConstant

Exceptions

InvalidArgumentException If the constant cannot be found

in ConstantsPart at line line 129
Map getConstants()

Returns all constants

Return Value

Map

in ConstantsPart at line line 138
Set getConstantNames()

Returns all constant names

Return Value

Set

in ConstantsPart at line line 147
$this clearConstants()

Clears all constants

Return Value

$this

in FinalPart at line line 21
bool isFinal()

Returns whether this is final

Return Value

bool true for final and false if not

in FinalPart at line line 31
$this setFinal(bool $bool)

Sets this final

Parameters

bool $bool true for final and false if not

Return Value

$this

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.

Parameters

PhpInterface|string $interface interface or qualified name

Return Value

$this

in InterfacesPart at line line 79
Set getInterfaces()

Returns the interfaces

Return Value

Set

in InterfacesPart at line line 88
bool hasInterfaces()

Checks whether interfaces exists

Return Value

bool true if interfaces are available and false if not

in InterfacesPart at line line 98
bool hasInterface(PhpInterface|string $interface)

Checks whether an interface exists

Parameters

PhpInterface|string $interface interface name or instance

Return Value

bool

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.

Parameters

PhpInterface|string $interface interface or qualified name

Return Value

$this

in InterfacesPart at line line 137
$this setInterfaces(array $interfaces)

Sets a collection of interfaces

Parameters

array $interfaces

Return Value

$this

in PropertiesPart at line line 29
$this setProperties(array $properties)

Sets a collection of properties

Parameters

array $properties

Return Value

$this

in PropertiesPart at line line 49
$this setProperty(PhpProperty $property)

Adds a property

Parameters

PhpProperty $property

Return Value

$this

in PropertiesPart at line line 63
$this removeProperty(PhpProperty|string $nameOrProperty)

Removes a property

Parameters

PhpProperty|string $nameOrProperty property name or instance

Return Value

$this

Exceptions

InvalidArgumentException If the property cannot be found

in PropertiesPart at line line 84
bool hasProperty(PhpProperty|string $nameOrProperty)

Checks whether a property exists

Parameters

PhpProperty|string $nameOrProperty property name or instance

Return Value

bool true if a property exists and false if not

in PropertiesPart at line line 99
PhpProperty getProperty(string $nameOrProperty)

Returns a property

Parameters

string $nameOrProperty property name

Return Value

PhpProperty

Exceptions

InvalidArgumentException If the property cannot be found

in PropertiesPart at line line 116
Map getProperties()

Returns a collection of properties

Return Value

Map

in PropertiesPart at line line 125
Set getPropertyNames()

Returns all property names

Return Value

Set

in PropertiesPart at line line 134
$this clearProperties()

Clears all properties

Return Value

$this

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.

Parameters

PhpTrait|string $trait trait or qualified name

Return Value

$this

in TraitsPart at line line 76
string[] getTraits()

Returns a collection of traits

Return Value

string[]

in TraitsPart at line line 86
bool hasTrait(PhpTrait|string $trait)

Checks whether a trait exists

Parameters

PhpTrait|string $trait

Return Value

bool true if it exists and false if not

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.

Parameters

PhpTrait|string $trait trait or qualified name

Return Value

$this

in TraitsPart at line line 129
$this setTraits(array $traits)

Sets a collection of traits

Parameters

array $traits

Return Value

$this

at line line 40
static PhpClass fromReflection(ReflectionClass $ref) deprecated

deprecated Use fromFile() instead

Creates a PHP class from reflection

Parameters

ReflectionClass $ref

Return Value

PhpClass

at line line 50
static PhpClass fromFile(string $filename)

Creates a PHP class from file

Parameters

string $filename

Return Value

PhpClass

at line line 79
string getParentClassName()

Returns the parent class name

Return Value

string

at line line 89
$this setParentClassName(string|null $name)

Sets the parent class name

Parameters

string|null $name the new parent

Return Value

$this