diff --git a/README.md b/README.md index 99ef17b9..115195d7 100644 --- a/README.md +++ b/README.md @@ -209,7 +209,7 @@ class MyHandler implements SubscribingHandlerInterface Naming Strategy --------------- -There are two types of naming strategies: `short` and `long`. The default is `short`, this naming strategy can however generate naming conflicts. +There are two predefined types of naming strategies: `short` and `long`. The default is `short`, this naming strategy can however generate naming conflicts. The `long` naming strategy will suffix elements with `Element` and types with `Type`. @@ -221,3 +221,5 @@ An XSD for instance with a type named `User`, a type named `UserType`, a root el * If you don't have naming conflicts and you want to have short and descriptive class names, use the `short` option. * If you have naming conflicts use the `long` option. * If you want to be safe, use the `long` option. + +If you want to use custom naming strategy, specify as `naming_strategy` FQN of class implementing `GoetasWebservices\Xsd\XsdToPhp\Naming\NamingStrategy` interface. diff --git a/src/DependencyInjection/Xsd2PhpExtension.php b/src/DependencyInjection/Xsd2PhpExtension.php index 8e3cdb14..2d83f3ca 100644 --- a/src/DependencyInjection/Xsd2PhpExtension.php +++ b/src/DependencyInjection/Xsd2PhpExtension.php @@ -3,6 +3,7 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; @@ -20,7 +21,12 @@ public function load(array $configs, ContainerBuilder $container) $config = array_merge($config, $subConfig); } - $definition = $container->getDefinition('goetas_webservices.xsd2php.naming_convention.' . $config['naming_strategy']); + $namingStrategy = $config['naming_strategy']; + if (in_array($namingStrategy, ['short', 'long'], true)) { + $definition = $container->getDefinition('goetas_webservices.xsd2php.naming_convention.' . $namingStrategy); + } else { + $definition = new Definition($namingStrategy); + } $container->setDefinition('goetas_webservices.xsd2php.naming_convention', $definition);