8000 Merge branch '5.2' into 5.3 · symfony/symfony@71c5c06 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71c5c06

Browse files
committed
Merge branch '5.2' into 5.3
* 5.2: [Messenger] Fix merging PrototypedArrayNode associative values [mailer] Remove useless code
2 parents 6bc4cbc + 174efe8 commit 71c5c06

File tree

5 files changed

+77
-48
lines changed

5 files changed

+77
-48
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"symfony/polyfill-mbstring": "~1.0",
5353
"symfony/polyfill-php73": "^1.11",
5454
"symfony/polyfill-php80": "^1.15",
55+
"symfony/polyfill-php81": "^1.22",
5556
"symfony/polyfill-uuid": "^1.15",
5657
"symfony/runtime": "self.version"
5758
},

src/Symfony/Component/Config/Definition/PrototypedArrayNode.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ protected function normalizeValue($value)
215215

216216
$value = $this->remapXml($value);
217217

218-
$isAssoc = array_keys($value) !== range(0, \count($value) - 1);
218+
$isList = array_is_list($value);
219219
$normalized = [];
220220
foreach ($value as $k => $v) {
221221
if (null !== $this->keyAttribute && \is_array($v)) {
222-
if (!isset($v[$this->keyAttribute]) && \is_int($k) && !$isAssoc) {
222+
if (!isset($v[$this->keyAttribute]) && \is_int($k) && $isList) {
223223
$ex = new InvalidConfigurationException(sprintf('The attribute "%s" must be set for path "%s".', $this->keyAttribute, $this->getPath()));
224224
$ex->setPath($this->getPath());
225225

@@ -261,7 +261,7 @@ protected function normalizeValue($value)
261261
}
262262

263263
$prototype = $this->getPrototypeForChild($k);
264-
if (null !== $this->keyAttribute || $isAssoc) {
264+
if (null !== $this->keyAttribute || !$isList) {
265265
$normalized[$k] = $prototype->normalize($v);
266266
} else {
267267
$normalized[] = $prototype->normalize($v);
@@ -294,9 +294,10 @@ protected function mergeValues($leftSide, $rightSide)
294294
return $rightSide;
295295
}
296296

297+
$isList = array_is_list($rightSide);
297298
foreach ($rightSide as $k => $v) {
298-
// prototype, and key is irrelevant, append the element
299-
if (null === $this->keyAttribute) {
299+
// prototype, and key is irrelevant there are no named keys, append the element
300+
if (null === $this->keyAttribute && $isList) {
300301
$leftSide[] = $v;
301302
continue;
302303
}

src/Symfony/Component/Config/Tests/Definition/PrototypedArrayNodeTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,56 @@ public function getDataForKeyRemovedLeftValueOnly()
338338
],
339339
];
340340
}
341+
342+
/**
343+
* @dataProvider getPrototypedArrayNodeDataToMerge
344+
*/
345+
public function testPrototypedArrayNodeMerge($left, $right, $expected)
346+
{
347+
$node = new PrototypedArrayNode('options');
348+
$node->setNormalizeKeys(false);
349+
$node->setPrototype(new VariableNode('value'));
350+
$node->setDefaultValue([]);
351+
352+
$result = $node->merge($left, $right);
353+
354+
self::assertSame($result, $expected);
355+
}
356+
357+
public function getPrototypedArrayNodeDataToMerge()
358+
{
359+
return [
360+
// data to merged is a plain array
361+
[
362+
['foo', 'bar'],
363+
['foo', 'baz', 'qux'],
364+
['foo', 'bar', 'foo', 'baz', 'qux'],
365+
],
366+
// data to be merged is an associative array
367+
[
368+
['option1' => true, 'option2' => 'foo'],
369+
[
370+
'option2' => 'bar',
371+
'option3' => 42,
372+
'option4' => [
373+
'option41' => 'baz',
374+
'option42' => [
375+
'option423' => 'qux',
376+
],
377+
],
378+
],
379+
[
380+
'option1' => true,
381+
'option2' => 'bar',
382+
'option3' => 42,
383+
'option4' => [
384+
'option41' => 'baz',
385+
'option42' => [
386+
'option423' => 'qux',
387+
],
388+
],
389+
],
390+
],
391+
];
392+
}
341393
}

src/Symfony/Component/Config/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"symfony/deprecation-contracts": "^2.1",
2121
"symfony/filesystem": "^4.4|^5.0",
2222
"symfony/polyfill-ctype": "~1.8",
23-
"symfony/polyfill-php80": "^1.15"
23+
"symfony/polyfill-php80": "^1.15",
24+
"symfony/polyfill-php81": "^1.22"
2425
},
2526
"require-dev": {
2627
"symfony/event-dispatcher": "^4.4|^5.0",

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesTransportFactory.php

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
use AsyncAws\Core\Configuration;
1515
use AsyncAws\Ses\SesClient;
16-
use Symfony\Component\HttpClient\HttpClient;
17-
use Symfony\Component\Mailer\Exception\LogicException;
1816
use Symfony\Component\Mailer\Exception\UnsupportedSchemeException;
1917
use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
2018
use Symfony\Component\Mailer\Transport\Dsn;
@@ -35,46 +33,22 @@ public function create(Dsn $dsn): TransportInterface
3533
return new SesSmtpTransport($this->getUser($dsn), $this->getPassword($dsn), $region, $this->dispatcher, $this->logger);
3634
}
3735

38-
if (!class_exists(SesClient::class)) {
39-
if (!class_exists(HttpClient::class)) {
40-
throw new \LogicException(sprintf('You cannot use "%s" as the HttpClient component or AsyncAws package is not installed. Try running "composer require async-aws/ses".', __CLASS__));
41-
}
42-
43-
trigger_deprecation('symfony/amazon-mailer', '5.1', 'Using the "%s" transport without AsyncAws is deprecated. Try running "composer require async-aws/ses".', $scheme, static::class);
44-
45-
$user = $this->getUser($dsn);
46-
$password = $this->getPassword($dsn);
47-
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
48-
$port = $dsn->getPort();
49-
50-
if ('ses+api' === $scheme) {
51-
if (!\extension_loaded('simplexml')) {
52-
throw new LogicException(sprintf('Cannot use "%s". Make sure you have "ext-simplexml" installed and enabled.', SesApiTransport::class));
53-
}
54-
55-
return (new SesApiTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
56-
}
57-
if ('ses+https' === $scheme || 'ses' === $scheme) {
58-
return (new SesHttpTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
59-
}
60-
} else {
61-
switch ($scheme) {
62-
case 'ses+api':
63-
$class = SesApiAsyncAwsTransport::class;
64-
// no break
65-
case 'ses':
66-
case 'ses+https':
67-
$class = $class ?? SesHttpAsyncAwsTransport::class;
68-
$options = [
69-
'region' => $dsn->getOption('region') ?: 'eu-west-1',
70-
'accessKeyId' => $dsn->getUser(),
71-
'accessKeySecret' => $dsn->getPassword(),
72-
] + (
73-
'default' === $dsn->getHost() ? [] : ['endpoint' => 'https://'.$dsn->getHost().($dsn->getPort() ? ':'.$dsn->getPort() : '')]
74-
);
75-
76-
return new $class(new SesClient(Configuration::create($options), null, $this->client, $this->logger), $this->dispatcher, $this->logger);
77-
}
36+
switch ($scheme) {
37+
case 'ses+api':
38+
$class = SesApiAsyncAwsTransport::class;
39+
// no break
40+
case 'ses':
41+
case 'ses+https':
42+
$class = $class ?? SesHttpAsyncAwsTransport::class;
43+
$options = [
44+
'region' => $dsn->getOption('region') ?: 'eu-west-1',
45+
'accessKeyId' => $dsn->getUser(),
46+
'accessKeySecret' => $dsn->getPassword(),
47+
] + (
48+
'default' === $dsn->getHost() ? [] : ['endpoint' => 'https://'.$dsn->getHost().($dsn->getPort() ? ':'.$dsn->getPort() : '')]
49+
);
50+
51+
return new $class(new SesClient(Configuration::create($options), null, $this->client, $this->logger), $this->dispatcher, $this->logger);
7852
}
7953

8054
throw new UnsupportedSchemeException($dsn, 'ses', $this->getSupportedSchemes());

0 commit comments

Comments
 (0)
0