Skip to content

Commit

Permalink
Add support for custom naming strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubkulhan committed Feb 14, 2018
1 parent 482def7 commit 9906aff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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.
8 changes: 7 additions & 1 deletion src/DependencyInjection/Xsd2PhpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);


Expand Down

0 comments on commit 9906aff

Please sign in to comment.