8000 feature #35514 [DI][Routing] add wither to configure the path of PHP-… · symfony/symfony@ee9aacd · GitHub
[go: up one dir, main page]

Skip to content

Commit ee9aacd

Browse files
committed
feature #35514 [DI][Routing] add wither to configure the path of PHP-DSL configurators (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- [DI][Routing] add wither to configure the path of PHP-DSL configurators | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - This makes PHP-DSL configurators more flexible, by allowing to use them for a different path than they were initially created for. Sidekick of symfony/recipes#721 Commits ------- 8f92c85 [DI][Routing] add wither to configure the path of PHP-DSL configurators
2 parents a916c61 + 8f92c85 commit ee9aacd

File tree

6 files changed

+30
-13
lines changed

6 files changed

+30
-13
lines changed

src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
124124
}
125125

126126
// the user has opted into using the ContainerConfigurator
127-
$defaultDefinition = (new Definition())->setAutowired(true)->setAutoconfigured(true);
128127
/* @var ContainerPhpFileLoader $kernelLoader */
129128
$kernelLoader = $loader->getResolver()->resolve($file);
130129
$kernelLoader->setCurrentDir(\dirname($file));
@@ -136,7 +135,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
136135
};
137136

138137
try {
139-
$this->configureContainer(new ContainerConfigurator($container, $kernelLoader, $instanceof, $file, $file, $defaultDefinition), $loader);
138+
$this->configureContainer(new ContainerConfigurator($container, $kernelLoader, $instanceof, $file, $file), $loader);
140139
} finally {
141140
$instanceof = [];
142141
$kernelLoader->registerAliasesForSinglyImplementedInterfaces();

src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/flex-style/src/FlexStyleMicroKernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ protected function configureContainer(ContainerConfigurator $c)
7979
$c->services()
8080
->set('logger', NullLogger::class)
8181
->set('stdClass', 'stdClass')
82+
->autowire()
8283
->factory([$this, 'createHalloween'])
8384
->arg('$halloween', '%halloween%');
8485

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"symfony/polyfill-mbstring": "~1.0",
2828
"symfony/filesystem": "^4.4|^5.0",
2929
"symfony/finder": "^4.4|^5.0",
30-
"symfony/routing": "^5.0"
30+
"symfony/routing": "^5.1"
3131
},
3232
"require-dev": {
3333
"doctrine/annotations": "~1.7",

src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@ class ContainerConfigurator extends AbstractConfigurator
3434
private $path;
3535
private $file;
3636
private $anonymousCount = 0;
37-
private $defaultDefinition;
3837

39-
public function __construct(ContainerBuilder $container, PhpFileLoader $loader, array &$instanceof, string $path, string $file, Definition $defaultDefinition = null)
38+
public function __construct(ContainerBuilder $container, PhpFileLoader $loader, array &$instanceof, string $path, string $file)
4039
{
4140
$this->container = $container;
4241
$this->loader = $loader;
4342
$this->instanceof = &$instanceof;
4443
$this->path = $path;
4544
$this->file = $file;
46-
$this->defaultDefinition = $defaultDefinition;
4745
}
4846

4947
final public function extension(string $namespace, array $config)
@@ -69,7 +67,18 @@ final public function parameters(): ParametersConfigurator
6967

7068
final public function services(): ServicesConfigurator
7169
{
72-
return new ServicesConfigurator($this->container, $this->loader, $this->instanceof, $this->path, $this->anonymousCount, $this->defaultDefinition);
70+
return new ServicesConfigurator($this->container, $this->loader, $this->instanceof, $this->path, $this->anonymousCount);
71+
}
72+
73+
/**
74+
* @return static
75+
*/
76+
final public function withPath(string $path): self
77+
{
78+
$clone = clone $this;
79+
$clone->path = $clone->file = $path;
80+
81+
return $clone;
7382
}
7483
}
7584

src/Symfony/Component/DependencyInjection/Loader/Configurator/ServicesConfigurator.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@ class ServicesConfigurator extends AbstractConfigurator
3232
private $path;
3333
private $anonymousHash;
3434
private $anonymousCount;
35-
private $defaultDefinition;
3635

37-
public function __construct(ContainerBuilder $container, PhpFileLoader $loader, array &$instanceof, string $path = null, int &$anonymousCount = 0, Definition $defaultDefinition = null)
36+
public function __construct(ContainerBuilder $container, PhpFileLoader $loader, array &$instanceof, string $path = null, int &$anonymousCount = 0)
3837
{
39-
$defaultDefinition = $defaultDefinition ?? new Definition();
40-
$this->defaults = clone $defaultDefinition;
38+
$this->defaults = new Definition();
4139
$this->container = $container;
4240
$this->loader = $loader;
4341
$this->instanceof = &$instanceof;
4442
$this->path = $path;
4543
$this->anonymousHash = ContainerBuilder::hash($path ?: mt_rand());
4644
$this->anonymousCount = &$anonymousCount;
47-
$this->defaultDefinition = $defaultDefinition;
4845
$instanceof = [];
4946
}
5047

@@ -53,7 +50,7 @@ public function __construct(ContainerBuilder $container, PhpFileLoader $loader,
5350
*/
5451
final public function defaults(): DefaultsConfigurator
5552
{
56-
return new DefaultsConfigurator($this, $this->defaults = clone $this->defaultDefinition, $this->path);
53+
return new DefaultsConfigurator($this, $this->defaults = new Definition(), $this->path);
5754
}
5855

5956
/**

src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,15 @@ final public function collection(string $name = ''): CollectionConfigurator
5757
{
5858
return new CollectionConfigurator($this->collection, $name);
5959
}
60+
61+
/**
62+
* @return static
63+
*/
64+
final public function withPath(string $path): self
65+
{
66+
$clone = clone $this;
67+
$clone->path = $clone->file = $path;
68+
69+
return $clone;
70+
}
6071
}

0 commit comments

Comments
 (0)
0