8000 Merge branch '5.2' into 5.x · symfony/symfony@3f0f21c · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f0f21c

Browse files
Merge branch '5.2' into 5.x
* 5.2: fixed parser Fixed bugs found by psalm [FrameworkBundle] Dont store cache misses on warmup fix test Update references to the ContainerConfigurator [Translation] Remove file added back from a bad merge Fix sleep value [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 [Stopwatch] Document new "name" property of StopwatchEvent [DependencyInjection] Fix "url" env var processor behavior when the url has no path Fixed support for nodes not extending BaseNode [FrameworkBundle] dont access the container to configure http_cache add missing queue_name to find(id) in doctrine messenger transport [Config][FrameworkBundle] Hint to use PHP 8+ or to install Annotations to use attributes/annots [Serializer] AbstractNormalizer force null for non-optional nullable constructor parameter denormalization when not present in input
2 parents 993f809 + b5d1cbc commit 3f0f21c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+337
-311
lines changed

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

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

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

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
@@ -16,6 +16,7 @@
1616
use Doctrine\Common\Annotations\PsrCachedReader;
1717
use Doctrine\Common\Annotations\Reader;
1818
use Symfony\Component\Cache\Adapter\ArrayAdapter;
19+
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
1920
use Symfony\Component\Cache\DoctrineProvider;
2021

2122
/**
@@ -75,6 +76,17 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
7576
return true;
7677
}
7778

79+
/**
80+
* @return string[] A list of classes to preload on PHP 7.4+
81+
*/
82+
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
83+
{
84+
// make sure we don't cache null values
85+
$values = array_filter($values, function ($val) { return null !== $val; });
86+
87+
return parent::warmUpPhpArrayAdapter($phpArrayAdapter, $values);
88+
}
89+
7890
private function readAllComponents(Reader $reader, string $class)
7991
{
8092
$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
@@ -44,9 +44,6 @@
4444

4545
/**
4646
* FrameworkExtension configuration structure.
47-
*
48-
* @author Jeremy Mikola <jmikola@gmail.com>
49-
* @author Grégoire Pineau <lyrixx@lyrixx.info>
5047
*/
5148
class Configuration implements ConfigurationInterface
5249
{

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,8 @@
188188
use Symfony\Contracts\Translation\LocaleAwareInterface;
189189

190190
/**
191-
* FrameworkExtension.
192-
*
193-
* @author Fabien Potencier <fabien@symfony.com>
194-
* @author Jeremy Mikola <jmikola@gmail.com>
195-
* @author Kévin Dunglas <dunglas@gmail.com>
196-
* @author Grégoire Pineau <lyrixx@lyrixx.info>
191+
* Process the configuration and prepare the dependency injection container with
192+
* parameters and services.
197193
*/
198194
class FrameworkExtension extends Extension
199195
{
@@ -415,7 +411,7 @@ public function load(array $configs, ContainerBuilder $container)
415411

416412
$propertyInfoEnabled = $this->isConfigEnabled($container, $config['property_info']);
417413
$this->registerValidationConfiguration($config['validation'], $container, $loader, $propertyInfoEnabled);
418-
$this->registerHttpCacheConfiguration($config['http_cache'], $container);
414+
$this->registerHttpCacheConfiguration($config['http_cache'], $container, $config['http_method_override']);
419415
$this->registerEsiConfiguration($config['esi'], $container, $loader);
420416
$this->registerSsiConfiguration($config['ssi'], $container, $loader);
421417
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
@@ -622,7 +618,7 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
622618
}
623619
}
624620

625-
private function registerHttpCacheConfiguration(array $config, ContainerBuilder $container)
621+
private function registerHttpCacheConfiguration(array $config, ContainerBuilder $container, bool $httpMethodOverride)
626622
{
627623
$options = $config;
628624
unset($options['enabled']);
@@ -634,6 +630,13 @@ private function registerHttpCacheConfiguration(array $config, ContainerBuilder
634630
$container->getDefinition('http_cache')
635631
->setPublic($config['enabled'])
636632
->replaceArgument(3, $options);
633+
634+
if ($httpMethodOverride) {
635+
$container->getDefinition('http_cache')
636+
->addArgument((new Definition('void'))
637+
->setFactory([Request::class, 'enableHttpMethodParameterOverride'])
638+
);
639+
}
637640
}
638641

639642
private function registerEsiConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
@@ -1376,7 +1379,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
13761379

13771380
if (\array_key_exists('enable_annotations', $config) && $config['enable_annotations']) {
13781381
if (!$this->annotationsConfigEnabled && \PHP_VERSION_ID < 80000) {
1379-
throw new \LogicException('"enable_annotations" on the validator cannot be set as Doctrine Annotations support is disabled.');
1382+
throw new \LogicException('"enable_annotations" on the validator cannot be set as the PHP version is lower than 8 and Doctrine Annotations support is disabled. Consider upgrading PHP.');
13801383
}
13811384

13821385
$validatorBuilder->addMethodCall('enableAnnotationMapping', [true]);
@@ -1679,7 +1682,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
16791682
$serializerLoaders = [];
16801683
if (isset($config['enable_annotations']) && $config['enable_annotations']) {
16811684
if (\PHP_VERSION_ID < 80000 && !$this->annotationsConfigEnabled) {
1682-
throw new \LogicException('"enable_annotations" on the serializer cannot be set as Annotations support is disabled.');
1685+
throw new \LogicException('"enable_annotations" on the serializer cannot be set as the PHP version is lower than 8 and Annotations support is disabled. Consider upgrading PHP.');
16831686
}
16841687

16851688
$annotationLoader = new Definition(

src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\HttpKernel\HttpCache\Store;
1919
use Symfony\Component\HttpKernel\HttpCache\StoreInterface;
2020
use Symfony\Component\HttpKernel\HttpCache\SurrogateInterface;
21-
use Symfony\Component\HttpKernel\HttpKernelInterface;
2221
use Symfony\Component\HttpKernel\KernelInterface;
2322

2423
/**
@@ -63,15 +62,6 @@ public function __construct(KernelInterface $kernel, $cache = null, SurrogateInt
6362
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge($this->options, $this->getOptions()));
6463
}
6564

66-
public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true)
67-
{
68-
if ($this->kernel->getContainer()->getParameter('kernel.http_method_override')) {
69-
Request::enableHttpMethodParameterOverride();
70-
}
71-
72-
return parent::handle($request, $type, $catch);
73-
}
74-
7565
/**
7666
* {@inheritdoc}
7767
*/

src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ trait MicroKernelTrait
6161
*
6262
* $c->parameters()->set('halloween', 'lot of fun');
6363
*/
64-
//abstract protected function configureContainer(ContainerConfigurator $c): void;
64+
//abstract protected function configureContainer(ContainerConfigurator $container): void;
6565

6666
/**
6767
* {@inheritdoc}
@@ -129,7 +129,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
129129
try {
130130
$configureContainer = new \ReflectionMethod($this, 'configureContainer');
131131
} catch (\ReflectionException $e) {
132-
throw new \LogicException(sprintf('"%s" uses "%s", but does not implement the required method "protected function configureContainer(ContainerConfigurator $c): void".', get_debug_type($this), MicroKernelTrait::class), 0, $e);
132+
throw new \LogicException(sprintf('"%s" uses "%s", but does not implement the required method "protected function configureContainer(ContainerConfigurator $container): void".', get_debug_type($this), MicroKernelTrait::class), 0, $e);
133133
}
134134

135135
$configuratorClass = $configureContainer->getNumberOfParameters() > 0 && ($type = $configureContainer->getParameters()[0]->getType()) instanceof \ReflectionNamedType && !$type->isBuiltin() ? $type->getName() : null;

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPUnit\Framework\MockObject\MockObject;
1010
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
1111
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
12+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1213
use Symfony\Component\Cache\Adapter\NullAdapter;
1314
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
1415
use Symfony\Component\Cache\DoctrineProvider;
@@ -127,6 +128,35 @@ public function testClassAutoloadExceptionWithUnrelatedException()
127128
spl_autoload_unregister($classLoader);
128129
}
129130

131+
public function testWarmupRemoveCacheMisses()
132+
{
133+
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
134+
$warmer = $this->getMockBuilder(AnnotationsCacheWarmer::class)
135+
->setConstructorArgs([new AnnotationReader(), $cacheFile])
136+
->setMethods(['doWarmUp'])
137+
->getMock();
138+
139+
$warmer->method('doWarmUp')->willReturnCallback(function ($cacheDir, ArrayAdapter $arrayAdapter) {
140+
$arrayAdapter->getItem('foo_miss');
141+
142+
$item = $arrayAdapter->getItem('bar_hit');
143+
$item->set('data');
144+
$arrayAdapter->save($item);
145+
146+
$item = $arrayAdapter->getItem('baz_hit_null');
147+
$item->set(null);
148+
$arrayAdapter->save($item);
149+
150+
return true;
< 741A div aria-hidden="true" class="position-absolute top-0 d-flex user-select-none DiffLineTableCellParts-module__comment-indicator--eI0hb">
151+
});
152+
153+
$warmer->warmUp($this->cacheDir);
154+
$data = include $cacheFile;
155+
156+
$this->assertCount(1, $data[0]);
157+
$this->assertTrue(isset($data[0]['bar_hit']));
158+
}
159+
130160
/**
131161
* @return MockObject|Reader
132162
*/

src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected function configureRoutes(RoutingConfigurator $routes): void
136136
};
137137

138138
$this->expectException(\LogicException::class);
139-
$this->expectExceptionMessage('"Symfony\Bundle\FrameworkBundle\Tests\Kernel\MinimalKernel@anonymous" uses "Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait", but does not implement the required method "protected function configureContainer(ContainerConfigurator $c): void".');
139+
$this->expectExceptionMessage('"Symfony\Bundle\FrameworkBundle\Tests\Kernel\MinimalKernel@anonymous" uses "Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait", but does not implement the required method "protected function configureContainer(ContainerConfigurator $container): void".');
140140

141141
$kernel->boot();
142142
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ private function freeze($value, $key)
350350
try {
351351
$serialized = serialize($value);
352352
} catch (\Exception $e) {
353+
unset($this->values[$key]);
353354
$type = get_debug_type($value);
354355
$message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
355356
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< 10000 /span>->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);

0 commit comments

Comments
 (0)
0