class ClassGenerator

The ClassGenerator generates PHP classes for entries.

ClassGenerator can easily be customized by overwriting some of the protected methods. Do note, that there is not backwards compatibility promise for override any method but getClassName.

Properties

protected $spaces
static protected $classTemplate

Methods

__construct()

ClassGenerator constructor.

string
generateEntryClass(ContentType $contentType)

Generate a class for entries of the provided ContentType.

string
generateUseStatement(ContentType $contentType)

Generate the use statements.

string
generateClassName(ContentType $contentType)

Generate the class declaration

string
generateClassBody(ContentType $contentType)

Generate the class body.

string
getPropertyName(ContentTypeField $field)

Get the name of the property of the given field.

string
getPropertyDocBlockType(ContentTypeField $field)

Get the docblock for the property of the given field.

string
getMethodDocBlockType(ContentTypeField $field)

Get the docblock for the getter method for the given field.

string
generateProperty(ContentTypeField $field)

Generate the property of the given field.

string
generateConstructor(ContentType $contentType)

Generate the Constructor.

string
generateJsonSerialize(ContentType $contentType)

Generate the jsonSerialize function.

bool
isSimpleType(string $type)

Returns true if the type does not need any further processing.

string
generateMethod(ContentTypeField $field)

Generate the getter method for the field.

string
generateSimpleMethodBody(ContentTypeField $field)

Generate the getter method body in simple cases.

string
generateLinkMethodBody(ContentTypeField $field)

Generate the getter method body for links.

string
generateArrayMethodBody(ContentTypeField $field)

Generate the getter method body for arrays.

string
generateIdMethod(ContentTypeField $field)

Fields that reference links (or arrays of links) also get a method to get just the ID.

string
getClassName(ContentType $contentType)

Get the class name for and entry of the provided ContentType.

Details

at line 41
__construct()

ClassGenerator constructor.

Empty constructor provided for forward compatability.

at line 54
string generateEntryClass(ContentType $contentType)

Generate a class for entries of the provided ContentType.

Parameters

ContentType $contentType

Return Value

string

at line 80
protected string generateUseStatement(ContentType $contentType)

Generate the use statements.

Parameters

ContentType $contentType

Return Value

string

at line 105
protected string generateClassName(ContentType $contentType)

Generate the class declaration

Parameters

ContentType $contentType

Return Value

string

at line 117
protected string generateClassBody(ContentType $contentType)

Generate the class body.

Parameters

ContentType $contentType

Return Value

string

at line 147
protected string getPropertyName(ContentTypeField $field)

Get the name of the property of the given field.

Parameters

ContentTypeField $field

Return Value

string

at line 159
protected string getPropertyDocBlockType(ContentTypeField $field)

Get the docblock for the property of the given field.

Parameters

ContentTypeField $field

Return Value

string

at line 175
protected string getMethodDocBlockType(ContentTypeField $field)

Get the docblock for the getter method for the given field.

Parameters

ContentTypeField $field

Return Value

string

at line 222
protected string generateProperty(ContentTypeField $field)

Generate the property of the given field.

Parameters

ContentTypeField $field

Return Value

string

at line 240
protected string generateConstructor(ContentType $contentType)

Generate the Constructor.

Parameters

ContentType $contentType

Return Value

string

at line 275
protected string generateJsonSerialize(ContentType $contentType)

Generate the jsonSerialize function.

Parameters

ContentType $contentType

Return Value

string

at line 377
protected bool isSimpleType(string $type)

Returns true if the type does not need any further processing.

Parameters

string $type

Return Value

bool

at line 388
protected string generateMethod(ContentTypeField $field)

Generate the getter method for the field.

Parameters

ContentTypeField $field

Return Value

string

at line 423
protected string generateSimpleMethodBody(ContentTypeField $field)

Generate the getter method body in simple cases.

Parameters

ContentTypeField $field

Return Value

string

at line 444
protected string generateLinkMethodBody(ContentTypeField $field)

Generate the getter method body for links.

Parameters

ContentTypeField $field

Return Value

string

at line 470
protected string generateArrayMethodBody(ContentTypeField $field)

Generate the getter method body for arrays.

Parameters

ContentTypeField $field

Return Value

string

at line 505
protected string generateIdMethod(ContentTypeField $field)

Fields that reference links (or arrays of links) also get a method to get just the ID.

Parameters

ContentTypeField $field

Return Value

string

at line 562
string getClassName(ContentType $contentType)

Get the class name for and entry of the provided ContentType.

Parameters

ContentType $contentType

Return Value

string