Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more options for Single Table Inheritance in Doctrine 2 Annotation #143

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Expand Up @@ -230,7 +230,7 @@ Common Setup Options for Doctrine 2.0:

* `generatedValueStrategy`

The stragety for auto-generated values.
The strategy for auto-generated values.

Default is `auto`.

Expand Down Expand Up @@ -276,6 +276,12 @@ Common Setup Options for Doctrine 2.0:

Default is `false`.

* `extendableEntityDefaultDiscriminatorType`

This option allows you to specify the default type for discriminator column.

Default is 'string'.

* `quoteIdentifierStrategy`

This option determine wheter identifier quoting is applied or not, depend on the strategy
Expand Down Expand Up @@ -359,6 +365,22 @@ Common Setup Options for Doctrine 2.0:
column1,desc
{/d:order}

* `{d:discriminator}column{/d:discriminator}` (applied to Table)

Allows you to specify a column name to be used as discriminator for single table inheritance.

* `{d:discriminatorType}type{/d:discriminatorType}` (applied to Table)

Allows you to specify the type to be used for discriminator column in single table inheritance.
This option overrides the `extendableEntityDefaultDiscriminatorType` configuration option and
is overriden by above discriminator column specification, as its type is then automatically deduced.

* `{d:discriminatorMap}value=class, ...{/d:discriminatorMap}` (applied to Table)

In the Single Table Inheritance context, this option overrides the default map (base=Base%Entity%, extended=%Entity%)
with your own discriminator map.


#### Doctrine 2.0 Annotation with ZF2 Input Filter Classes

Doctrine 2.0 Annotation with ZF2 Input Filter Classes formatter directly extend Doctrine 2.0
Expand Down
Binary file added example/data/inheritance.mwb
Binary file not shown.
55 changes: 34 additions & 21 deletions lib/MwbExporter/Formatter/Doctrine2/Annotation/Formatter.php
Expand Up @@ -33,39 +33,51 @@

class Formatter extends BaseFormatter
{
const CFG_ANNOTATION_PREFIX = 'useAnnotationPrefix';
const CFG_EXTENDS_CLASS = 'extendsClass';
const CFG_PROPERTY_TYPEHINT = 'propertyTypehint';
const CFG_SKIP_GETTER_SETTER = 'skipGetterAndSetter';
const CFG_GENERATE_ENTITY_SERIALIZATION = 'generateEntitySerialization';
const CFG_GENERATE_EXTENDABLE_ENTITY = 'generateExtendableEntity';
const CFG_QUOTE_IDENTIFIER_STRATEGY = 'quoteIdentifierStrategy';
const CFG_ANNOTATION_PREFIX = 'useAnnotationPrefix';
const CFG_PROPERTY_TYPEHINT = 'propertyTypehint';
const CFG_QUOTE_IDENTIFIER_STRATEGY = 'quoteIdentifierStrategy';
const CFG_SKIP_GETTER_SETTER = 'skipGetterAndSetter';

// These options should go in BaseFormatter and thus be implemented in Yaml (?)
const CFG_EXTENDS_CLASS = 'extendsClass';
const CFG_OVERWRITE_EXTENDED_ENTITIES = 'overwriteExtendedEntities';
const CFG_GENERATE_ENTITY_SERIALIZATION = 'generateEntitySerialization';
const CFG_GENERATE_EXTENDABLE_ENTITY = 'generateExtendableEntity';
const CFG_GENERATE_SINGLE_INHERITANCE = 'generateSingleInheritance';
const CFG_EXTENDABLE_ENTITY_DEFAULT_DISCR_TYPE = 'extendableEntityDefaultDiscriminatorType';

const QUOTE_IDENTIFIER_AUTO = 'auto';
const QUOTE_IDENTIFIER_ALWAYS = 'always';
const QUOTE_IDENTIFIER_NONE = 'none';
const QUOTE_IDENTIFIER_AUTO = 'auto';
const QUOTE_IDENTIFIER_ALWAYS = 'always';
const QUOTE_IDENTIFIER_NONE = 'none';

protected function init()
{
parent::init();
$this->addConfigurations(array(
static::CFG_INDENTATION => 4,
static::CFG_FILENAME => '%entity%.%extension%',
static::CFG_ANNOTATION_PREFIX => 'ORM\\',
static::CFG_SKIP_GETTER_SETTER => false,
static::CFG_GENERATE_ENTITY_SERIALIZATION => true,
static::CFG_GENERATE_EXTENDABLE_ENTITY => false,
static::CFG_QUOTE_IDENTIFIER_STRATEGY => static::QUOTE_IDENTIFIER_AUTO,
static::CFG_EXTENDS_CLASS => '',
static::CFG_PROPERTY_TYPEHINT => false,
static::CFG_ANNOTATION_PREFIX => 'ORM\\',
static::CFG_QUOTE_IDENTIFIER_STRATEGY => static::QUOTE_IDENTIFIER_AUTO,
static::CFG_PROPERTY_TYPEHINT => false,
static::CFG_FILENAME => '%entity%.%extension%',
static::CFG_SKIP_GETTER_SETTER => false,
static::CFG_GENERATE_ENTITY_SERIALIZATION => true,
static::CFG_OVERWRITE_EXTENDED_ENTITIES => false,
static::CFG_EXTENDS_CLASS => '',
static::CFG_GENERATE_EXTENDABLE_ENTITY => false,
static::CFG_GENERATE_SINGLE_INHERITANCE => false,
static::CFG_EXTENDABLE_ENTITY_DEFAULT_DISCR_TYPE => $this->getDataTypeConverter()->getDataType(DataTypeConverter::DATATYPE_VARCHAR),

));
$this->addValidators(array(
static::CFG_QUOTE_IDENTIFIER_STRATEGY => new ChoiceValidator(array(
static::CFG_QUOTE_IDENTIFIER_STRATEGY => new ChoiceValidator(array(
static::QUOTE_IDENTIFIER_AUTO,
static::QUOTE_IDENTIFIER_ALWAYS,
static::QUOTE_IDENTIFIER_NONE,
)),
static::CFG_EXTENDABLE_ENTITY_DEFAULT_DISCR_TYPE => new ChoiceValidator(
$this->getInheritanceDiscriminatorRelevantTypes()
),
));

}

/**
Expand Down Expand Up @@ -104,4 +116,5 @@ public function getFileExtension()
{
return 'php';
}
}

}
Expand Up @@ -54,7 +54,7 @@ public function writeVar(WriterInterface $writer)
return $this;
}

public function writeGetterAndSetter(WriterInterface $writer)
public function writeGetterAndSetter(WriterInterface $writer, $base = false, $entityName = "")
{
if (!$this->isIgnored()) {
$this->getDocument()->addLog(sprintf(' Writing setter/getter for column "%s"', $this->getColumnName()));
Expand All @@ -71,7 +71,7 @@ public function writeGetterAndSetter(WriterInterface $writer)
->write(' * Set the value of '.$this->getColumnName().'.')
->write(' *')
->write(' * @param '.$nativeType.' $'.$this->getColumnName())
->write(' * @return '.$table->getNamespace())
->write(' * @return '.$table->getNamespace(null, true, $base))
->write(' */')
->write('public function set'.$this->getBeautifiedColumnName().'('.$typehint.'$'.$this->getColumnName().')')
->write('{')
Expand Down