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

Skip to content

Commit b5d1cbc

Browse files
Merge branch '4.4' into 5.2
* 4.4: fixed parser Fixed bugs found by psalm [FrameworkBundle] Dont store cache misses on warmup [Cache] skip storing failure-to-save as misses in ArrayAdapter [Validator] Delete obsolete statement in Regex::getHtmlPattern() phpDoc [FrameworkBundle] Remove author comments for configuration and extension [DependencyInjection] Fix "url" env var processor behavior when the url has no path Fixed support for nodes not extending BaseNode add missing queue_name to find(id) in doctrine messenger transport [Serializer] AbstractNormalizer force null for non-optional nullable constructor parameter denormalization when not present in input
2 parents 4d23fec + 4e4cdf5 commit b5d1cbc

File tree

34 files changed

+309
-65
lines changed

34 files changed

+309
-65
lines changed

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private function displayJson(OutputInterface $output, array $filesInfo)
219219
return min($errors, 1);
220220
}
221221

222-
private function renderException(OutputInterface $output, string $template, Error $exception, string $file = null)
222+
private function renderException(SymfonyStyle $output, string $template, Error $exception, string $file = null)
223223
{
224224
$line = $exception->getTemplateLine();
225225

src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function getBcc(): array
182182
*/
183183
public function setPriority(int $priority): self
184184
{
185-
$this->message->setPriority($priority);
185+
$this->message->priority($priority);
186186

187187
return $this;
188188
}

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Common\Annotations\CachedReader;
1616
use Doctrine\Common\Annotations\Reader;
1717
use Symfony\Component\Cache\Adapter\ArrayAdapter;
18+
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
1819
use Symfony\Component\Cache\DoctrineProvider;
1920

2021
/**
@@ -68,6 +69,17 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
6869
return true;
6970
}
7071

72+
/**
73+
* @return string[] A list of classes to preload on PHP 7.4+
74+
*/
75+
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
76+
{
77+
// make sure we don't cache null values
78+
$values = array_filter($values, function ($val) { return null !== $val; });
79+
80+
return parent::warmUpPhpArrayAdapter($phpArrayAdapter, $values);
81+
}
82+
7183
private function readAllComponents(Reader $reader, string $class)
7284
{
7385
$reflectionClass = new \ReflectionClass($class);

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/ValidatorCacheWarmer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
7474
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
7575
{
7676
// make sure we don't cache null values
77-
return parent::warmUpPhpArrayAdapter($phpArrayAdapter, array_filter($values));
77+
$values = array_filter($values, function ($val) { return null !== $val; });
78+
79+
return parent::warmUpPhpArrayAdapter($phpArrayAdapter, $values);
7880
}
7981

8082
/**

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040

4141
/**
4242
* FrameworkExtension configuration structure.
43-
*
44-
* @author Jeremy Mikola <[email protected]>
45-
* @author Grégoire Pineau <[email protected]>
4643
*/
4744
class Configuration implements ConfigurationInterface
4845
{

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,8 @@
166166
use Symfony\Contracts\Translation\LocaleAwareInterface;
167167

168168
/**
169-
* FrameworkExtension.
170-
*
171-
* @author Fabien Potencier <[email protected]>
172-
* @author Jeremy Mikola <[email protected]>
173-
* @author Kévin Dunglas <[email protected]>
174-
* @author Grégoire Pineau <[email protected]>
169+
* Process the configuration and prepare the dependency injection container with
170+
* parameters and services.
175171
*/
176172
class FrameworkExtension extends Extension
177173
{

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPUnit\Framework\MockObject\MockObject;
99
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
1010
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
11+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1112
use Symfony\Component\Cache\Adapter\NullAdapter;
1213
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
1314
use Symfony\Component\Cache\DoctrineProvider;
@@ -120,6 +121,35 @@ public function testClassAutoloadExceptionWithUnrelatedException()
120121
spl_autoload_unregister($classLoader);
121122
}
122123

124+
public function testWarmupRemoveCacheMisses()
125+
{
126+
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
127+
$warmer = $this->getMockBuilder(AnnotationsCacheWarmer::class)
128+
->setConstructorArgs([new AnnotationReader(), $cacheFile])
129+
->setMethods(['doWarmUp'])
130+
->getMock();
131+
132+
$warmer->method('doWarmUp')->willReturnCallback(function ($cacheDir, ArrayAdapter $arrayAdapter) {
133+
$arrayAdapter->getItem('foo_miss');
134+
135+
$item = $arrayAdapter->getItem('bar_hit');
136+
$item->set('data');
137+
$arrayAdapter->save($item);
138+
139+
$item = $arrayAdapter->getItem('baz_hit_null');
140+
$item->set(null);
141+
$arrayAdapter->save($item);
142+
143+
return true;
144+
});
145+
146+
$warmer->warmUp($this->cacheDir);
147+
$data = include $cacheFile;
148+
149+
$this->assertCount(1, $data[0]);
150+
$this->assertTrue(isset($data[0]['bar_hit']));
151+
}
152+
123153
/**
124154
* @return MockObject|Reader
125155
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ private function freeze($value, $key)
356356
try {
357357
$serialized = serialize($value);
358358
} catch (\Exception $e) {
359+
unset($this->values[$key]);
359360
$type = get_debug_type($value);
360361
$message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
361362
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);

src/Symfony/Component/Cache/Tests/Adapter/ArrayAdapterTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public function testGetValuesHitAndMiss()
4747
// Miss (should be present as NULL in $values)
4848
$cache->getItem('bar');
4949

50+
// Fail (should be missing from $values)
51+
$item = $cache->getItem('buz');
52+
$cache->save($item->set(function() {}));
53+
5054
$values = $cache->getValues();
5155

5256
$this->assertCount(2, $values);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function preNormalize($value)
6868
/**
6969
* Retrieves the children of this node.
7070
*
71-
* @return array The children
71+
* @return array<string, NodeInterface>
7272
*/
7373
public function getChildren()
7474
{

src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ public function getNode(bool $forceRootNode = false)
124124
}
125125

126126
$node = $this->createNode();
127-
$node->setAttributes($this->attributes);
127+
if ($node instanceof BaseNode) {
128+
$node->setAttributes($this->attributes);
129+
}
128130

129131
return $node;
130132
}

src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Config\Definition\Dumper;
1313

1414
use Symfony\Component\Config\Definition\ArrayNode;
15+
use Symfony\Component\Config\Definition\BaseNode;
1516
use Symfony\Component\Config\Definition\ConfigurationInterface;
1617
use Symfony\Component\Config\Definition\EnumNode;
1718
use Symfony\Component\Config\Definition\NodeInterface;
@@ -126,51 +127,53 @@ private function writeNode(NodeInterface $node, int $depth = 0, bool $root = fal
126127

127128
// get attributes and elements
128129
foreach ($children as $child) {
129-
if (!$child instanceof ArrayNode) {
130-
// get attributes
130+
if ($child instanceof ArrayNode) {
131+
// get elements
132+
$rootChildren[] = $child;
131133

132-
// metadata
133-
$name = str_replace('_', '-', $child->getName());
134-
$value = '%%%%not_defined%%%%'; // use a string which isn't used in the normal world
134+
continue;
135+
}
135136

136-
// comments
137-
$comments = [];
138-
if ($info = $child->getInfo()) {
139-
$comments[] = $info;
140-
}
137+
// get attributes
141138

142-
if ($example = $child->getExample()) {
143-
$comments[] = 'Example: '.$example;
144-
}
139+
// metadata
140+
$name = str_replace('_', '-', $child->getName());
141+
$value = '%%%%not_defined%%%%'; // use a string which isn't used in the normal world
145142

146-
if ($child->isRequired()) {
147-
$comments[] = 'Required';
148-
}
143+
// comments
144+
$comments = [];
145+
if ($child instanceof BaseNode && $info = $child->getInfo()) {
146+
$comments[] = $info;
147+
}
149148

150-
if ($child->isDeprecated()) {
151-
$deprecation = $child->getDeprecation($child->getName(), $node->getPath());
152-
$comments[] = sprintf('Deprecated (%s)', ($deprecation['package'] || $deprecation['version'] ? "Since {$deprecation['package']} {$deprecation['version']}: " : '').$deprecation['message']);
153-
}
149+
if ($child instanceof BaseNode && $example = $child->getExample()) {
150+
$comments[] = 'Example: '.$example;
151+
}
154152

155-
if ($child instanceof EnumNode) {
156-
$comments[] = 'One of '.implode('; ', array_map('json_encode', $child->getValues()));
157-
}
153+
if ($child->isRequired()) {
154+
$comments[] = 'Required';
155+
}
158156

159-
if (\count($comments)) {
160-
$rootAttributeComments[$name] = implode(";\n", $comments);
161-
}
157+
if ($child instanceof BaseNode && $child->isDeprecated()) {
158+
$deprecation = $child->getDeprecation($child->getName(), $node->getPath());
159+
$comments[] = sprintf('Deprecated (%s)', ($deprecation['package'] || $deprecation['version'] ? "Since {$deprecation['package']} {$deprecation['version']}: " : '').$deprecation['message']);
160+
}
162161

163-
// default values
164-
if ($child->hasDefaultValue()) {
165-
$value = $child->getDefaultValue();
166-
}
162+
if ($child instanceof EnumNode) {
163+
$comments[] = 'One of '.implode('; ', array_map('json_encode', $child->getValues()));
164+
}
167165

168-
// append attribute
169-
$rootAttributes[$name] = $value;
170-
} else {
171-
// get elements
172-
$rootChildren[] = $child;
166+
if (\count($comments)) {
167+
$rootAttributeComments[$name] = implode(";\n", $comments);
173168
}
169+
170+
// default values
171+
if ($child->hasDefaultValue()) {
172+
$value = $child->getDefaultValue();
173+
}
174+
175+
// append attribute
176+
$rootAttributes[$name] = $value;
174177
}
175178
}
176179

src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Config\Definition\Dumper;
1313

1414
use Symfony\Component\Config\Definition\ArrayNode;
15+
use Symfony\Component\Config\Definition\BaseNode;
1516
use Symfony\Component\Config\Definition\ConfigurationInterface;
1617
use Symfony\Component\Config\Definition\EnumNode;
1718
use Symfony\Component\Config\Definition\NodeInterface;
@@ -76,7 +77,10 @@ private function writeNode(NodeInterface $node, NodeInterface $parentNode = null
7677
$default = '';
7778
$defaultArray = null;
7879
$children = null;
79-
$example = $node->getExample();
80+
$example = null;
81+
if ($node instanceof BaseNode) {
82+
$example = $node->getExample();
83+
}
8084

8185
// defaults
8286
if ($node instanceof ArrayNode) {
@@ -123,7 +127,7 @@ private function writeNode(NodeInterface $node, NodeInterface $parentNode = null
123127
}
124128

125129
// deprecated?
126-
if ($node->isDeprecated()) {
130+
if ($node instanceof BaseNode && $node->isDeprecated()) {
127131
$deprecation = $node->getDeprecation($node->getName(), $parentNode ? $parentNode->getPath() : $node->getPath());
128132
$comments[] = sprintf('Deprecated (%s)', ($deprecation['package'] || $deprecation['version'] ? "Since {$deprecation['package']} {$deprecation['version']}: " : '').$deprecation['message']);
129133
}
@@ -139,7 +143,7 @@ private function writeNode(NodeInterface $node, NodeInterface $parentNode = null
139143
$key = $prototypedArray ? '-' : $node->getName().':';
140144
$text = rtrim(sprintf('%-21s%s %s', $key, $default, $comments), ' ');
141145

142-
if ($info = $node->getInfo()) {
146+
if ($node instanceof BaseNode && $info = $node->getInfo()) {
143147
$this->writeLine('');
144148
// indenting multi-line info
145149
$info = str_replace("\n", sprintf("\n%".($depth * 4).'s# ', ' '), $info);

src/Symfony/Component/Config/Tests/Definition/Dumper/XmlReferenceDumperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ private function getConfigurationAsString()
5757
node-with-a-looong-name=""
5858
enum-with-default="this"
5959
enum=""
60+
custom-node="true"
6061
>
6162
6263
<!-- some info -->

src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ enum: ~ # One of "this"; "that"
137137
138138
# Prototype
139139
name: []
140+
custom_node: true
140141

141142
EOL;
142143
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
4+
namespace Symfony\Component\Config\Tests\Fixtures\Configuration;
5+
6+
use Symfony\Component\Config\Definition\NodeInterface;
7+
8+
class CustomNode implements NodeInterface
9+
{
10+
public function getName()
11+
{
12+
return 'custom_node';
13+
}
14+
15+
public function getPath()
16+
{
17+
return 'custom';
18+
}
19+
20+
public function isRequired()
21+
{
22+
return false;
23+
}
24+
25+
public function hasDefaultValue()
26+
{
27+
return true;
28+
}
29+
30+
public function getDefaultValue()
31+
{
32+
return true;
33+
}
34+
35+
public function normalize($value)
36+
{
37+
return $value;
38+
}
39+
40+
public function merge($leftSide, $rightSide)
41+
{
42+
return array_merge($leftSide, $rightSide);
43+
}
44+
45+
public function finalize($value)
46+
{
47+
return $value;
48+
}
49+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
4+
namespace Symfony\Component\Config\Tests\Fixtures\Configuration;
5+
6+
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
7+
8+
class CustomNodeDefinition extends NodeDefinition
9+
{
10+
protected function createNode()
11+
{
12+
return new CustomNode();
13+
}
14+
}

src/Symfony/Component/Config/Tests/Fixtures/Configuration/ExampleConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function getConfigTreeBuilder(): TreeBuilder
9393
->end()
9494
->end()
9595
->end()
96+
->append(new CustomNodeDefinition('acme'))
9697
->end()
9798
;
9899

src/Symfony/Component/DependencyInjection/Definition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function setChanges(array $changes)
9696
/**
9797
* Sets a factory.
9898
*
99-
* @param string|array|Reference $factory A PHP function, reference or an array containing a class/Reference and a method to call
99+
* @param string|array|Reference|null $factory A PHP function, reference or an array containing a class/Reference and a method to call
100100
*
101101
* @return $this
102102
*/

0 commit comments

Comments
 (0)