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

Skip to content

Commit fc78e20

Browse files
Merge branch '4.3' into 4.4
* 4.3: [FrameworkBundle] Fix framework bundle lock configuration not working as expected [Validator] Add the missing translations for the Azerbaijani locale [HttpClient] workaround bad Content-Length sent by old libcurl [Cache] dont override native Memcached options Fix CS Fix exceptions (PDOException) error code type Fix return type of Process::restart(). [Cache] fail gracefully when locking is not supported [HttpClient] fix race condition when reading response with informational status Names for buttons should start with lowercase
2 parents 7f43dc4 + dff71ce commit fc78e20

File tree

17 files changed

+289
-17
lines changed

17 files changed

+289
-17
lines changed

UPGRADE-4.3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Form
9696
----
9797

9898
* Using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled is deprecated.
99-
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
99+
* Using names for buttons that do not start with a lowercase letter, a digit, or an underscore is deprecated and will lead to an
100100
exception in 5.0.
101101
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and
102102
will lead to an exception in 5.0.

UPGRADE-5.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Form
160160
without configuring a reference date.
161161
* Removed support for using `int` or `float` as data for the `NumberType` when the `input` option is set to `string`.
162162
* Removed support for using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled.
163-
* Using names for buttons that do not start with a letter, a digit, or an underscore leads to an exception.
163+
* Using names for buttons that do not start with a lowercase letter, a digit, or an underscore leads to an exception.
164164
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons leads to an
165165
exception.
166166
* Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,11 @@ private function addLockSection(ArrayNodeDefinition $rootNode)
10741074
->ifString()->then(function ($v) { return ['enabled' => true, 'resources' => $v]; })
10751075
->end()
10761076
->beforeNormalization()
1077-
->ifTrue(function ($v) { return \is_array($v) && !isset($v['resources']); })
1077+
->ifTrue(function ($v) { return \is_array($v) && !isset($v['enabled']); })
1078+
->then(function ($v) { return $v + ['enabled' => true]; })
1079+
->end()
1080+
->beforeNormalization()
1081+
->ifTrue(function ($v) { return \is_array($v) && !isset($v['resources']) && !isset($v['resource']); })
10781082
->then(function ($v) {
10791083
$e = $v['enabled'];
10801084
unset($v['enabled']);
@@ -1093,7 +1097,19 @@ private function addLockSection(ArrayNodeDefinition $rootNode)
10931097
->end()
10941098
->beforeNormalization()
10951099
->ifTrue(function ($v) { return \is_array($v) && array_keys($v) === range(0, \count($v) - 1); })
1096-
->then(function ($v) { return ['default' => $v]; })
1100+
->then(function ($v) {
1101+
$resources = [];
1102+
foreach ($v as $resource) {
1103+
$resources = array_merge_recursive(
1104+
$resources,
1105+
\is_array($resource) && isset($resource['name'])
1106+
? [$resource['name'] => $resource['value']]
1107+
: ['default' => $resource]
1108+
);
1109+
}
1110+
1111+
return $resources;
1112+
})
10971113
->end()
10981114
->prototype('array')
10991115
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,69 @@ public function provideInvalidAssetConfigurationTests()
187187
yield [$createPackageConfig($config), 'You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.'];
188188
}
189189

190+
/**
191+
* @dataProvider provideValidLockConfigurationTests
192+
*/
193+
public function testValidLockConfiguration($lockConfig, $processedConfig)
194+
{
195+
$processor = new Processor();
196+
$configuration = new Configuration(true);
197+
$config = $processor->processConfiguration($configuration, [
198+
[
199+
'lock' => $lockConfig,
200+
],
201+
]);
202+
203+
$this->assertArrayHasKey('lock', $config);
204+
205+
$this->assertEquals($processedConfig, $config['lock']);
206+
}
207+
208+
public function provideValidLockConfigurationTests()
209+
{
210+
yield [null, ['enabled' => true, 'resources' => ['default' => [class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphore' : 'flock']]]];
211+
212+
yield ['flock', ['enabled' => true, 'resources' => ['default' => ['flock']]]];
213+
yield [['flock', 'semaphore'], ['enabled' => true, 'resources' => ['default' => ['flock', 'semaphore']]]];
214+
yield [['foo' => 'flock', 'bar' => 'semaphore'], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
215+
yield [['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore'], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
216+
yield [['default' => 'flock'], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
217+
218+
yield [['enabled' => false, 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
219+
yield [['enabled' => false, ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['default' => ['flock', 'semaphore']]]];
220+
yield [['enabled' => false, 'foo' => 'flock', 'bar' => 'semaphore'], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
221+
yield [['enabled' => false, 'foo' => ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore']]]];
222+
yield [['enabled' => false, 'default' => 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
223+
224+
yield [['resources' => 'flock'], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
225+
yield [['resources' => ['flock', 'semaphore']], ['enabled' => true, 'resources' => ['default' => ['flock', 'semaphore']]]];
226+
yield [['resources' => ['foo' => 'flock', 'bar' => 'semaphore']], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
227+
yield [['resources' => ['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore']], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
228+
yield [['resources' => ['default' => 'flock']], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
229+
230+
yield [['enabled' => false, 'resources' => 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
231+
yield [['enabled' => false, 'resources' => ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['default' => ['flock', 'semaphore']]]];
232+
yield [['enabled' => false, 'resources' => ['foo' => 'flock', 'bar' => 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
233+
yield [['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
234+
yield [['enabled' => false, 'resources' => ['default' => 'flock']], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
235+
236+
// xml
237+
238+
yield [['resource' => ['flock']], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
239+
yield [['resource' => ['flock', ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['default' => ['flock'], 'foo' => ['semaphore']]]];
240+
yield [['resource' => [['name' => 'foo', 'value' => 'flock']]], ['enabled' => true, 'resources' => ['foo' => ['flock']]]];
241+
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore']]]];
242+
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
243+
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
244+
245+
yield [['enabled' => false, 'resource' => ['flock']], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
246+
yield [['enabled' => false, 'resource' => ['flock', ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['default' => ['flock'], 'foo' => ['semaphore']]]];
247+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock']]], ['enabled' => false, 'resources' => ['foo' => ['flock']]]];
248+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore']]]];
249+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
250+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
251+
}
252+
190253
public function testItShowANiceMessageIfTwoMessengerBusesAreConfiguredButNoDefaultBus()
191254
{
192255
$expectedMessage = 'You must specify the "default_bus" if you define more than one bus.';

src/Symfony/Component/Cache/LockRegistry.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ public static function compute(callable $callback, ItemInterface $item, bool &$s
9090
while (true) {
9191
try {
9292
// race to get the lock in non-blocking mode
93-
if (flock($lock, LOCK_EX | LOCK_NB)) {
94-
$logger && $logger->info('Lock acquired, now computing item "{key}"', ['key' => $item->getKey()]);
93+
$locked = flock($lock, LOCK_EX | LOCK_NB, $wouldBlock);
94+
95+
if ($locked || !$wouldBlock) {
96+
$logger && $logger->info(sprintf('Lock %s, now computing item "{key}"', $locked ? 'acquired' : 'not supported'), ['key' => $item->getKey()]);
9597
self::$lockedFiles[$key] = true;
9698

9799
$value = $callback($item, $save);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ trait MemcachedTrait
2828
'persistent_id' => null,
2929
'username' => null,
3030
'password' => null,
31-
'serializer' => 'php',
31+
\Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_PHP,
3232
];
3333

3434
private $marshaller;

src/Symfony/Component/Form/ButtonBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct(?string $name, array $options = [])
6363

6464
if (preg_match('/^([^a-z0-9_].*)?(.*[^a-zA-Z0-9_\-:].*)?$/D', $name, $matches)) {
6565
if (isset($matches[1])) {
66-
@trigger_error(sprintf('Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated since Symfony 4.3 and will throw an exception in 5.0 ("%s" given).', $name), E_USER_DEPRECATED);
66+
@trigger_error(sprintf('Using names for buttons that do not start with a lowercase letter, a digit, or an underscore is deprecated since Symfony 4.3 and will throw an exception in 5.0 ("%s" given).', $name), E_USER_DEPRECATED);
6767
}
6868
if (isset($matches[2])) {
6969
@trigger_error(sprintf('Using names for buttons that do not contain only letters, digits, underscores ("_"), hyphens ("-") and colons (":") ("%s" given) is deprecated since Symfony 4.3 and will throw an exception in 5.0.', $name), E_USER_DEPRECATED);

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CHANGELOG
1818

1919
* added a `symbol` option to the `PercentType` that allows to disable or customize the output of the percent character
2020
* Using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled is deprecated.
21-
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
21+
* Using names for buttons that do not start with a lowercase letter, a digit, or an underscore is deprecated and will lead to an
2222
exception in 5.0.
2323
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and
2424
will lead to an exception in 5.0.

src/Symfony/Component/Form/Tests/ButtonBuilderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public function testNameContainingIllegalCharacters()
4747
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder('button[]'));
4848
}
4949

50+
/**
51+
* @group legacy
52+
*/
53+
public function testNameStartingWithIllegalCharacters()
54+
{
55+
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder('Button'));
56+
}
57+
5058
public function getInvalidNames()
5159
{
5260
return [

src/Symfony/Component/HttpClient/CurlHttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function request(string $method, string $url, array $options = []): Respo
269269
if ('POST' !== $method) {
270270
$curlopts[CURLOPT_UPLOAD] = true;
271271
}
272-
} elseif ('' !== $body) {
272+
} elseif ('' !== $body || 'POST' === $method) {
273273
$curlopts[CURLOPT_POSTFIELDS] = $body;
274274
}
275275

@@ -383,7 +383,7 @@ private static function handlePush($parent, $pushed, array $requestHeaders, Curl
383383
*/
384384
private static function acceptPushForRequest(string $method, array $options, PushedResponse $pushedResponse): bool
385385
{
386-
if ($options['body'] || $method !== $pushedResponse->requestHeaders[':method'][0]) {
386+
if ('' !== $options['body'] || $method !== $pushedResponse->requestHeaders[':method'][0]) {
387387
return false;
388388
}
389389

src/Symfony/Component/HttpClient/Response/CurlResponse.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,17 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
133133

134134
if (\in_array($waitFor, ['headers', 'destruct'], true)) {
135135
try {
136-
self::stream([$response])->current();
136+
foreach (self::stream([$response]) as $chunk) {
137+
if ($chunk->isFirst()) {
138+
break;
139+
}
140+
}
137141
} catch (\Throwable $e) {
138142
// Persist timeouts thrown during initialization
139143
$response->info['error'] = $e->getMessage();
140144
$response->close();
141145
throw $e;
142146
}
143-
} elseif ('content' === $waitFor && ($response->multi->handlesActivity[$response->id][0] ?? null) instanceof FirstChunk) {
144-
self::stream([$response])->current();
145147
}
146148

147149
curl_setopt($ch, CURLOPT_HEADERFUNCTION, null);

src/Symfony/Component/HttpClient/Response/NativeResponse.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ public function __construct(NativeClientState $multi, $context, string $url, $op
6767
}
6868

6969
if (null === $response->remaining) {
70-
self::stream([$response])->current();
70+
foreach (self::stream([$response]) as $chunk) {
71+
if ($chunk->isFirst()) {
72+
break;
73+
}
74+
}
7175
}
7276
};
7377
}

src/Symfony/Component/Messenger/Exception/HandlerFailedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(Envelope $envelope, array $exceptions)
2929
1 === \count($exceptions)
3030
? $firstFailure->getMessage()
3131
: sprintf('%d handlers failed. First failure is: "%s"', \count($exceptions), $firstFailure->getMessage()),
32-
$firstFailure->getCode(),
32+
(int) $firstFailure->getCode(),
3333
$firstFailure
3434
);
3535

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Symfony\Component\Messenger\Tests\Exception;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\Messenger\Envelope;
7+
use Symfony\Component\Messenger\Exception\HandlerFailedException;
8+
9+
class HandlerFailedExceptionTest extends TestCase
10+
{
11+
public function testThatStringErrorCodeConvertsToInteger()
12+
{
13+
$envelope = new Envelope(new \stdClass());
14+
$exception = new class() extends \RuntimeException {
15+
public function __construct()
16+
{
17+
$this->code = 'HY000';
18+
$this->message = 'test';
19+
// no to call parent constructor, it will fail with string error code
20+
}
21+
};
22+
23+
$handlerException = new HandlerFailedException($envelope, [$exception]);
24+
$originalException = $handlerException->getNestedExceptions()[0];
25+
26+
$this->assertIsInt($handlerException->getCode(), 'Exception codes must converts to int');
27+
$this->assertSame(0, $handlerException->getCode(), 'String code (HY000) converted to int must be 0');
28+
$this->assertIsString($originalException->getCode(), 'Original exception code still with original type (string)');
29+
$this->assertSame($exception->getCode(), $originalException->getCode(), 'Original exception code is not modified');
30+
}
31+
}

src/Symfony/Component/Process/Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public function start(callable $callback = null, array $env = [])
361361
* @param callable|null $callback A PHP callback to run whenever there is some
362362
* output available on STDOUT or STDERR
363363
*
364-
* @return $this
364+
* @return static
365365
*
366366
* @throws RuntimeException When process can't be launched
367367
* @throws RuntimeException When process is already running

0 commit comments

Comments
 (0)