Skip to content

Commit 97cbd19

Browse files
committed
Add support for custom naming strategy
1 parent 889c7d1 commit 97cbd19

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class MyHandler implements SubscribingHandlerInterface
209209
Naming Strategy
210210
---------------
211211

212-
There are two types of naming strategies: `short` and `long`. The default is `short`, this naming strategy can however generate naming conflicts.
212+
There are two predefined types of naming strategies: `short` and `long`. The default is `short`, this naming strategy can however generate naming conflicts.
213213

214214
The `long` naming strategy will suffix elements with `Element` and types with `Type`.
215215

@@ -221,3 +221,5 @@ An XSD for instance with a type named `User`, a type named `UserType`, a root el
221221
* If you don't have naming conflicts and you want to have short and descriptive class names, use the `short` option.
222222
* If you have naming conflicts use the `long` option.
223223
* If you want to be safe, use the `long` option.
224+
225+
If you want to use custom naming strategy, specify as `naming_strategy` FQN of class implementing `GoetasWebservices\Xsd\XsdToPhp\Naming\NamingStrategy` interface.

src/DependencyInjection/Xsd2PhpExtension.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use Symfony\Component\Config\FileLocator;
55
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\DependencyInjection\Definition;
67
use Symfony\Component\DependencyInjection\Extension\Extension;
78
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
89

@@ -20,7 +21,12 @@ public function load(array $configs, ContainerBuilder $container)
2021
$config = array_merge($config, $subConfig);
2122
}
2223

23-
$definition = $container->getDefinition('goetas_webservices.xsd2php.naming_convention.' . $config['naming_strategy']);
24+
$namingStrategy = $config['naming_strategy'];
25+
if (in_array($namingStrategy, ['short', 'long'], true)) {
26+
$definition = $container->getDefinition('goetas_webservices.xsd2php.naming_convention.' . $namingStrategy);
27+
} else {
28+
$definition = new Definition($namingStrategy);
29+
}
2430
$container->setDefinition('goetas_webservices.xsd2php.naming_convention', $definition);
2531

2632

0 commit comments

Comments
 (0)