Skip to content

Commit 89472f2

Browse files
committed
Move all namespaces under namespaces config node
1 parent 65a0534 commit 89472f2

File tree

3 files changed

+48
-29
lines changed

3 files changed

+48
-29
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,40 @@ public function getConfigTreeBuilder()
3030
}
3131

3232
$rootNode
33+
->beforeNormalization()
34+
->ifTrue(function ($v) { return isset($v['root_namespace']) && !isset($v['namespaces']['root']); })
35+
->then(function ($v) {
36+
$v['namespaces']['root'] = $v['root_namespace'];
37+
38+
return $v;
39+
})
40+
->end()
41+
3342
->children()
34-
->scalarNode('root_namespace')->defaultValue('App\\')->end()
35-
->scalarNode('command_namespace')->defaultValue('Command\\')->end()
36-
->scalarNode('controller_namespace')->defaultValue('Controller\\')->end()
37-
->scalarNode('entity_namespace')->defaultValue('Entity\\')->end()
38-
->scalarNode('fixtures_namespace')->defaultValue('DataFixtures\\')->end()
39-
->scalarNode('form_namespace')->defaultValue('Form\\')->end()
40-
->scalarNode('functional_test_namespace')->defaultValue('Tests\\')->end()
41-
->scalarNode('repository_namespace')->defaultValue('Repository\\')->end()
42-
->scalarNode('security_namespace')->defaultValue('Security\\')->end()
43-
->scalarNode('serializer_namespace')->defaultValue('Serializer\\')->end()
44-
->scalarNode('subscriber_namespace')->defaultValue('EventSubscriber\\')->end()
45-
->scalarNode('twig_namespace')->defaultValue('Twig\\')->end()
46-
->scalarNode('unit_test_namespace')->defaultValue('Tests\\')->end()
47-
->scalarNode('validator_namespace')->defaultValue('Validator\\')->end()
43+
->scalarNode('root_namespace')
44+
->setDeprecated('The child node "%node%" at path "%path%" is deprecated. Please use namespaces.root instead.')
45+
->defaultNull()
46+
->end()
47+
48+
->arrayNode('namespaces')
49+
->addDefaultsIfNotSet()
50+
->children()
51+
->scalarNode('root')->defaultNull()->end()
52+
->scalarNode('command')->defaultValue('Command\\')->end()
53+
->scalarNode('controller')->defaultValue('Controller\\')->end()
54+
->scalarNode('entity')->defaultValue('Entity\\')->end()
55+
->scalarNode('fixtures')->defaultValue('DataFixtures\\')->end()
56+
->scalarNode('form')->defaultValue('Form\\')->end()
57+
->scalarNode('functional_test')->defaultValue('Tests\\')->end()
58+
->scalarNode('repository')->defaultValue('Repository\\')->end()
59+
->scalarNode('security')->defaultValue('Security\\')->end()
60+
->scalarNode('serializer')->defaultValue('Serializer\\')->end()
61+
->scalarNode('subscriber')->defaultValue('EventSubscriber\\')->end()
62+
->scalarNode('twig')->defaultValue('Twig\\')->end()
63+
->scalarNode('unit_test')->defaultValue('Tests\\')->end()
64+
->scalarNode('validator')->defaultValue('Validator\\')->end()
65+
->end()
66+
->end()
4867
->end()
4968
;
5069

src/DependencyInjection/MakerExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function load(array $configs, ContainerBuilder $container)
3838
$config = $this->processConfiguration($configuration, $configs);
3939

4040
$namespacesHelperDefinition = $container->getDefinition('maker.namespaces_helper');
41-
$namespacesHelperDefinition->replaceArgument(0, $config);
41+
$namespacesHelperDefinition->replaceArgument(0, $config['namespaces']);
4242

4343
$container->registerForAutoconfiguration(MakerInterface::class)
4444
->addTag(MakeCommandRegistrationPass::MAKER_TAG);

src/Util/NamespacesHelper.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,72 +23,72 @@ public function __construct(array $namespaces = null)
2323

2424
public function getCommandNamespace(): string
2525
{
26-
return $this->trim($this->namespaces['command_namespace'] ?? 'Command\\');
26+
return $this->trim($this->namespaces['command'] ?? 'Command\\');
2727
}
2828

2929
public function getControllerNamespace(): string
3030
{
31-
return $this->trim($this->namespaces['controller_namespace'] ?? 'Controller\\');
31+
return $this->trim($this->namespaces['controller'] ?? 'Controller\\');
3232
}
3333

3434
public function getEntityNamespace(): string
3535
{
36-
return $this->trim($this->namespaces['entity_namespace'] ?? 'Entity\\');
36+
return $this->trim($this->namespaces['entity'] ?? 'Entity\\');
3737
}
3838

3939
public function getFixturesNamespace(): string
4040
{
41-
return $this->trim($this->namespaces['fixtures_namespace'] ?? 'DataFixtures\\');
41+
return $this->trim($this->namespaces['fixtures'] ?? 'DataFixtures\\');
4242
}
4343

4444
public function getFormNamespace(): string
4545
{
46-
return $this->trim($this->namespaces['form_namespace'] ?? 'Form\\');
46+
return $this->trim($this->namespaces['form'] ?? 'Form\\');
4747
}
4848

4949
public function getFunctionalTestNamespace(): string
5050
{
51-
return $this->trim($this->namespaces['functional_test_namespace'] ?? 'Tests\\');
51+
return $this->trim($this->namespaces['functional_test'] ?? 'Tests\\');
5252
}
5353

5454
public function getRepositoryNamespace(): string
5555
{
56-
return $this->trim($this->namespaces['repository_namespace'] ?? 'Repository\\');
56+
return $this->trim($this->namespaces['repository'] ?? 'Repository\\');
5757
}
5858

5959
public function getRootNamespace(): string
6060
{
61-
return $this->trim($this->namespaces['root_namespace'] ?? 'App\\');
61+
return $this->trim($this->namespaces['root'] ?? 'App\\');
6262
}
6363

6464
public function getSecurityNamespace(): string
6565
{
66-
return $this->trim($this->namespaces['security_namespace'] ?? 'Security\\');
66+
return $this->trim($this->namespaces['security'] ?? 'Security\\');
6767
}
6868

6969
public function getSerializerNamespace(): string
7070
{
71-
return $this->trim($this->namespaces['serializer_namespace'] ?? 'Serializer\\');
71+
return $this->trim($this->namespaces['serializer'] ?? 'Serializer\\');
7272
}
7373

7474
public function getSubscriberNamespace(): string
7575
{
76-
return $this->trim($this->namespaces['subscriber_namespace'] ?? 'EventSubscriber\\');
76+
return $this->trim($this->namespaces['subscriber'] ?? 'EventSubscriber\\');
7777
}
7878

7979
public function getTwigNamespace(): string
8080
{
81-
return $this->trim($this->namespaces['twig_namespace'] ?? 'Twig\\');
81+
return $this->trim($this->namespaces['twig'] ?? 'Twig\\');
8282
}
8383

8484
public function getUnitTestNamespace(): string
8585
{
86-
return $this->trim($this->namespaces['unit_test_namespace'] ?? 'Tests\\');
86+
return $this->trim($this->namespaces['unit_test'] ?? 'Tests\\');
8787
}
8888

8989
public function getValidatorNamespace(): string
9090
{
91-
return $this->trim($this->namespaces['validator_namespace'] ?? 'Validator\\');
91+
return $this->trim($this->namespaces['validator'] ?? 'Validator\\');
9292
}
9393

9494
private function trim(string $namespace): string

0 commit comments

Comments
 (0)