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

Add support for custom naming strategy #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about using an alias? so is possible to pass parameters to the naming strategy constructor?

}
$container->setDefinition('goetas_webservices.xsd2php.naming_convention', $definition);


Expand Down