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

Skip to content

Commit ab1bc87

Browse files
Merge branch '4.3' into 4.4
* 4.3: [HttpFoundation] Throw exception when the \"session\" extension is not loaded remove invalid test case remove invalid test cases [Serializer] Fixed PHP of DenormalizableInterface::denormalize [Cache] work aroung PHP memory leak [Finder] docblock fixes pass error code as a string Catch JsonException and rethrow in JsonEncode
2 parents 61d180e + a218efe commit ab1bc87

File tree

11 files changed

+74
-43
lines changed

11 files changed

+74
-43
lines changed

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

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

228228
if ($this->isConfigEnabled($container, $config['session'])) {
229+
if (!\extension_loaded('session')) {
230+
throw new \LogicException('PHP extension "session" is required.');
231+
}
232+
229233
$this->sessionConfigEnabled = true;
230234
$this->registerSessionConfiguration($config['session'], $container, $loader);
231235
if (!empty($config['test'])) {

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

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@ public function prune()
5050
{
5151
$time = time();
5252
$pruned = true;
53+
$getExpiry = true;
5354

5455
set_error_handler($this->includeHandler);
5556
try {
5657
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
5758
try {
58-
list($expiresAt) = include $file;
59+
if (\is_array($expiresAt = include $file)) {
60+
$expiresAt = $expiresAt[0];
61+
}
5962
} catch (\ErrorException $e) {
6063
$expiresAt = $time;
6164
}
@@ -87,15 +90,21 @@ protected function doFetch(array $ids)
8790
$values = [];
8891

8992
begin:
93+
$getExpiry = false;
94+
9095
foreach ($ids as $id) {
9196
if (null === $value = $this->values[$id] ?? null) {
9297
$missingIds[] = $id;
9398
} elseif ('N;' === $value) {
9499
$values[$id] = null;
95-
} elseif ($value instanceof \Closure) {
96-
$values[$id] = $value();
97-
} else {
100+
} elseif (!\is_object($value)) {
98101
$values[$id] = $value;
102+
} elseif (!$value instanceof LazyValue) {
103+
// calling a Closure is for @deprecated BC and should be removed in Symfony 5.0
104+
$values[$id] = $value();
105+
} elseif (false === $values[$id] = include $value->file) {
106+
unset($values[$id], $this->values[$id]);
107+
$missingIds[] = $id;
99108
}
100109
if (!$this->appendOnly) {
101110
unset($this->values[$id]);
@@ -108,10 +117,18 @@ protected function doFetch(array $ids)
108117

109118
set_error_handler($this->includeHandler);
110119
try {
120+
$getExpiry = true;
121+
111122
foreach ($missingIds as $k => $id) {
112123
try {
113124
$file = $this->files[$id] ?? $this->files[$id] = $this->getFile($id);
114-
list($expiresAt, $this->values[$id]) = include $file;
125+
126+
if (\is_array($expiresAt = include $file)) {
127+
[$expiresAt, $this->values[$id]] = $expiresAt;
128+
} elseif ($now < $expiresAt) {
129+
$this->values[$id] = new LazyValue($file);
130+
}
131+
115132
if ($now >= $expiresAt) {
116133
unset($this->values[$id], $missingIds[$k]);
117134
}
@@ -140,7 +157,13 @@ protected function doHave($id)
140157
set_error_handler($this->includeHandler);
141158
try {
142159
$file = $this->files[$id] ?? $this->files[$id] = $this->getFile($id);
143-
list($expiresAt, $value) = include $file;
160+
$getExpiry = true;
161+
162+
if (\is_array($expiresAt = include $file)) {
163+
[$expiresAt, $value] = $expiresAt;
164+
} elseif ($this->appendOnly) {
165+
$value = new LazyValue($file);
166+
}
144167
} catch (\ErrorException $e) {
145168
return false;
146169
} finally {
@@ -189,13 +212,16 @@ protected function doSave(array $values, $lifetime)
189212
}
190213

191214
if (!$isStaticValue) {
192-
$value = str_replace("\n", "\n ", $value);
193-
$value = "static function () {\n\n return {$value};\n\n}";
215+
// We cannot use a closure here because of https://bugs.php.net/76982
216+
$value = str_replace('\Symfony\Component\VarExporter\Internal\\', '', $value);
217+
$value = "<?php\n\nnamespace Symfony\Component\VarExporter\Internal;\n\nreturn \$getExpiry ? {$expiry} : {$value};\n";
218+
} else {
219+
$value = "<?php return [{$expiry}, {$value}];\n";
194220
}
195221

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

200226
if ($allowCompile) {
201227
@opcache_invalidate($file, true);
@@ -241,3 +267,16 @@ protected function doUnlink($file)
241267
return @unlink($file);
242268
}
243269
}
270+
271+
/**
272+
* @internal
273+
*/
274+
class LazyValue
275+
{
276+
public $file;
277+
278+
public function __construct($file)
279+
{
280+
$this->file = $file;
281+
}
282+
}

src/Symfony/Component/Finder/Finder.php

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

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
@@ -47,14 +47,19 @@ public function __construct($defaultContext = [])
4747
*/
4848
public function encode($data, $format, array $context = [])
4949
{
50-
$jsonEncodeOptions = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
51-
$encodedJson = json_encode($data, $jsonEncodeOptions);
50+
$options = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
5251

53-
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $jsonEncodeOptions)) {
52+
try {
53+
$encodedJson = json_encode($data, $options);
54+
} catch (\JsonException $e) {
55+
throw new NotEncodableValueException($e->getMessage(), 0, $e);
56+
}
57+
58+
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $options)) {
5459
return $encodedJson;
5560
}
5661

57-
if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($jsonEncodeOptions & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
62+
if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($options & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
5863
throw new NotEncodableValueException(json_last_error_msg());
5964
}
6065

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