mediatekformation

EntityGenerator
in package

Generic class used to generate PHP5 entity classes from ClassMetadataInfo instances.

[php] $classes = $em->getClassMetadataFactory()->getAllMetadata();

$generator = new \Doctrine\ORM\Tools\EntityGenerator(); $generator->setGenerateAnnotations(true); $generator->setGenerateStubMethods(true); $generator->setRegenerateEntityIfExists(false); $generator->setUpdateEntityIfExists(true); $generator->generate($classes, '/path/to/generate/entities');

Tags
deprecated
2.7

This class is being removed from the ORM and won't have any replacement

link
www.doctrine-project.org

Table of Contents

FIELD_VISIBLE_PRIVATE  = 'private'
Specifies class fields should be private.
FIELD_VISIBLE_PROTECTED  = 'protected'
Specifies class fields should be protected.
$addMethodTemplate  : string
$annotationsPrefix  : string
$backupExisting  : bool
$changeTrackingPolicyMap  : mixed
Hash-map to handle the change tracking policy string.
$classTemplate  : string
$classToExtend  : string
The class all generated entities should extend.
$constructorMethodTemplate  : string
$embeddableConstructorMethodTemplate  : string
$embeddablesImmutable  : bool
Whether or not to make generated embeddables immutable.
$extension  : string
The extension to use for written php files.
$fieldVisibility  : string
Visibility of the field
$generateAnnotations  : bool
Whether or not to generation annotations.
$generateEntityStubMethods  : bool
Whether or not to generate sub methods.
$generatorStrategyMap  : mixed
Hash-map to handle generator types string.
$getMethodTemplate  : string
$inflector  : Inflector
$inheritanceTypeMap  : mixed
Hash-map to handle the inheritance type string.
$isNew  : bool
Whether or not the current ClassMetadataInfo instance is new or old.
$lifecycleCallbackMethodTemplate  : string
$numSpaces  : int
Number of spaces to use for indention in generated code.
$regenerateEntityIfExists  : bool
Whether or not to re-generate entity class if it exists already.
$removeMethodTemplate  : string
$setMethodTemplate  : string
$spaces  : string
The actual spaces to use for indention.
$staticReflection  : array<string|int, mixed>
$typeAlias  : mixed
Hash-map for handle types.
$updateEntityIfExists  : bool
Whether or not to update the entity class if it exists already.
__construct()  : mixed
generate()  : void
Generates and writes entity classes for the given array of ClassMetadataInfo instances.
generateEntityClass()  : string
Generates a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance.
generateUpdatedEntityClass()  : string
Generates the updated code for the given ClassMetadataInfo and entity at path.
setAnnotationPrefix()  : void
Sets an annotation prefix.
setBackupExisting()  : void
Should an existing entity be backed up if it already exists?
setClassToExtend()  : void
Sets the name of the class the generated classes should extend from.
setEmbeddablesImmutable()  : void
Sets whether or not to generate immutable embeddables.
setExtension()  : void
Sets the extension to use when writing php files to disk.
setFieldVisibility()  : void
Sets the class fields visibility for the entity (can either be private or protected).
setGenerateAnnotations()  : void
Sets whether or not to generate annotations for the entity.
setGenerateStubMethods()  : void
Sets whether or not to generate stub methods for the entity.
setInflector()  : void
setNumSpaces()  : void
Sets the number of spaces the exported class should have.
setRegenerateEntityIfExists()  : void
Sets whether or not to regenerate the entity if it exists.
setUpdateEntityIfExists()  : void
Sets whether or not to try and update the entity if it already exists.
writeEntityClass()  : void
Generates and writes entity class to disk for the given ClassMetadataInfo instance.
extendsClass()  : bool
generateAssociationMappingPropertyDocBlock()  : string
generateDiscriminatorColumnAnnotation()  : string
generateDiscriminatorMapAnnotation()  : string|null
generateEmbeddedPropertyDocBlock()  : string
generateEntityAnnotation()  : string
generateEntityAssociationMappingProperties()  : string
generateEntityBody()  : string
generateEntityClassName()  : string
generateEntityConstructor()  : string
generateEntityDocBlock()  : string
generateEntityEmbeddedProperties()  : string
generateEntityFieldMappingProperties()  : string
generateEntityLifecycleCallbackMethods()  : string
generateEntityNamespace()  : string
generateEntityStubMethod()  : string
generateEntityStubMethods()  : string
generateEntityUse()  : string
generateFieldMappingPropertyDocBlock()  : string
generateInheritanceAnnotation()  : string
generateJoinColumnAnnotation()  : string
generateLifecycleCallbackMethod()  : string
generateTableAnnotation()  : string
generateTableConstraints()  : string
getChangeTrackingPolicyString()  : string
getClassName()  : string
getClassToExtend()  : string
getClassToExtendName()  : string
getIdGeneratorTypeString()  : string
getInheritanceTypeString()  : string
getNamespace()  : string
getTraits()  : array<string|int, ReflectionClass>
getType()  : string
hasMethod()  : bool
hasNamespace()  : bool
hasProperty()  : bool
isAssociationIsNullable()  : bool
parseTokensInEntityFile()  : void
prefixCodeWithSpaces()  : string
exportTableOptions()  : string
Exports (nested) option elements.
generateEmbeddableConstructor()  : string
generateEntityListenerAnnotation()  : string
nullableFieldExpression()  : string|null

Constants

FIELD_VISIBLE_PRIVATE

Specifies class fields should be private.

public mixed FIELD_VISIBLE_PRIVATE = 'private'

FIELD_VISIBLE_PROTECTED

Specifies class fields should be protected.

public mixed FIELD_VISIBLE_PROTECTED = 'protected'

Properties

$addMethodTemplate

protected static string $addMethodTemplate = '/** * <description> * * @param <variableType> $<variableName> * * @return <entity> */ public function <methodName>(<methodTypeHint>$<variableName>) { <spaces>$this-><fieldName>[] = $<variableName>; <spaces>return $this; }'

$changeTrackingPolicyMap

Hash-map to handle the change tracking policy string.

protected static mixed $changeTrackingPolicyMap = [\Doctrine\ORM\Mapping\ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT => 'DEFERRED_IMPLICIT', \Doctrine\ORM\Mapping\ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT => 'DEFERRED_EXPLICIT', \Doctrine\ORM\Mapping\ClassMetadataInfo::CHANGETRACKING_NOTIFY => 'NOTIFY']
Tags
psalm-var

array<ClassMetadataInfo::CHANGETRACKING_*, string>

$classTemplate

protected static string $classTemplate = '<?php <namespace> <useStatement> <entityAnnotation> <entityClassName> { <entityBody> } '

$classToExtend

The class all generated entities should extend.

protected string $classToExtend

$constructorMethodTemplate

protected static string $constructorMethodTemplate = '/** * Constructor */ public function __construct() { <spaces><collections> } '

$embeddableConstructorMethodTemplate

protected static string $embeddableConstructorMethodTemplate = '/** * Constructor * * <paramTags> */ public function __construct(<params>) { <spaces><fields> } '

$embeddablesImmutable

Whether or not to make generated embeddables immutable.

protected bool $embeddablesImmutable = false

$extension

The extension to use for written php files.

protected string $extension = '.php'

$fieldVisibility

Visibility of the field

protected string $fieldVisibility = 'private'

$generateAnnotations

Whether or not to generation annotations.

protected bool $generateAnnotations = false

$generateEntityStubMethods

Whether or not to generate sub methods.

protected bool $generateEntityStubMethods = false

$generatorStrategyMap

Hash-map to handle generator types string.

protected static mixed $generatorStrategyMap = [\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO => 'AUTO', \Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE => 'SEQUENCE', \Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_IDENTITY => 'IDENTITY', \Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_NONE => 'NONE', \Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_UUID => 'UUID', \Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_CUSTOM => 'CUSTOM']
Tags
psalm-var

array<ClassMetadataInfo::GENERATOR_TYPE_*, string>

$getMethodTemplate

protected static string $getMethodTemplate = '/** * <description> * * @return <variableType> */ public function <methodName>() { <spaces>return $this-><fieldName>; }'

$inheritanceTypeMap

Hash-map to handle the inheritance type string.

protected static mixed $inheritanceTypeMap = [\Doctrine\ORM\Mapping\ClassMetadataInfo::INHERITANCE_TYPE_NONE => 'NONE', \Doctrine\ORM\Mapping\ClassMetadataInfo::INHERITANCE_TYPE_JOINED => 'JOINED', \Doctrine\ORM\Mapping\ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE => 'SINGLE_TABLE', \Doctrine\ORM\Mapping\ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS => 'TABLE_PER_CLASS']
Tags
psalm-var

array<ClassMetadataInfo::INHERITANCE_TYPE_*, string>

$isNew

Whether or not the current ClassMetadataInfo instance is new or old.

protected bool $isNew = true

$lifecycleCallbackMethodTemplate

protected static string $lifecycleCallbackMethodTemplate = '/** * @<name> */ public function <methodName>() { <spaces>// Add your code here }'

$numSpaces

Number of spaces to use for indention in generated code.

protected int $numSpaces = 4

$regenerateEntityIfExists

Whether or not to re-generate entity class if it exists already.

protected bool $regenerateEntityIfExists = false

$removeMethodTemplate

protected static string $removeMethodTemplate = '/** * <description> * * @param <variableType> $<variableName> * * @return boolean TRUE if this collection contained the specified element, FALSE otherwise. */ public function <methodName>(<methodTypeHint>$<variableName>) { <spaces>return $this-><fieldName>->removeElement($<variableName>); }'

$setMethodTemplate

protected static string $setMethodTemplate = '/** * <description> * * @param <variableType> $<variableName> * * @return <entity> */ public function <methodName>(<methodTypeHint>$<variableName><variableDefault>) { <spaces>$this-><fieldName> = $<variableName>; <spaces>return $this; }'

$spaces

The actual spaces to use for indention.

protected string $spaces = ' '

$staticReflection

protected array<string|int, mixed> $staticReflection = []

$typeAlias

Hash-map for handle types.

protected mixed $typeAlias = [\Doctrine\DBAL\Types\Types::DATETIMETZ_MUTABLE => '\\DateTime', \Doctrine\DBAL\Types\Types::DATETIME_MUTABLE => '\\DateTime', \Doctrine\DBAL\Types\Types::DATE_MUTABLE => '\\DateTime', \Doctrine\DBAL\Types\Types::TIME_MUTABLE => '\\DateTime', \Doctrine\DBAL\Types\Types::OBJECT => '\\stdClass', \Doctrine\DBAL\Types\Types::INTEGER => 'int', \Doctrine\DBAL\Types\Types::BIGINT => 'int', \Doctrine\DBAL\Types\Types::SMALLINT => 'int', \Doctrine\DBAL\Types\Types::TEXT => 'string', \Doctrine\DBAL\Types\Types::BLOB => 'string', \Doctrine\DBAL\Types\Types::DECIMAL => 'string', \Doctrine\DBAL\Types\Types::GUID => 'string', 'json_array' => 'array', \Doctrine\DBAL\Types\Types::JSON => 'array', \Doctrine\DBAL\Types\Types::SIMPLE_ARRAY => 'array', \Doctrine\DBAL\Types\Types::BOOLEAN => 'bool']
Tags
psalm-var

array<Types::*|'json_array', string>

$updateEntityIfExists

Whether or not to update the entity class if it exists already.

protected bool $updateEntityIfExists = false

Methods

generate()

Generates and writes entity classes for the given array of ClassMetadataInfo instances.

public generate(array<string|int, mixed> $metadatas, string $outputDirectory) : void
Parameters
$metadatas : array<string|int, mixed>
$outputDirectory : string
Tags
psalm-param

list<ClassMetadataInfo> $metadatas

Return values
void —

generateEntityClass()

Generates a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance.

public generateEntityClass(ClassMetadataInfo $metadata) : string
Parameters
$metadata : ClassMetadataInfo
Return values
string —

generateUpdatedEntityClass()

Generates the updated code for the given ClassMetadataInfo and entity at path.

public generateUpdatedEntityClass(ClassMetadataInfo $metadata, string $path) : string
Parameters
$metadata : ClassMetadataInfo
$path : string
Return values
string —

setAnnotationPrefix()

Sets an annotation prefix.

public setAnnotationPrefix(string $prefix) : void
Parameters
$prefix : string
Return values
void —

setBackupExisting()

Should an existing entity be backed up if it already exists?

public setBackupExisting(bool $bool) : void
Parameters
$bool : bool
Return values
void —

setClassToExtend()

Sets the name of the class the generated classes should extend from.

public setClassToExtend(string $classToExtend) : void
Parameters
$classToExtend : string
Return values
void —

setEmbeddablesImmutable()

Sets whether or not to generate immutable embeddables.

public setEmbeddablesImmutable(bool $embeddablesImmutable) : void
Parameters
$embeddablesImmutable : bool
Return values
void —

setExtension()

Sets the extension to use when writing php files to disk.

public setExtension(string $extension) : void
Parameters
$extension : string
Return values
void —

setFieldVisibility()

Sets the class fields visibility for the entity (can either be private or protected).

public setFieldVisibility(string $visibility) : void
Parameters
$visibility : string
Tags
psalm-param

self::FIELD_VISIBLE_*

throws
InvalidArgumentException
Return values
void —

setGenerateAnnotations()

Sets whether or not to generate annotations for the entity.

public setGenerateAnnotations(bool $bool) : void
Parameters
$bool : bool
Return values
void —

setGenerateStubMethods()

Sets whether or not to generate stub methods for the entity.

public setGenerateStubMethods(bool $bool) : void
Parameters
$bool : bool
Return values
void —

setNumSpaces()

Sets the number of spaces the exported class should have.

public setNumSpaces(int $numSpaces) : void
Parameters
$numSpaces : int
Return values
void —

setRegenerateEntityIfExists()

Sets whether or not to regenerate the entity if it exists.

public setRegenerateEntityIfExists(bool $bool) : void
Parameters
$bool : bool
Return values
void —

setUpdateEntityIfExists()

Sets whether or not to try and update the entity if it already exists.

public setUpdateEntityIfExists(bool $bool) : void
Parameters
$bool : bool
Return values
void —

writeEntityClass()

Generates and writes entity class to disk for the given ClassMetadataInfo instance.

public writeEntityClass(ClassMetadataInfo $metadata, string $outputDirectory) : void
Parameters
$metadata : ClassMetadataInfo
$outputDirectory : string
Tags
throws
RuntimeException
Return values
void —

extendsClass()

protected extendsClass() : bool
Return values
bool —

generateAssociationMappingPropertyDocBlock()

protected generateAssociationMappingPropertyDocBlock(array<string|int, mixed> $associationMapping, ClassMetadataInfo $metadata) : string
Parameters
$associationMapping : array<string|int, mixed>
$metadata : ClassMetadataInfo
Return values
string —

generateEmbeddedPropertyDocBlock()

protected generateEmbeddedPropertyDocBlock(array<string|int, mixed> $embeddedClass) : string
Parameters
$embeddedClass : array<string|int, mixed>
Tags
psalm-param

array<string, mixed> $embeddedClass

Return values
string —

generateEntityStubMethod()

protected generateEntityStubMethod(ClassMetadataInfo $metadata, string $type, string $fieldName[, string|null $typeHint = null ][, string|null $defaultValue = null ]) : string
Parameters
$metadata : ClassMetadataInfo
$type : string
$fieldName : string
$typeHint : string|null = null
$defaultValue : string|null = null
Return values
string —

generateEntityUse()

protected generateEntityUse() : string
Return values
string —

generateFieldMappingPropertyDocBlock()

protected generateFieldMappingPropertyDocBlock(array<string|int, mixed> $fieldMapping, ClassMetadataInfo $metadata) : string
Parameters
$fieldMapping : array<string|int, mixed>
$metadata : ClassMetadataInfo
Return values
string —

generateJoinColumnAnnotation()

protected generateJoinColumnAnnotation(array<string|int, mixed> $joinColumn) : string
Parameters
$joinColumn : array<string|int, mixed>
Tags
psalm-param

array<string, mixed> $joinColumn

Return values
string —

generateLifecycleCallbackMethod()

protected generateLifecycleCallbackMethod(string $name, string $methodName, ClassMetadataInfo $metadata) : string
Parameters
$name : string
$methodName : string
$metadata : ClassMetadataInfo
Return values
string —

generateTableConstraints()

protected generateTableConstraints(string $constraintName, array<string|int, mixed> $constraints) : string
Parameters
$constraintName : string
$constraints : array<string|int, mixed>
Tags
psalm-param

array<string, array<string, mixed>> $constraints

Return values
string —

getChangeTrackingPolicyString()

protected getChangeTrackingPolicyString(int $type) : string
Parameters
$type : int

The policy used for change-tracking for the mapped class.

Tags
throws
InvalidArgumentException

When the change-tracking type does not exist.

Return values
string —

The literal string for the change-tracking type.

getClassToExtend()

protected getClassToExtend() : string
Return values
string —

getClassToExtendName()

protected getClassToExtendName() : string
Return values
string —

getIdGeneratorTypeString()

protected getIdGeneratorTypeString(int $type) : string
Parameters
$type : int

The generator to use for the mapped class.

Tags
throws
InvalidArgumentException

When the generator type does not exist.

Return values
string —

The literal string for the generator type.

getInheritanceTypeString()

protected getInheritanceTypeString(int $type) : string
Parameters
$type : int

The inheritance type used by the class and its subclasses.

Tags
throws
InvalidArgumentException

When the inheritance type does not exist.

Return values
string —

The literal string for the inheritance type.

getTraits()

protected getTraits(ClassMetadataInfo $metadata) : array<string|int, ReflectionClass>
Parameters
$metadata : ClassMetadataInfo
Tags
psalm-return

array<trait-string, ReflectionClass>

throws
ReflectionException
Return values
array<string|int, ReflectionClass> —

getType()

protected getType(string $type) : string
Parameters
$type : string
Return values
string —

isAssociationIsNullable()

protected isAssociationIsNullable(array<string|int, mixed> $associationMapping) : bool
Parameters
$associationMapping : array<string|int, mixed>
Tags
psalm-param

array<string, mixed> $associationMapping

Return values
bool —

parseTokensInEntityFile()

protected parseTokensInEntityFile(string $src) : void
Parameters
$src : string
Tags
todo

this won't work if there is a namespace in brackets and a class outside of it.

psalm-suppress

UndefinedConstant

Return values
void —

prefixCodeWithSpaces()

protected prefixCodeWithSpaces(string $code[, int $num = 1 ]) : string
Parameters
$code : string
$num : int = 1
Return values
string —

exportTableOptions()

Exports (nested) option elements.

private exportTableOptions(array<string|int, mixed> $options) : string
Parameters
$options : array<string|int, mixed>
Tags
psalm-param

array<string, mixed> $options

Return values
string —

nullableFieldExpression()

private nullableFieldExpression(array<string|int, mixed> $fieldMapping) : string|null
Parameters
$fieldMapping : array<string|int, mixed>
Tags
psalm-param

array<string, mixed> $fieldMapping

Return values
string|null —

Search results