Doctrine\ORM\Tools\EntityGenerator
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');
- Author: Benjamin Eberlei <kontakt@beberlei.de>
Synopsis
class EntityGenerator
{
- // constants
- const FIELD_VISIBLE_PROTECTED = 'protected';
- const FIELD_VISIBLE_PRIVATE = 'private';
- // members
- private bool $backupExisting;
- private string $extension;
- private boolean $isNew;
- private array $staticReflection;
- private integer $numSpaces;
- private string $spaces;
- private string $classToExtend;
- private boolean $generateAnnotations;
- private string $annotationsPrefix;
- private boolean $generateEntityStubMethods;
- private boolean $updateEntityIfExists;
- private boolean $regenerateEntityIfExists;
- private string $fieldVisibility;
- private array $typeAlias;
- protected array $generatorStrategyMap;
- protected array $changeTrackingPolicyMap;
- protected array $inheritanceTypeMap;
- private string $classTemplate;
- private string $getMethodTemplate;
- private string $setMethodTemplate;
- private string $addMethodTemplate;
- private string $removeMethodTemplate;
- private string $lifecycleCallbackMethodTemplate;
- private string $constructorMethodTemplate;
- // methods
- public void __construct()
- public void generate()
- public void writeEntityClass()
- public string generateEntityClass()
- public string generateUpdatedEntityClass()
- public void setNumSpaces()
- public void setExtension()
- public void setClassToExtend()
- public void setGenerateAnnotations()
- public void setFieldVisibility()
- public void setAnnotationPrefix()
- public void setUpdateEntityIfExists()
- public void setRegenerateEntityIfExists()
- public void setGenerateStubMethods()
- public void setBackupExisting()
- private string getType()
- private void generateEntityNamespace()
- private void generateEntityClassName()
- private void generateEntityBody()
- private void generateEntityConstructor()
- private void parseTokensInEntityFile()
- private void hasProperty()
- private void hasMethod()
- private void hasNamespace()
- private void extendsClass()
- private void getClassToExtend()
- private void getClassToExtendName()
- private void getClassName()
- private void getNamespace()
- private void generateEntityDocBlock()
- private void generateTableAnnotation()
- private void generateTableConstraints()
- private void generateInheritanceAnnotation()
- private void generateDiscriminatorColumnAnnotation()
- private void generateDiscriminatorMapAnnotation()
- private void generateEntityStubMethods()
- private void isAssociationIsNullable()
- private void generateEntityLifecycleCallbackMethods()
- private void generateEntityAssociationMappingProperties()
- private void generateEntityFieldMappingProperties()
- private void generateEntityStubMethod()
- private void generateLifecycleCallbackMethod()
- private void generateJoinColumnAnnotation()
- private void generateAssociationMappingPropertyDocBlock()
- private void generateFieldMappingPropertyDocBlock()
- private void prefixCodeWithSpaces()
- protected string getInheritanceTypeString()
- protected string getChangeTrackingPolicyString()
- protected string getIdGeneratorTypeString()
Tasks
Line | Task |
---|---|
592+ | this won't work if there is a namespace in brackets and a class outside of it. |
Constants
Name | Value |
---|---|
FIELD_VISIBLE_PROTECTED | 'protected' |
FIELD_VISIBLE_PRIVATE | 'private' |
Members
private
- $addMethodTemplate — string
- $annotationsPrefix — string
- $backupExisting — Doctrine\ORM\Tools\bool
- $classTemplate — string
- $classToExtend
—
string
The class all generated entities should extend - $constructorMethodTemplate — string
- $extension
—
string
The extension to use for written php files - $fieldVisibility — boolean
- $generateAnnotations
—
boolean
Whether or not to generation annotations - $generateEntityStubMethods
—
boolean
Whether or not to generated sub methods - $getMethodTemplate — string
- $isNew
—
boolean
Whether or not the current ClassMetadataInfo instance is new or old - $lifecycleCallbackMethodTemplate — string
-
$numSpaces
Number of spaces to use for indention in generated code - $regenerateEntityIfExists
—
boolean
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
- $typeAlias
—
array
Hash-map for handle types - $updateEntityIfExists
—
boolean
Whether or not to update the entity class if it exists already
protected
- $changeTrackingPolicyMap — array
- $generatorStrategyMap — array
- $inheritanceTypeMap — array
Methods
private
- extendsClass()
- generateAssociationMappingPropertyDocBlock()
- generateDiscriminatorColumnAnnotation()
- generateDiscriminatorMapAnnotation()
- generateEntityAssociationMappingProperties()
- generateEntityBody()
- generateEntityClassName()
- generateEntityConstructor()
- generateEntityDocBlock()
- generateEntityFieldMappingProperties()
- generateEntityLifecycleCallbackMethods()
- generateEntityNamespace()
- generateEntityStubMethod()
- generateEntityStubMethods()
- generateFieldMappingPropertyDocBlock()
- generateInheritanceAnnotation()
- generateJoinColumnAnnotation()
- generateLifecycleCallbackMethod()
- generateTableAnnotation()
- generateTableConstraints()
- getClassName()
- getClassToExtend()
- getClassToExtendName()
- getNamespace()
- getType()
- hasMethod()
- hasNamespace()
- hasProperty()
- isAssociationIsNullable()
- parseTokensInEntityFile()
- prefixCodeWithSpaces()
protected
public
- __construct()
- generate() — Generate and write entity classes for the given array of ClassMetadataInfo instances
- generateEntityClass() — Generate a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance
- generateUpdatedEntityClass() — Generate the updated code for the given ClassMetadataInfo and entity at path
- setAnnotationPrefix() — Set an annotation prefix.
- setBackupExisting() — Should an existing entity be backed up if it already exists?
- setClassToExtend() — Set the name of the class the generated classes should extend from
- setExtension() — Set the extension to use when writing php files to disk
- setFieldVisibility() — Set the class fields visibility for the entity (can either be private or protected)
- setGenerateAnnotations() — Set whether or not to generate annotations for the entity
- setGenerateStubMethods() — Set whether or not to generate stub methods for the entity
- setNumSpaces() — Set the number of spaces the exported class should have
- setRegenerateEntityIfExists() — Set whether or not to regenerate the entity if it exists
- setUpdateEntityIfExists() — Set whether or not to try and update the entity if it already exists
- writeEntityClass() — Generated and write entity class to disk for the given ClassMetadataInfo instance