class DocumentGenerator (View source)

Generic class used to generate PHP5 document classes from ClassMetadataInfo instances

[php] $classes = $dm->getClassMetadataInfoFactory()->getAllMetadata();

$generator = new \Doctrine\ODM\MongoDB\Tools\DocumentGenerator();
$generator->setGenerateAnnotations(true);
$generator->setGenerateStubMethods(true);
$generator->setRegenerateDocumentIfExists(false);
$generator->setUpdateDocumentIfExists(true);
$generator->generate($classes, '/path/to/generate/documents');

Methods

void
generate(array $metadatas, string $outputDirectory)

Generate and write document classes for the given array of ClassMetadataInfo instances

void
writeDocumentClass(ClassMetadataInfo $metadata, string $outputDirectory)

Generated and write document class to disk for the given ClassMetadataInfo instance

string
generateDocumentClass(ClassMetadataInfo $metadata)

Generate a PHP5 Doctrine 2 document class from the given ClassMetadataInfo instance

string
generateUpdatedDocumentClass(ClassMetadataInfo $metadata, string $path)

Generate the updated code for the given ClassMetadataInfo and document at path

void
setNumSpaces(integer $numSpaces)

Set the number of spaces the exported class should have

void
setExtension(string $extension)

Set the extension to use when writing php files to disk

void
setClassToExtend($classToExtend)

Set the name of the class the generated classes should extend from

void
setGenerateAnnotations(bool $bool)

Set whether or not to generate annotations for the document

void
setUpdateDocumentIfExists(bool $bool)

Set whether or not to try and update the document if it already exists

void
setRegenerateDocumentIfExists(bool $bool)

Set whether or not to regenerate the document if it exists

void
setGenerateStubMethods(bool $bool)

Set whether or not to generate stub methods for the document

setBackupExisting($bool)

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

array
getTraits(ClassMetadataInfo $metadata)

No description

bool
isAssociationNullable(array $fieldMapping)

No description

Details

void generate(array $metadatas, string $outputDirectory)

Generate and write document classes for the given array of ClassMetadataInfo instances

Parameters

array $metadatas
string $outputDirectory

Return Value

void

void writeDocumentClass(ClassMetadataInfo $metadata, string $outputDirectory)

Generated and write document class to disk for the given ClassMetadataInfo instance

Parameters

ClassMetadataInfo $metadata
string $outputDirectory

Return Value

void

Exceptions

RuntimeException

string generateDocumentClass(ClassMetadataInfo $metadata)

Generate a PHP5 Doctrine 2 document class from the given ClassMetadataInfo instance

Parameters

ClassMetadataInfo $metadata

Return Value

string $code

string generateUpdatedDocumentClass(ClassMetadataInfo $metadata, string $path)

Generate the updated code for the given ClassMetadataInfo and document at path

Parameters

ClassMetadataInfo $metadata
string $path

Return Value

string $code;

void setNumSpaces(integer $numSpaces)

Set the number of spaces the exported class should have

Parameters

integer $numSpaces

Return Value

void

void setExtension(string $extension)

Set the extension to use when writing php files to disk

Parameters

string $extension

Return Value

void

void setClassToExtend($classToExtend)

Set the name of the class the generated classes should extend from

Parameters

$classToExtend

Return Value

void

void setGenerateAnnotations(bool $bool)

Set whether or not to generate annotations for the document

Parameters

bool $bool

Return Value

void

void setUpdateDocumentIfExists(bool $bool)

Set whether or not to try and update the document if it already exists

Parameters

bool $bool

Return Value

void

void setRegenerateDocumentIfExists(bool $bool)

Set whether or not to regenerate the document if it exists

Parameters

bool $bool

Return Value

void

void setGenerateStubMethods(bool $bool)

Set whether or not to generate stub methods for the document

Parameters

bool $bool

Return Value

void

setBackupExisting($bool)

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

Parameters

$bool

protected array getTraits(ClassMetadataInfo $metadata)

Parameters

ClassMetadataInfo $metadata

Return Value

array

protected bool isAssociationNullable(array $fieldMapping)

Parameters

array $fieldMapping

Return Value

bool