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

Skip to content

Commit 27d10a6

Browse files
author
Robin Chalas
committed
Merge branch '4.2'
* 4.2: Fix url matcher edge cases with trailing slash [Form] Fix author tag + exception messages [TwigBridge] Fix deprecation on twig 2.9 Fix left-associative ternary deprecation warnings for PHP 7.4 [Validator] Fixed imprecise translations [Validator] Add Dutch translations [Security] Cleanup "Digest nonce has expired." translation Intercept redirections only for HTML format [PhpUnitBridge] fix reading phpunit.xml on bootstrap resolve class name parameters Fix name and phpdoc of ContainerBuilder::removeBindings [Intl] Update the ICU data to 64.2
2 parents a7d12ee + 7947b26 commit 27d10a6

File tree

306 files changed

+666
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

306 files changed

+666
-439
lines changed

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ $getEnvVar = function ($name, $default = false) {
3737
}
3838
if (false !== $phpunitConfig) {
3939
$var = new DOMXpath($phpunitConfig);
40+
foreach ($var->query('//php/server[@name="'.$name.'"]') as $var) {
41+
return $var->getAttribute('value');
42+
}
4043
foreach ($var->query('//php/env[@name="'.$name.'"]') as $var) {
4144
return $var->getAttribute('value');
4245
}
@@ -94,7 +97,7 @@ $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rt
9497
: 'composer';
9598

9699

97-
$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy symfony/yaml');
100+
$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml': ''));
98101

99102
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) {
100103
// Build a standalone phpunit without symfony/yaml nor prophecy by default

src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Twig\Node\Node;
2525
use Twig\Node\SetNode;
2626
use Twig\NodeVisitor\AbstractNodeVisitor;
27+
use Twig\TokenParser\ApplyTokenParser;
2728

2829
/**
2930
* @author Fabien Potencier <fabien@symfony.com>
@@ -95,7 +96,8 @@ protected function doEnterNode(Node $node, Environment $env)
9596
protected function doLeaveNode(Node $node, Environment $env)
9697
{
9798
if ($node instanceof TransDefaultDomainNode) {
98-
return false;
99+
// must return null as of Twig 2.9
100+
return class_exists(ApplyTokenParser::class) ? null : false;
99101
}
100102

101103
if ($node instanceof BlockNode || $node instanceof ModuleNode) {

src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function onKernelResponse(FilterResponseEvent $event)
8787
return;
8888
}
8989

90-
if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
90+
if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects && 'html' === $request->getRequestFormat()) {
9191
$session = $request->getSession();
9292
if (null !== $session && $session->isStarted() && $session->getFlashBag() instanceof AutoExpireFlashBag) {
9393
// keep current flashes for one more request if using AutoExpireFlashBag

src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getInjectToolbarTests()
5858
/**
5959
* @dataProvider provideRedirects
6060
*/
61-
public function testRedirectionIsIntercepted($statusCode, $hasSession)
61+
public function testHtmlRedirectionIsIntercepted($statusCode, $hasSession)
6262
{
6363
$response = new Response('Some content', $statusCode);
6464
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
@@ -71,6 +71,19 @@ public function testRedirectionIsIntercepted($statusCode, $hasSession)
7171
$this->assertEquals('Redirection', $response->getContent());
7272
}
7373

74+
public function testNonHtmlRedirectionIsNotIntercepted()
75+
{
76+
$response = new Response('Some content', '301');
77+
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
78+
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'json', true), HttpKernelInterface::MASTER_REQUEST, $response);
79+
80+
$listener = new WebDebugToolbarListener($this->getTwigMock('Redirection'), true);
81+
$listener->onKernelResponse($event);
82+
83+
$this->assertEquals(301, $response->getStatusCode());
84+
$this->assertEquals('Some content', $response->getContent());
85+
}
86+
7487
public function testToolbarIsInjected()
7588
{
7689
$response = new Response('<html><head></head><body></body></html>');

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,13 +1506,13 @@ public function getRemovedBindingIds()
15061506
}
15071507

15081508
/**
1509-
* Adds a removed binding id.
1509+
* Removes bindings for a service.
15101510
*
1511-
* @param int $id
1511+
* @param string $id The service identifier
15121512
*
15131513
* @internal
15141514
*/
1515-
public function addRemovedBindingIds($id)
1515+
public function removeBindings($id)
15161516
{
15171517
if ($this->hasDefinition($id)) {
15181518
foreach ($this->getDefinition($id)->getBindings() as $key => $binding) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __destruct()
6161
{
6262
parent::__destruct();
6363

64-
$this->container->addRemovedBindingIds($this->id);
64+
$this->container->removeBindings($this->id);
6565

6666
if (!$this->definition instanceof ChildDefinition) {
6767
$this->container->setDefinition($this->id, $this->definition->setInstanceofConditionals($this->instanceof));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function registerClasses(Definition $prototype, $namespace, $resource, $e
9191
*/
9292
protected function setDefinition($id, Definition $definition)
9393
{
94-
$this->container->addRemovedBindingIds($id);
94+
$this->container->removeBindings($id);
9595

9696
if ($this->isLoadingInstanceof) {
9797
if (!$definition instanceof ChildDefinition) {

src/Symfony/Component/Form/DependencyInjection/FormPass.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,20 @@ private function processFormTypeExtensions(ContainerBuilder $container)
9292
$serviceDefinition = $container->getDefinition($serviceId);
9393

9494
$tag = $serviceDefinition->getTag($this->formTypeExtensionTag);
95+
$typeExtensionClass = $container->getParameterBag()->resolveValue($serviceDefinition->getClass());
96+
9597
if (isset($tag[0]['extended_type'])) {
96-
if (!method_exists($serviceDefinition->getClass(), 'getExtendedTypes')) {
97-
@trigger_error(sprintf('Not implementing the static getExtendedTypes() method in %s when implementing the %s is deprecated since Symfony 4.2. The method will be added to the interface in 5.0.', $serviceDefinition->getClass(), FormTypeExtensionInterface::class), E_USER_DEPRECATED);
98+
if (!method_exists($typeExtensionClass, 'getExtendedTypes')) {
99+
@trigger_error(sprintf('Not implementing the static getExtendedTypes() method in %s when implementing the %s is deprecated since Symfony 4.2. The method will be added to the interface in 5.0.', $typeExtensionClass, FormTypeExtensionInterface::class), E_USER_DEPRECATED);
98100
}
99101

100102
$typeExtensions[$tag[0]['extended_type']][] = new Reference($serviceId);
101-
$typeExtensionsClasses[] = $serviceDefinition->getClass();
102-
} elseif (method_exists($serviceDefinition->getClass(), 'getExtendedTypes')) {
103+
$typeExtensionsClasses[] = $typeExtensionClass;
104+
} elseif (method_exists($typeExtensionClass, 'getExtendedTypes')) {
103105
$extendsTypes = false;
104106

105-
$typeExtensionsClasses[] = $serviceDefinition->getClass();
106-
foreach ($serviceDefinition->getClass()::getExtendedTypes() as $extendedType) {
107+
$typeExtensionsClasses[] = $typeExtensionClass;
108+
foreach ($typeExtensionClass::getExtendedTypes() as $extendedType) {
107109
$typeExtensions[$extendedType][] = new Reference($serviceId);
108110
$extendsTypes = true;
109111
}
@@ -112,7 +114,7 @@ private function processFormTypeExtensions(ContainerBuilder $container)
112114
throw new InvalidArgumentException(sprintf('The getExtendedTypes() method for service "%s" does not return any extended types.', $serviceId));
113115
}
114116
} else {
115-
throw new InvalidArgumentException(sprintf('"%s" tagged services have to implement the static getExtendedTypes() method. The class for service "%s" does not implement it.', $this->formTypeExtensionTag, $serviceId));
117+
throw new InvalidArgumentException(sprintf('"%s" tagged services have to implement the static getExtendedTypes() method. Class "%s" for service "%s" does not implement it.', $this->formTypeExtensionTag, $typeExtensionClass, $serviceId));
116118
}
117119
}
118120

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeZoneToStringTransformer.php

Lines changed: 5 additions & 5 deletions
7189
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* Transforms between a timezone identifier string and a DateTimeZone object.
1919
*
20-
* @author Roland Franssen <franssen.roland@gmai.com>
20+
* @author Roland Franssen <franssen.roland@gmail.com>
2121
*/
2222
class DateTimeZoneToStringTransformer implements DataTransformerInterface
2323
{
@@ -39,14 +39,14 @@ public function transform($dateTimeZone)
3939

4040
if ($this->multiple) {
4141
if (!\is_array($dateTimeZone)) {
42-
throw new TransformationFailedException('Expected an array.');
42+
throw new TransformationFailedException('Expected an array of \DateTimeZone objects.');
4343
}
4444

4545
return array_map([new self(), 'transform'], $dateTimeZone);
4646
}
4747

4848
if (!$dateTimeZone instanceof \DateTimeZone) {
49-
throw new TransformationFailedException('Expected a \DateTimeZone.');
49+
throw new TransformationFailedException('Expected a \DateTimeZone object.');
5050
}
5151

5252
return $dateTimeZone->getName();
@@ -63,14 +63,14 @@ public function reverseTransform($value)
6363

6464
if ($this->multiple) {
6565
if (!\is_array($value)) {
66-
throw new TransformationFailedException('Expected an array.');
66+
throw new TransformationFailedException('Expected an array of timezone identifier strings.');
6767
}
6868

6969
return array_map([new self(), 'reverseTransform'], $value);
7070
}
7171

7272
if (!\is_string($value)) {
73-
throw new TransformationFailedException('Expected a string.');
73+
throw new TransformationFailedException('Expected a timezone identifier string.');
7474
}
7575

7676
try {

src/Symfony/Component/Form/Tests/DependencyInjection/FormPassTest.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,14 @@ public function testAddTaggedTypesToDebugCommand()
9797
/**
9898
* @dataProvider addTaggedTypeExtensionsDataProvider
9999
*/
100-
public function testAddTaggedTypeExtensions(array $extensions, array $expectedRegisteredExtensions)
100+
public function testAddTaggedTypeExtensions(array $extensions, array $expectedRegisteredExtensions, array $parameters = [])
101101
{
102102
$container = $this->createContainerBuilder();
103103

104+
foreach ($parameters as $name => $value) {
105+
$container->setParameter($name, $value);
106+
}
107+
104108
$container->setDefinition('form.extension', $this->createExtensionDefinition());
105109

106110
foreach ($extensions as $serviceId => $config) {
@@ -191,6 +195,27 @@ public function addTaggedTypeExtensionsDataProvider()
191195
]),
192196
],
193197
],
198+
[
199+
[
200+
'my.type_extension1' => [
201+
'class' => '%type1_extension_class%',
202+
'tag' => ['extended_type' => 'type1'],
203+
],
204+
'my.type_extension2' => [
205+
'class' => '%type1_extension_class%',
206+
'tag' => [],
207+
],
208+
],
209+
[
210+
'type1' => new IteratorArgument([
211+
new Reference('my.type_extension1'),
212+
new Reference('my.type_extension2'),
213+
]),
214+
],
215+
[
216+
'type1_extension_class' => Type1TypeExtension::class,
217+
],
218+
],
194219
];
195220
}
196221

@@ -261,7 +286,7 @@ public function addLegacyTaggedTypeExtensionsDataProvider()
261286

262287
/**
263288
* @expectedException \InvalidArgumentException
264-
* @expectedExceptionMessage "form.type_extension" tagged services have to implement the static getExtendedTypes() method. The class for service "my.type_extension" does not implement it.
289+
* @expectedExceptionMessage "form.type_extension" tagged services have to implement the static getExtendedTypes() method. Class "stdClass" for service "my.type_extension" does not implement it.
265290
*/
266291
public function testAddTaggedFormTypeExtensionWithoutExtendedTypeAttributeNorImplementingGetExtendedTypes()
267292
{

0 commit comments

Comments
 (0)
0