Skip to content

Commit 822efd2

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 caa59cd + 8a5cad8 commit 822efd2

File tree

8 files changed

+61
-27
lines changed

8 files changed

+61
-27
lines changed

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);

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
/**

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 <[email protected]>
49-
* @author Grégoire Pineau <[email protected]>
5047
*/
5148
class Configuration implements ConfigurationInterface
5249
{

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 <[email protected]>
194-
* @author Jeremy Mikola <[email protected]>
195-
* @author Kévin Dunglas <[email protected]>
196-
* @author Grégoire Pineau <[email protected]>
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(

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
*/

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;

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;
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
*/

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
}

0 commit comments

Comments
 (0)