8000 Merge branch '4.4' · symfony/symfony@58d61dc · GitHub
[go: up one dir, main page]

Skip to content

Commit 58d61dc

Browse files
Merge branch '4.4'
* 4.4: fix merge [HttpFoundation] Throw exception when the \"session\" extension is not loaded remove invalid test case remove invalid test cases [Serializer] Fixed PHP of DenormalizableInterface::denormalize fix Debug component dependencies [Cache] work aroung PHP memory leak [Finder] docblock fixes pass error code as a string [travis] not all components have a master branch [HttpKernel] Add @method PHPDoc for getRequest and getResponse back to Client Catch JsonException and rethrow in JsonEncode
2 parents 7b3ef19 + b40f6b5 commit 58d61dc

File tree

14 files changed

+77
-45
lines changed

14 files changed

+77
-45
lines changed

.github/build-packages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
$versions = @file_get_contents('https://repo.packagist.org/p/'.$package->name.'.json') ?: sprintf('{"packages":{"%s":{"dev-master":%s}}}', $package->name, file_get_contents($dir.'/composer.json'));
5858
$versions = json_decode($versions)->packages->{$package->name};
5959

60-
if ($package->version === str_replace('-dev', '.x-dev', $versions->{'dev-master'}->extra->{'branch-alias'}->{'dev-master'})) {
60+
if (isset($versions->{'dev-master'}) && $package->version === str_replace('-dev', '.x-dev', $versions->{'dev-master'}->extra->{'branch-alias'}->{'dev-master'})) {
6161
unset($versions->{'dev-master'});
6262
}
6363

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ public function load(array $configs, ContainerBuilder $container)
213213
}
214214

215215
if ($this->isConfigEnabled($container, $config['session'])) {
216+
if (!\extension_loaded('session')) {
217+
throw new \LogicException('PHP extension "session" is required.');
218+
}
219+
216220
$this->sessionConfigEnabled = true;
217221
$this->registerSessionConfiguration($config['session'], $container, $loader);
218222
if (!empty($config['test'])) {

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function build(ContainerBuilder $container)
9090
KernelEvents::FINISH_REQUEST,
9191
];
9292

93-
$this->addCompilerPassIfExists($container, ErrorCatcherPass::class);
93+
$container->addCompilerPass(new ErrorCatcherPass());
9494
$container->addCompilerPass(new LoggerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
9595
$container->addCompilerPass(new RegisterControllerArgumentLocatorsPass());
9696
$container->addCompilerPass(new RemoveEmptyControllerArgumentLocatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"symfony/cache": "^4.4|^5.0",
2222
"symfony/config": "^4.4|^5.0",
2323
"symfony/dependency-injection": "^4.4|^5.0",
24+
"symfony/error-catcher": "^4.4|^5.0",
2425
"symfony/http-foundation": "^4.4|^5.0",
2526
"symfony/http-kernel": "^4.4|^5.0",
2627
"symfony/polyfill-mbstring": "~1.0",

src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,15 @@ public function prune()
6767
{
6868
$time = time();
6969
$pruned = true;
70+
$getExpiry = true;
7071

7172
set_error_handler($this->includeHandler);
7273
try {
7374
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
7475
try {
75-
list($expiresAt) = include $file;
76+
if (\is_array($expiresAt = include $file)) {
77+
$expiresAt = $expiresAt[0];
78+
}
7679
} catch (\ErrorException $e) {
7780
$expiresAt = $time;
7881
}
@@ -104,15 +107,21 @@ protected function doFetch(array $ids)
104107
$values = [];
105108

106109
begin:
110+
$getExpiry = false;
111+
107112
foreach ($ids as $id) {
108113
if (null === $value = $this->values[$id] ?? null) {
109114
$missingIds[] = $id;
110115
} elseif ('N;' === $value) {
111116
$values[$id] = null;
112-
} elseif ($value instanceof \Closure) {
113-
$values[$id] = $value();
114-
} else {
117+
} elseif (!\is_object($value)) {
115118
$values[$id] = $value;
119+
} elseif (!$value instanceof LazyValue) {
120+
// calling a Closure is for @deprecated BC and should be removed in Symfony 5.0
121+
$values[$id] = $value();
122+
} elseif (false === $values[$id] = include $value->file) {
123+
unset($values[$id], $this->values[$id]);
124+
$missingIds[] = $id;
116125
}
117126
if (!$this->appendOnly) {
118127
unset($this->values[$id]);
@@ -125,10 +134,18 @@ protected function doFetch(array $ids)
125134

126135
set_error_handler($this->includeHandler);
127136
try {
137+
$getExpiry = true;
138+
128139
foreach ($missingIds as $k => $id) {
129140
try {
130141
$file = $this->files[$id] ?? $this->files[$id] = $this->getFile($id);
131-
list($expiresAt, $this->values[$id]) = include $file;
142+
143+
if (\is_array($expiresAt = include $file)) {
144+
[$expiresAt, $this->values[$id]] = $expiresAt;
145+
} elseif ($now < $expiresAt) {
146+
$this->values[$id] = new LazyValue($file);
147+
}
148+
132149
if ($now >= $expiresAt) {
133150
unset($this->values[$id], $missingIds[$k]);
134151
}
@@ -157,7 +174,13 @@ protected function doHave($id)
157174
set_error_handler($this->includeHandler);
158175
try {
159176
$file = $this->files[$id] ?? $this->files[$id] = $this->getFile($id);
160-
list($expiresAt, $value) = include $file;
177+
$getExpiry = true;
178+
179+
if (\is_array($expiresAt = include $file)) {
180+
[$expiresAt, $value] = $expiresAt;
181+
} elseif ($this->appendOnly) {
182+
$value = new LazyValue($file);
183+
}
161184
} catch (\ErrorException $e) {
162185
return false;
163186
} finally {
@@ -206,13 +229,16 @@ protected function doSave(array $values, $lifetime)
206229
}
207230

208231
if (!$isStaticValue) {
209-
$value = str_replace("\n", "\n ", $value);
210-
$value = "static function () {\n\n return {$value};\n\n}";
232+
// We cannot use a closure here because of https://bugs.php.net/76982
233+
$value = str_replace('\Symfony\Component\VarExporter\Internal\\', '', $value);
234+
$value = "<?php\n\nnamespace Symfony\Component\VarExporter\Internal;\n\nreturn \$getExpiry ? {$expiry} : {$value};\n";
235+
} else {
236+
$value = "<?php return [{$expiry}, {$value}];\n";
211237
}
212238

213239
$file = $this->files[$key] = $this->getFile($key, true);
214240
// Since OPcache only compiles files older than the script execution start, set the file's mtime in the past
215-
$ok = $this->write($file, "<?php return [{$expiry}, {$value}];\n", self::$startTime - 10) && $ok;
241+
$ok = $this->write($file, $value, self::$startTime - 10) && $ok;
216242

217243
if ($allowCompile) {
218244
@opcache_invalidate($file, true);
@@ -258,3 +284,16 @@ protected function doUnlink($file)
258284
return @unlink($file);
259285
}
260286
}
287+
288+
/**
289+
* @internal
290+
*/
291+
class LazyValue
292+
{
293+
public $file;
294+
295+
public function __construct($file)
296+
{
297+
$this->file = $file;
298+
}
299+
}

src/Symfony/Component/Finder/Finder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ public function ignoreUnreadableDirs($ignore = true)
577577
/**
578578
* Searches files and directories which match defined rules.
579579
*
580-
* @param string|array $dirs A directory path or an array of directories
580+
* @param string|string[] $dirs A directory path or an array of directories
581581
*
582582
* @return $this
583583
*

src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ExcludeDirectoryFilterIterator extends \FilterIterator implements \Recursi
2525

2626
/**
2727
* @param \Iterator $iterator The Iterator to filter
28-
* @param array $directories An array of directories to exclude
28+
* @param string[] $directories An array of directories to exclude
2929
*/
3030
public function __construct(\Iterator $iterator, array $directories)
3131
{

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ class NativeSessionStorage implements SessionStorageInterface
103103
*/
104104
public function __construct(array $options = [], $handler = null, MetadataBag $metaBag = null)
105105
{
106+
if (!\extension_loaded('session')) {
107+
throw new \LogicException('PHP extension "session" is required.');
108+
}
109+
106110
$options += [
107111
'cache_limiter' => '',
108112
'cache_expire' => 0,

src/Symfony/Component/HttpFoundation/Session/Storage/PhpBridgeSessionStorage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class PhpBridgeSessionStorage extends NativeSessionStorage
2424
*/
2525
public function __construct($handler = null, MetadataBag $metaBag = null)
2626
{
27+
if (!\extension_loaded('session')) {
28+
throw new \LogicException('PHP extension "session" is required.');
29+
}
30+
2731
$this->setMetadataBag($metaBag);
2832
$this->setSaveHandler($handler);
2933
}

src/Symfony/Component/Serializer/Encoder/JsonEncode.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,19 @@ public function __construct(array $defaultContext = [])
3838
*/
3939
public function encode($data, $format, array $context = [])
4040
{
41-
$jsonEncodeOptions = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
42-
$encodedJson = json_encode($data, $jsonEncodeOptions);
41+
$options = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
4342

44-
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $jsonEncodeOptions)) {
43+
try {
44+
$encodedJson = json_encode($data, $options);
45+
} catch (\JsonException $e) {
46+
throw new NotEncodableValueException($e->getMessage(), 0, $e);
47+
}
48+
49+
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $options)) {
4550
return $encodedJson;
4651
}
4752

48-
if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($jsonEncodeOptions & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
53+
if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($options & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
4954
throw new NotEncodableValueException(json_last_error_msg());
5055
}
5156

src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface DenormalizableInterface
3434
* differently based on different input formats
3535
* @param array $context Options for denormalizing
3636
*
37-
* @return object
37+
* @return object|object[]
3838
*/
3939
public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = []);
4040
}

src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,6 @@ public function testValidComparisonToPropertyPath($comparedValue)
148148
$this->assertNoViolation();
149149
}
150150

151-
/**
152-
* @dataProvider provideValidComparisonsToPropertyPath
153-
*/
154-
public function testValidComparisonToPropertyPathOnArray($comparedValue)
155-
{
156-
$constraint = $this->createConstraint(['propertyPath' => '[root][value]']);
157-
158-
$this->setObject(['root' => ['value' => 5]]);
159-
160-
$this->validator->validate($comparedValue, $constraint);
161-
162-
$this->assertNoViolation();
163-
}
164-
165151
public function testNoViolationOnNullObjectWithPropertyPath()
166152
{
167153
$constraint = $this->createConstraint(['propertyPath' => 'propertyPath']);

src/Symfony/Component/Validator/Tests/Constraints/BicValidatorTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ public function testValidComparisonToPropertyPath()
5050
$this->assertNoViolation();
5151
}
5252

53-
public function testValidComparisonToPropertyPathOnArray()
54-
{
55-
$constraint = new Bic(['ibanPropertyPath' => '[root][value]']);
56-
57-
$this->setObject(['root' => ['value' => 'FR14 2004 1010 0505 0001 3M02 606']]);
58-
59-
$this->validator->validate('SOGEFRPP', $constraint);
60-
61-
$this->assertNoViolation();
62-
}
63-
6453
public function testInvalidComparisonToPropertyPath()
6554
{
6655
$constraint = new Bic(['ibanPropertyPath' => 'value']);

src/Symfony/Component/Validator/Tests/Validator/AbstractTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ public function testAddCustomizedViolation()
511511
->setParameter('%param%', 'value')
512512
->setInvalidValue('Invalid value')
513513
->setPlural(2)
514-
->setCode(42)
514+
->setCode('42')
515515
->addViolation();
516516
};
517517

@@ -528,7 +528,7 @@ public function testAddCustomizedViolation()
528528
$this->assertSame($entity, $violations[0]->getRoot());
529529
$this->assertSame('Invalid value', $violations[0]->getInvalidValue());
530530
$this->assertSame(2, $violations[0]->getPlural());
531-
$this->assertSame(42, $violations[0]->getCode());
531+
$this->assertSame('42', $violations[0]->getCode());
532532
}
533533

534534
public function testNoDuplicateValidationIfClassConstraintInMultipleGroups()

0 commit comments

Comments
 (0)
0