Skip to content

Commit ec906b6

Browse files
[DI] deprecate short callables in yaml
1 parent e19db43 commit ec906b6

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

UPGRADE-4.4.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
UPGRADE FROM 4.2 to 4.3
2+
=======================
3+
4+
DependencyInjection
5+
-------------------
6+
7+
* Deprecated support for short factories and short configurators in Yaml
8+
9+
Before:
10+
```yaml
11+
services:
12+
my_service:
13+
factory: factory_service:method
14+
```
15+
16+
After:
17+
```yaml
18+
services:
19+
my_service:
20+
factory: ['@factory_service', method]
21+
```

UPGRADE-5.0.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ DependencyInjection
6969
env(NAME): '1.5'
7070
```
7171
72+
* Removed support for short factories and short configurators in Yaml
73+
74+
Before:
75+
```yaml
76+
services:
77+
my_service:
78+
factory: factory_service:method
79+
```
80+
81+
After:
82+
```yaml
83+
services:
84+
my_service:
85+
factory: ['@factory_service', method]
86+
```
87+
7288
DoctrineBridge
7389
--------------
7490

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.4.0
5+
-----
6+
7+
* deprecated support for short factories and short configurators in Yaml
8+
49
4.3.0
510
-----
611

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,28 +574,29 @@ private function parseDefinition($id, $service, $file, array $defaults)
574574
/**
575575
* Parses a callable.
576576
*
577-
* @param string|array $callable A callable
578-
* @param string $parameter A parameter (e.g. 'factory' or 'configurator')
579-
* @param string $id A service identifier
580-
* @param string $file A parsed file
577+
* @param string|array $callable A callable reference
578+
* @param string $parameter The type of callable (e.g. 'factory' or 'configurator')
581579
*
582580
* @throws InvalidArgumentException When errors occur
583581
*
584582
* @return string|array|Reference A parsed callable
585583
*/
586-
private function parseCallable($callable, $parameter, $id, $file)
584+
private function parseCallable($callable, string $parameter, string $id, string $file)
587585
{
588586
if (\is_string($callable)) {
589587
if ('' !== $callable && '@' === $callable[0]) {
590588
if (false === strpos($callable, ':')) {
591589
return [$this->resolveServices($callable, $file), '__invoke'];
592590
}
593-
throw new InvalidArgumentException(sprintf('The value of the "%s" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $parameter, $id, $callable, substr($callable, 1)));
591+
592+
throw new InvalidArgumentException(sprintf('The value of the "%s" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s" in "%s").', $parameter, $id, $callable, substr($callable, 1), $file));
594593
}
595594

596595
if (false !== strpos($callable, ':') && false === strpos($callable, '::')) {
597596
$parts = explode(':', $callable);
598597

598+
@trigger_error(sprintf('Using short %s syntax for service "%s" is deprecated since Symfony 4.4, use "[\'@%s\', \'%s\']" instead.', $parameter, $id, ...$parts), E_USER_DEPRECATED);
599+
599600
return [$this->resolveServices('@'.$parts[0], $file), $parts[1]];
600601
}
601602

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ public function testDeprecatedAliases()
191191
$this->assertSame($message, $container->getAlias('alias_for_foobar')->getDeprecationMessage('alias_for_foobar'));
192192
}
193193

194+
/**
195+
* @group legacy
196+
*/
194197
public function testLoadFactoryShortSyntax()
195198
{
196199
$container = new ContainerBuilder();
@@ -208,10 +211,13 @@ public function testFactorySyntaxError()
208211
$container = new ContainerBuilder();
209212
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
210213
$this->expectException(InvalidArgumentException::class);
211-
$this->expectExceptionMessage('The value of the "factory" option for the "invalid_factory" service must be the id of the service without the "@" prefix (replace "@factory:method" with "factory:method").');
214+
$this->expectExceptionMessage('The value of the "factory" option for the "invalid_factory" service must be the id of the service without the "@" prefix (replace "@factory:method" with "factory:method"');
212215
$loader->load('bad_factory_syntax.yml');
213216
}
214217

218+
/**
219+
* @group legacy
220+
*/
215221
public function testLoadConfiguratorShortSyntax()
216222
{
217223
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy