8000 Merge branch '4.2' · symfony/symfony@e6fa538 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6fa538

Browse files
Merge branch '4.2'
* 4.2: [TwigBridge] Deprecating legacy Twig paths in DebugCommand and simplifications [Cache] Fixed Memcached adapter doClear()to call flush() Fixes sprintf(): Too few arguments in Translator fix TransChoiceTokenParser deprecation message [DoctrineBridge] Conflict with Messenger <4.2 [Contracts] extract LocaleAwareInterface out of TranslatorInterface
2 parents c7fe1b6 + 15fefd8 commit e6fa538

File tree

30 files changed

+150
-130
lines changed

30 files changed

+150
-130
lines changed

UPGRADE-4.2.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Finder
6868
Form
6969
----
7070

71+
* The `symfony/translation` dependency has been removed - run `composer require symfony/translation` if you need the component
7172
* The `getExtendedType()` method of the `FormTypeExtensionInterface` is deprecated and will be removed in 5.0. Type
7273
extensions must implement the static `getExtendedTypes()` method instead and return an iterable of extended types.
7374

@@ -381,6 +382,7 @@ TwigBundle
381382
Validator
382383
---------
383384

385+
* The `symfony/translation` dependency has been removed - run `composer require symfony/translation` if you need the component
384386
* The `checkMX` and `checkHost` options of the `Email` constraint are deprecated
385387
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
386388
* The `ValidatorBuilderInterface` has been deprecated and `ValidatorBuilder` made final

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
},
4747
"conflict": {
4848
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
49-
"symfony/dependency-injection": "<3.4"
49+
"symfony/dependency-injection": "<3.4",
50+
"symfony/messenger": "<4.2"
5051
},
5152
"suggest": {
5253
"symfony/form": "",

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ private function displayGeneralText(SymfonyStyle $io, string $filter = null)
208208
$io->table(array('Namespace', 'Paths'), $this->buildTableRows($paths));
209209
}
210210

211-
if ($wronBundles = $this->findWrongBundleOverrides()) {
212-
foreach ($this->buildWarningMessages($wronBundles) as $message) {
211+
if ($wrongBundles = $this->findWrongBundleOverrides()) {
212+
foreach ($this->buildWarningMessages($wrongBundles) as $message) {
213213
$io->warning($message);
214214
}
215215
}
@@ -253,13 +253,7 @@ private function getLoaderPaths(string $name = null): array
253253
}
254254

255255
foreach ($namespaces as $namespace) {
256-
$paths = array_map(function ($path) {
257-
if (null !== $this->projectDir && 0 === strpos($path, $this->projectDir)) {
258-
$path = ltrim(substr($path, \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
259-
}
260-
261-
return $path;
262-
}, $loader->getPaths($namespace));
256+
$paths = array_map(array($this, 'getRelativePath'), $loader->getPaths($namespace));
263257

264258
if (FilesystemLoader::MAIN_NAMESPACE === $namespace) {
265259
$namespace = '(None)';
@@ -368,53 +362,38 @@ private function findWrongBundleOverrides(): array
368362

369363
if ($this->rootDir && $this->projectDir) {
370364
$folders = glob($this->rootDir.'/Resources/*/views', GLOB_ONLYDIR);
371-
$relativePath = ltrim(substr($this->rootDir.'/Resources/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
372-
$bundleNames = array_reduce(
373-
$folders,
374-
function ($carry, $absolutePath) use ($relativePath) {
375-
if (0 === strpos($absolutePath, $this->projectDir)) {
376-
$name = basename(\dirname($absolutePath));
377-
$path = $relativePath.$name;
378-
$carry[$name] = $path;
379-
}
365+
$relativePath = ltrim(substr($this->rootDir.\DIRECTORY_SEPARATOR.'Resources/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
366+
$bundleNames = array_reduce($folders, function ($carry, $absolutePath) use ($relativePath) {
367+
if (0 === strpos($absolutePath, $this->projectDir)) {
368+
$name = basename(\dirname($absolutePath));
369+
$path = ltrim($relativePath.$name, \DIRECTORY_SEPARATOR);
370+
$carry[$name] = $path;
371+
372+
@trigger_error(sprintf('Templates directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $absolutePath, $this->twigDefaultPath.'/bundles/'.$name), E_USER_DEPRECATED);
373+
}
380374

381-
return $carry;
382-
},
383-
$bundleNames
384-
);
375+
return $carry;
376+
}, $bundleNames);
385377
}
386378

387379
if ($this->twigDefaultPath && $this->projectDir) {
388380
$folders = glob($this->twigDefaultPath.'/bundles/*', GLOB_ONLYDIR);
389-
$relativePath = ltrim(substr($this->twigDefaultPath.'/bundles', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
390-
$bundleNames = array_reduce(
391-
$folders,
392-
function ($carry, $absolutePath) use ($relativePath) {
393-
if (0 === strpos($absolutePath, $this->projectDir)) {
394-
$path = ltrim(substr($absolutePath, \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
395-
$name = ltrim(substr($path, \strlen($relativePath)), \DIRECTORY_SEPARATOR);
396-
$carry[$name] = $path;
397-
}
398-
399-
return $carry;
400-
},
401-
$bundleNames
402-
);
403-
}
404-
405-
if (\count($bundleNames)) {
406-
$notFoundBundles = array_diff_key($bundleNames, $this->bundlesMetadata);
407-
if (\count($notFoundBundles)) {
408-
$alternatives = array();
409-
foreach ($notFoundBundles as $notFoundBundle => $path) {
410-
$alternatives[$path] = array();
411-
foreach ($this->bundlesMetadata as $name => $bundle) {
412-
$lev = levenshtein($notFoundBundle, $name);
413-
if ($lev <= \strlen($notFoundBundle) / 3 || false !== strpos($name, $notFoundBundle)) {
414-
$alternatives[$path][] = $name;
415-
}
416-
}
381+
$relativePath = ltrim(substr($this->twigDefaultPath.'/bundles/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
382+
$bundleNames = array_reduce($folders, function ($carry, $absolutePath) use ($relativePath) {
383+
if (0 === strpos($absolutePath, $this->projectDir)) {
384+
$name = basename($absolutePath);
385+
$path = ltrim($relativePath.$name, \DIRECTORY_SEPARATOR);
386+
$carry[$name] = $path;
417387
}
388+
389+
return $carry;
390+
}, $bundleNames);
391+
}
392+
393+
if ($notFoundBundles = array_diff_key($bundleNames, $this->bundlesMetadata)) {
394+
$alternatives = array();
395+
foreach ($notFoundBundles as $notFoundBundle => $path) {
396+
$alternatives[$path] = $this->findAlternatives($notFoundBundle, array_keys($this->bundlesMetadata));
418397
}
419398
}
420399

src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,52 @@ public function testFilterAndJsonFormatOptions()
4242
$this->assertEquals($expected, json_decode($tester->getDisplay(true), true));
4343
}
4444

45+
public function testWarningsWrongBundleOverriding()
46+
{
47+
$bundleMetadata = array(
48+
'TwigBundle' => 'vendor/twig-bundle/',
49+
'WebProfilerBundle' => 'vendor/web-profiler-bundle/',
50+
);
51+
$defaultPath = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'templates';
52+
53+
$tester = $this->createCommandTester(array(), $bundleMetadata, $defaultPath);
54+
$ret = $tester->execute(array('--filter' => 'unknown', '--format' => 'json'), array('decorated' => false));
55+
56+
$expected = array('warnings' => array(
57+
'Path "templates/bundles/UnknownBundle" not matching any bundle found',
58+
'Path "templates/bundles/WebProfileBundle" not matching any bundle found, did you mean "WebProfilerBundle"?',
59+
));
60+
61+
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
62+
$this->assertEquals($expected, json_decode($tester->getDisplay(true), true));
63+
}
64+
65+
/**
66+
* @group legacy
67+
* @expectedDeprecation Templates directory "%sResources/BarBundle/views" is deprecated since Symfony 4.2, use "%stemplates/bundles/BarBundle" instead.
68+
*/
69+
public function testDeprecationForWrongBundleOverridingInLegacyPath()
70+
{
71+
$bundleMetadata = array(
72+
'TwigBundle' => 'vendor/twig-bundle/',
73+
'WebProfilerBundle' => 'vendor/web-profiler-bundle/',
74+
);
75+
$defaultPath = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'templates';
76+
$rootDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
77+
78+
$tester = $this->createCommandTester(array(), $bundleMetadata, $defaultPath, $rootDir);
79+
$ret = $tester->execute(array('--filter' => 'unknown', '--format' => 'json'), array('decorated' => false));
80+
81+
$expected = array('warnings' => array(
82+
'Path "Resources/BarBundle" not matching any bundle found',
83+
'Path "templates/bundles/UnknownBundle" not matching any bundle found',
84+
'Path "templates/bundles/WebProfileBundle" not matching any bundle found, did you mean "WebProfilerBundle"?',
85+
));
86+
87+
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
88+
$this->assertEquals($expected, json_decode($tester->getDisplay(true), true));
89+
}
90+
4591
/**
4692
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException
4793
* @expectedExceptionMessage Malformed namespaced template name "@foo" (expecting "@namespace/template_name").
@@ -233,7 +279,7 @@ public function getDebugTemplateNameTestData()
233279
);
234280
}
235281

236-
private function createCommandTester(array $paths = array()): CommandTester
282+
private function createCommandTester(array $paths = array(), array $bundleMetadata = array(), string $defaultPath = null, string $rootDir = null): CommandTester
237283
{
238284
$projectDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
239285
$loader = new FilesystemLoader(array(), $projectDir);
@@ -246,7 +292,7 @@ private function createCommandTester(array $paths = array()): CommandTester
246292
}
247293

248294
$application = new Application();
249-
$application->add(new DebugCommand(new Environment($loader), $projectDir));
295+
$application->add(new DebugCommand(new Environment($loader), $projectDir, $bundleMetadata, $defaultPath, $rootDir));
250296
$command = $application->find('debug:twig');
251297

252298
return new CommandTester($command);

src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,4 @@ public function trans($id, array $parameters = array(), $domain = null, $locale
1919
{
2020
return '[trans]'.$id.'[/trans]';
2121
}
22-
23-
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
24-
{
25-
return '[trans]'.$id.'[/trans]';
26-
}
27-
28-
public function setLocale($locale)
29-
{
30-
}
31-
32-
public function getLocale()
33-
{
34-
}
3522
}

src/Symfony/Bridge/Twig/Tests/Fixtures/Resources/BarBundle/views/base.html.twig

Whitespace-only changes.

src/Symfony/Bridge/Twig/Tests/Fixtures/templates/bundles/UnknownBundle/base.html.twig

Whitespace-only changes.

src/Symfony/Bridge/Twig/Tests/Fixtures/templates/bundles/WebProfileBundle/Profiler/base.html.twig

Whitespace-only changes.

src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function parse(Token $token)
4040
$lineno = $token->getLine();
4141
$stream = $this->parser->getStream();
4242

43-
@trigger_error(sprintf('The "transchoice" tag is deprecated since Symfony 4.2, use the "trans" one instead with a "%count%" parameter in %s line %d.', $stream->getSourceContext()->getName(), $lineno), E_USER_DEPRECATED);
43+
@trigger_error(sprintf('The "transchoice" tag is deprecated since Symfony 4.2, use the "trans" one instead with a "%%count%%" parameter in %s line %d.', $stream->getSourceContext()->getName(), $lineno), E_USER_DEPRECATED);
4444

4545
$vars = new ArrayExpression(array(), $lineno);
4646

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.1.3",
20-
"symfony/contracts": "^1.0",
20+
"symfony/contracts": "^1.0.2",
2121
"twig/twig": "^1.35|^2.4.4"
2222
},
2323
"require-dev": {

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,4 @@ class TranslatorWithTranslatorBag implements TranslatorInterface
111111
public function trans($id, array $parameters = array(), $domain = null, $locale = null)
112112
{
113113
}
114-
115-
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
116-
{
117-
}
118-
119-
public function setLocale($locale)
120-
{
121-
}
122-
123-
public function getLocale()
124-
{
125-
}
126114
}

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTranslator.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,4 @@ public function trans($id, array $parameters = array(), $domain = null, $locale
1919
{
2020
return '[trans]'.$id.'[/trans]';
2121
}
22-
23-
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
24-
{
25-
return '[trans]'.$id.'[/trans]';
26-
}
27-
28-
public function setLocale($locale)
29-
{
30-
}
31-
32-
public function getLocale()
33-
{
34-
}
3522
}

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
"php": "^7.1.3",
2020
"ext-xml": "*",
2121
"symfony/cache": "~4.2",
22-
"symfony/dependency-injection": "^4.2",
2322
"symfony/config": "~4.2",
23+
"symfony/contracts": "^1.0.2",
24+
"symfony/dependency-injection": "^4.2",
2425
"symfony/event-dispatcher": "^4.1",
2526
"symfony/http-foundation": "^4.1.2",
2627
"symfony/http-kernel": "^4.2",

src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ public function provideDsnWithOptions()
193193
);
194194
}
195195

196+
public function testClear()
197+
{
198+
$this->assertTrue($this->createCachePool()->clear());
199+
}
200+
196201
public function testMultiServerDsn()
197202
{
198203
$dsn = 'memcached:?host[localhost]&host[localhost:12345]&host[/some/memcached.sock:]=3';

src/Symfony/Component/Cache/Traits/MemcachedTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ protected function doDelete(array $ids)
292292
*/
293293
protected function doClear($namespace)
294294
{
295-
return false;
295+
return '' === $namespace && $this->getClient()->flush();
296296
}
297297

298298
private function checkResultCode($result)

src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
1818
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1919
use Symfony\Component\HttpKernel\KernelEvents;
20-
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
21-
use Symfony\Contracts\Translation\TranslatorInterface;
20+
use Symfony\Component\Translation\TranslatorInterface;
21+
use Symfony\Contracts\Translation\LocaleAwareInterface;
2222

2323
/**
2424
* Synchronizes the locale between the request and the translator.
@@ -31,12 +31,12 @@ class TranslatorListener implements EventSubscriberInterface
3131
private $requestStack;
3232

3333
/**
34-
* @param TranslatorInterface $translator
34+
* @param LocaleAwareInterface $translator
3535
*/
3636
public function __construct($translator, RequestStack $requestStack)
3737
{
38-
if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
39-
throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
38+
if (!$translator instanceof TranslatorInterface && !$translator instanceof LocaleAwareInterface) {
39+
throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, LocaleAwareInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
4040
}
4141
$this->translator = $translator;
4242
$this->requestStack = $requestStack;

src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1818
use Symfony\Component\HttpKernel\EventListener\TranslatorListener;
1919
use Symfony\Component\HttpKernel\HttpKernelInterface;
20-
use Symfony\Contracts\Translation\TranslatorInterface;
20+
use Symfony\Contracts\Translation\LocaleAwareInterface;
2121

2222
class TranslatorListenerTest extends TestCase
2323
{
@@ -27,7 +27,7 @@ class TranslatorListenerTest extends TestCase
2727

2828
protected function setUp()
2929
{
30-
$this->translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
30+
$this->translator = $this->getMockBuilder(LocaleAwareInterface::class)->getMock();
3131
$this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
3232
$this->listener = new TranslatorListener($this->translator, $this->requestStack);
3333
}

src/Symfony/Component/HttpKernel/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.1.3",
20-
"symfony/contracts": "^1.0",
20+
"symfony/contracts": "^1.0.2",
2121
"symfony/event-dispatcher": "~4.1",
2222
"symfony/http-foundation": "^4.1.1",
2323
"symfony/debug": "~3.4|~4.0",

src/Symfony/Component/Translation/DataCollectorTranslator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Translation\Exception\InvalidArgumentException;
1515
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
16+
use Symfony\Contracts\Translation\LocaleAwareInterface;
1617
use Symfony\Contracts\Translation\TranslatorInterface;
1718

1819
/**
@@ -39,8 +40,8 @@ public function __construct($translator)
3940
if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
4041
throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
4142
}
42-
if (!$translator instanceof TranslatorBagInterface) {
43-
throw new InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface and TranslatorBagInterface.', \get_class($translator)));
43+
if (!$translator instanceof TranslatorBagInterface || !$translator instanceof LocaleAwareInterface) {
44+
throw new InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface, TranslatorBagInterface and LocaleAwareInterface.', \get_class($translator)));
4445
}
4546

4647
$this->translator = $translator;

src/Symfony/Component/Translation/Formatter/MessageFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function formatIntl(string $message, string $locale, array $parameters =
6666
*/
6767
public function choiceFormat($message, $number, $locale, array $parameters = array())
6868
{
69-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the format() one instead with a %count% parameter.', __METHOD__), E_USER_DEPRECATED);
69+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the format() one instead with a %%count%% parameter.', __METHOD__), E_USER_DEPRECATED);
7070

7171
$parameters = array('%count%' => $number) + $parameters;
7272

0 commit comments

Comments
 (0)
0