Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa975a8

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: Fix CS Fix CS quote address names if they contain parentheses [FrameworkBundle] Fail gracefully when forms use disabled CSRF [Mime] Fix inline parts when added via attachPart() Fail gracefully when attempting to autowire composite types [VarDumper] Add a test case for nesting intersection and union types Fix #46592 - Ignore getter with required parameters [Serializer] Fix inconsistent behaviour of nullable objects in key/value arrays
2 parents aabc22b + 72edb56 commit aa975a8

25 files changed

+701
-28
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+4
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,10 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
708708
}
709709

710710
if ($this->isConfigEnabled($container, $config['form']['csrf_protection'])) {
711+
if (!$container->hasDefinition('security.csrf.token_generator')) {
712+
throw new \LogicException('To use form CSRF protection, "framework.csrf_protection" must be enabled.');
713+
}
714+
711715
$loader->load('form_csrf.php');
712716

713717
$container->setParameter('form.type_extension.csrf.enabled', true);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'csrf_protection' => false,
5+
'form' => [
6+
'csrf_protection' => true,
7+
],
8+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services
7+
https://symfony.com/schema/dic/services/services-1.0.xsd
8+
http://symfony.com/schema/dic/symfony
9+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
10+
>
11+
<framework:config>
12+
<framework:csrf-protection enabled="false"/>
13+
<framework:form enabled="true">
14+
<framework:csrf-protection enabled="true"/>
15+
</framework:form>
16+
</framework:config>
17+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
csrf_protection: false
3+
form:
4+
csrf_protection: true

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ public function testFormCsrfProtection()
100100
$this->assertEquals('%form.type_extension.csrf.field_name%', $def->getArgument(2));
101101
}
102102

103+
public function testFormCsrfProtectionWithCsrfDisabled()
104+
{
105+
$this->expectException(\LogicException::class);
106+
$this->expectExceptionMessage('To use form CSRF protection `framework.csrf_protection` must be enabled.');
107+
108+
$this->createContainerFromFile('form_csrf_disabled');
109+
}
110+
103111
public function testPropertyAccessWithDefaultValue()
104112
{
105113
$container = $this->createContainerFromFile('full');

src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa
3232
return null;
3333
}
3434

35+
return self::getTypeHintForType($type, $r, $noBuiltin);
36+
}
37+
38+
private static function getTypeHintForType(\ReflectionType $type, \ReflectionFunctionAbstract $r, bool $noBuiltin): ?string
39+
{
3540
$types = [];
3641
$glue = '|';
3742
if ($type instanceof \ReflectionUnionType) {
@@ -46,6 +51,17 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa
4651
}
4752

4853
foreach ($reflectionTypes as $type) {
54+
if ($type instanceof \ReflectionIntersectionType) {
55+
$typeHint = self::getTypeHintForType($type, $r, $noBuiltin);
56+
if (null === $typeHint) {
57+
return null;
58+
}
59+
60+
$types[] = sprintf('(%s)', $typeHint);
61+
62+
continue;
63+
}
64+
4965
if ($type->isBuiltin()) {
5066
if (!$noBuiltin) {
5167
$types[] = $type->getName();

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

+40-3
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ public function testTypeNotGuessableNoServicesFound()
243243

244244
public function testTypeNotGuessableUnionType()
245245
{
246-
$this->expectException(AutowiringFailedException::class);
247-
$this->expectExceptionMessage('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\UnionClasses::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionA|Symfony\Component\DependencyInjection\Tests\Compiler\CollisionB" but this class was not found.');
248246
$container = new ContainerBuilder();
249247

250248
$container->register(CollisionA::class);
@@ -254,6 +252,9 @@ public function testTypeNotGuessableUnionType()
254252
$aDefinition->setAutowired(true);
255253

256254
$pass = new AutowirePass();
255+
256+
$this->expectException(AutowiringFailedException::class);
257+
$this->expectExceptionMessage('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\UnionClasses::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionA|Symfony\Component\DependencyInjection\Tests\Compiler\CollisionB" but this class was not found.');
257258
$pass->process($container);
258259
}
259260

@@ -287,7 +288,27 @@ public function testTypeNotGuessableIntersectionType()
287288
$pass = new AutowirePass();
288289

289290
$this->expectException(AutowiringFailedException::class);
290-
$this->expectExceptionMessage('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\IntersectionClasses::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\AnotherInterface&Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but this class was not found.');
291+
$this->expectExceptionMessage('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\IntersectionClasses::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface&Symfony\Component\DependencyInjection\Tests\Compiler\AnotherInterface" but this class was not found.');
292+
$pass->process($container);
293+
}
294+
295+
/**
296+
* @requires PHP 8.2
297+
*/
298+
public function testTypeNotGuessableCompositeType()
299+
{
300+
$container = new ContainerBuilder();
301+
302+
$container->register(CollisionInterface::class);
303+
$container->register(AnotherInterface::class);
304+
305+
$aDefinition = $container->register('a', CompositeTypeClasses::class);
306+
$aDefinition->setAutowired(true);
307+
308+
$pass = new AutowirePass();
309+
310+
$this->expectException(AutowiringFailedException::class);
311+
$this->expectExceptionMessage('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CompositeTypeClasses::__construct()" has type "(Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface&Symfony\Component\DependencyInjection\Tests\Compiler\AnotherInterface)|Symfony\Component\DependencyInjection\Tests\Compiler\YetAnotherInterface" but this class was not found.');
291312
$pass->process($container);
292313
}
293314

@@ -405,6 +426,22 @@ public function testParameterWithNullUnionIsSkipped()
405426
$this->assertNull($definition->getArgument(0));
406427
}
407428

429+
/**
430+
* @requires PHP 8.2
431+
*/
432+
public function testParameterWithNullableIntersectionIsSkipped()
433+
{
434+
$container = new ContainerBuilder();
435+
436+
$optDefinition = $container->register('opt', NullableIntersection::class);
437+
$optDefinition->setAutowired(true);
438+
439+
(new AutowirePass())->process($container);
440+
441+
$definition = $container->getDefinition('opt');
442+
$this->assertNull($definition->getArgument(0));
443+
}
444+
408445
public function testParameterWithNullUnionIsAutowired()
409446
{
410447
$container = new ContainerBuilder();

src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
require __DIR__.'/uniontype_classes.php';
88
require __DIR__.'/autowiring_classes_80.php';
99
require __DIR__.'/intersectiontype_classes.php';
10+
if (\PHP_VERSION_ID >= 80200) {
11+
require __DIR__.'/compositetype_classes.php';
12+
}
1013

1114
class Foo
1215
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
4+
5+
interface YetAnotherInterface
6+
{
7+
}
8+
9+
class CompositeTypeClasses
10+
{
11+
public function __construct((CollisionInterface&AnotherInterface)|YetAnotherInterface $collision)
12+
{
13+
}
14+
}
15+
16+
class NullableIntersection
17+
{
18+
public function __construct((CollisionInterface&AnotherInterface)|null $a)
19+
{
20+
}
21+
}

src/Symfony/Component/Mime/Email.php

+19-7
Original file line numberDiff line numberDiff line change
@@ -501,25 +501,37 @@ private function prepareParts(): ?array
501501
$names = array_filter(array_unique($names));
502502
}
503503

504+
// usage of reflection is a temporary workaround for missing getters that will be added in 6.2
505+
$dispositionRef = new \ReflectionProperty(TextPart::class, 'disposition');
506+
$dispositionRef->setAccessible(true);
507+
$nameRef = new \ReflectionProperty(TextPart::class, 'name');
508+
$nameRef->setAccessible(true);
504509
$attachmentParts = $inlineParts = [];
505510
foreach ($this->attachments as $attachment) {
511+
$part = $this->createDataPart($attachment);
512+
if (isset($attachment['part'])) {
513+
$attachment['name'] = $nameRef->getValue($part);
514+
}
515+
506516
foreach ($names as $name) {
507-
if (isset($attachment['part'])) {
508-
continue;
509-
}
510517
if ($name !== $attachment['name']) {
511518
continue;
512519
}
513520
if (isset($inlineParts[$name])) {
514521
continue 2;
515522
}
516-
$attachment['inline'] = true;
517-
$inlineParts[$name] = $part = $this->createDataPart($attachment);
523+
$part->setDisposition('inline');
518524
$html = str_replace('cid:'.$name, 'cid:'.$part->getContentId(), $html);
519525
$part->setName($part->getContentId());
520-
continue 2;
526+
527+
break;
528+
}
529+
530+
if ('inline' === $dispositionRef->getValue($part)) {
531+
$inlineParts[$attachment['name']] = $part;
532+
} else {
533+
$attachmentParts[] = $part;
521534
}
522-
$attachmentParts[] = $this->createDataPart($attachment);
523535
}
524536
if (null !== $htmlPart) {
525537
$htmlPart = new TextPart($html, $this->htmlCharset, 'html');

src/Symfony/Component/Mime/Header/AbstractHeader.php

+5
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ protected function createPhrase(HeaderInterface $header, string $string, string
109109
}
110110
$phraseStr = $this->encodeWords($header, $string, $usedLength);
111111
}
112+
} elseif (str_contains($phraseStr, '(')) {
113+
foreach (['\\', '"'] as $char) {
114+
$phraseStr = str_replace($char, '\\'.$char, $phraseStr);
115+
}
116+
$phraseStr = '"'.$phraseStr.'"';
112117
}
113118

114119
return $phraseStr;

0 commit comments

Comments
 (0)