Skip to content

Commit baf017f

Browse files
committed
abstract config
1 parent fc35493 commit baf017f

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

doc/configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ Example:
8383
parent: false # No parent
8484
```
8585

86+
## Forcing a class to be abstract
87+
88+
Force a class to be `abstract` (or to be not).
89+
90+
Example:
91+
92+
```yaml
93+
Person:
94+
abstract: true
95+
```
96+
8697
## Author PHPDoc
8798

8899
Add a `@author` PHPDoc annotation to class' DocBlock.

src/SchemaOrgModel/AnnotationGenerator/DoctrineOrmAnnotationGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function generateClassAnnotations($className)
3333
if (isset($this->config['types'][$class['resource']->localName()]['doctrine']['inheritanceMapping'])) {
3434
$inheritanceMapping = $this->config['types'][$class['resource']->localName()]['doctrine']['inheritanceMapping'];
3535
} else {
36-
$inheritanceMapping = $class['hasChild'] ? '@ORM\MappedSuperclass' : '@ORM\Entity';
36+
$inheritanceMapping = $class['abstract'] ? '@ORM\MappedSuperclass' : '@ORM\Entity';
3737
}
3838

3939
return [

src/SchemaOrgModel/TypesGenerator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public function generate($config)
111111
'uses' => [],
112112
'hasConstructor' => false,
113113
'hasChild' => false,
114+
'abstract' => false,
114115
];
115116

116117
$typesDefined = !empty($config['types']);
@@ -286,6 +287,15 @@ public function generate($config)
286287
}
287288
}
288289

290+
// Third pass
291+
foreach ($classes as &$class) {
292+
if (isset($config['types'][$class['name']]['abstract']) && null !== $config['types'][$class['name']]['abstract']) {
293+
$class['abstract'] = $config['types'][$class['name']]['abstract'];
294+
} else {
295+
$class['abstract'] = $class['hasChild'];
296+
}
297+
}
298+
289299
// Generate ID
290300
if ($config['generateId']) {
291301
foreach ($classes as &$class) {

src/SchemaOrgModel/TypesGeneratorConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function getConfigTreeBuilder()
7474
->useAttributeAsKey('id')
7575
->prototype('array')
7676
->children()
77+
->booleanNode('abstract')->defaultNull()->info('Is the class abstract? (null to guess)')->end()
7778
->arrayNode('namespaces')
7879
->addDefaultsIfNotSet()
7980
->info('Type namespaces')

templates/class.php.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use {{ use }};
1919
* {{ annotation }}
2020
{% endfor %}
2121
*/
22-
{% if class.hasChild %}abstract {% endif %}class {{ class.name }}{% if class.parent %} extends {{ class.parent }}{% endif %}{% if class.interfaceName %} implements {{ class.interfaceName }}{% endif %}
22+
{% if class.abstract %}abstract {% endif %}class {{ class.name }}{% if class.parent %} extends {{ class.parent }}{% endif %}{% if class.interfaceName %} implements {{ class.interfaceName }}{% endif %}
2323
{
2424
{% for constant in class.constants %}
2525
/**

0 commit comments

Comments
 (0)