Skip to content

Commit 4eb81ab

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

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

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