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

New config property "converterSuffix" #75

Open
wants to merge 3 commits into
base: main
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: 4 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ private function addConverterSection(ArrayNodeDefinition $rootNode): void
{
$rootNode
->children()
->scalarNode('converter_suffix')
->info('consolidated suffix for all converters')
Copy link
Member

Choose a reason for hiding this comment

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

This message is misleading. It only configures the suffix of the autowiring alias for converter arguments.

->defaultValue('Converter')
->end()
->arrayNode('converter')
->info('Converter configuration')
->normalizeKeys(false)
Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/NeustaConverterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function loadInternal(array $mergedConfig, ContainerBuilder $container):
$loader->load('services.yaml');

foreach ($mergedConfig['converter'] as $converterId => $converter) {
$this->registerConverterConfiguration($converterId, $converter, $container);
$this->registerConverterConfiguration($converterId, $converter, $container, $mergedConfig['converterSuffix']);
}

foreach ($mergedConfig['populator'] as $populatorId => $populator) {
Expand All @@ -40,7 +40,7 @@ public function loadInternal(array $mergedConfig, ContainerBuilder $container):
/**
* @param array<string, mixed> $config
*/
private function registerConverterConfiguration(string $id, array $config, ContainerBuilder $container): void
private function registerConverterConfiguration(string $id, array $config, ContainerBuilder $container, ?string $converterSuffix): void
Copy link
Member

Choose a reason for hiding this comment

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

I guess this is not nullable when there's a default value defined in the config.

{
$targetFactoryId = $config['target_factory'] ?? "{$id}.target_factory";
if (!isset($config['target_factory'])) {
Expand Down Expand Up @@ -77,7 +77,7 @@ private function registerConverterConfiguration(string $id, array $config, Conta
]);
}

$container->registerAliasForArgument($id, Converter::class, $this->appendSuffix($id, 'Converter'));
$container->registerAliasForArgument($id, Converter::class, $this->appendSuffix($id, $converterSuffix ?? ''));
$container->register($id, $config['converter'])
->setPublic(true)
->setArguments([
Expand Down
3 changes: 3 additions & 0 deletions tests/DependencyInjection/NeustaConverterExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected function getContainerExtensions(): array
public function test_with_generic_converter(): void
{
$this->load([
'converterSuffix' => 'Converter',
'converter' => [
'foobar' => [
'target_factory' => PersonFactory::class,
Expand Down Expand Up @@ -122,6 +123,7 @@ public function test_with_target_and_target_factory(): void
public function test_with_mapped_properties(): void
{
$this->load([
'converterSuffix' => 'Converter',
'converter' => [
'foobar' => [
'target_factory' => PersonFactory::class,
Expand Down Expand Up @@ -180,6 +182,7 @@ public function test_with_mapped_properties(): void
public function test_with_mapped_context(): void
{
$this->load([
'converterSuffix' => 'Converter',
'converter' => [
'foobar' => [
'target_factory' => PersonFactory::class,
Expand Down
Loading