Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit454d16b

Browse files
committed
feature#52962 [FrameworkBundle] Move Router cache directory tokernel.build_dir (Okhoshi)
This PR was squashed before being merged into the 7.1 branch.Discussion----------[FrameworkBundle] Move Router cache directory to `kernel.build_dir`| Q | A| ------------- | ---| Branch? | 7.1| Bug fix? | no| New feature? | yes| Deprecations? | no| Issues | none| License | MITFollow up to#50391, set up Router cache directory to `kernel.build_dir` instead of `kernel.cache_dir` by default, and only warm the cache on read-only resources phase.#SymfonyHackdayCommits-------1f031f8 [FrameworkBundle] Move Router cache directory to `kernel.build_dir`
2 parents2bf8fb9 +1f031f8 commit454d16b

File tree

6 files changed

+55
-13
lines changed

6 files changed

+55
-13
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Move the Router`cache_dir` to`kernel.build_dir`
8+
* Deprecate the`router.cache_dir` config option
9+
410
7.0
511
---
612

‎src/Symfony/Bundle/FrameworkBundle/CacheWarmer/RouterCacheWarmer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public function __construct(ContainerInterface $container)
3636

3737
publicfunctionwarmUp(string$cacheDir,string$buildDir =null):array
3838
{
39+
if (!$buildDir) {
40+
return [];
41+
}
42+
3943
$router =$this->container->get('router');
4044

4145
if ($routerinstanceof WarmableInterface) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,10 @@ private function addRouterSection(ArrayNodeDefinition $rootNode): void
613613
->children()
614614
->scalarNode('resource')->isRequired()->end()
615615
->scalarNode('type')->end()
616-
->scalarNode('cache_dir')->defaultValue('%kernel.cache_dir%')->end()
616+
->scalarNode('cache_dir')
617+
->defaultValue('%kernel.build_dir%')
618+
->setDeprecated('symfony/framework-bundle','7.1','Setting the "%path%.%node%" configuration option is deprecated. It will be removed in version 8.0.')
619+
->end()
617620
->scalarNode('default_uri')
618621
->info('The default URI used to generate URLs in a non-HTTP context')
619622
->defaultNull()

‎src/Symfony/Bundle/FrameworkBundle/Routing/Router.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,14 @@ public function getRouteCollection(): RouteCollection
8282

8383
publicfunctionwarmUp(string$cacheDir,string$buildDir =null):array
8484
{
85+
if (!$buildDir) {
86+
return [];
87+
}
88+
8589
$currentDir =$this->getOption('cache_dir');
8690

87-
// force cache generation
88-
$this->setOption('cache_dir',$cacheDir);
91+
// force cache generation in build_dir
92+
$this->setOption('cache_dir',$buildDir);
8993
$this->getMatcher();
9094
$this->getGenerator();
9195

‎src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/RouterCacheWarmerTest.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,61 @@
1919

2020
class RouterCacheWarmerTestextends TestCase
2121
{
22-
publicfunctiontestWarmUpWithWarmebleInterface()
22+
publicfunctiontestWarmUpWithWarmableInterfaceWithBuildDir()
2323
{
2424
$containerMock =$this->getMockBuilder(ContainerInterface::class)->onlyMethods(['get','has'])->getMock();
2525

26-
$routerMock =$this->getMockBuilder(testRouterInterfaceWithWarmebleInterface::class)->onlyMethods(['match','generate','getContext','setContext','getRouteCollection','warmUp'])->getMock();
26+
$routerMock =$this->getMockBuilder(testRouterInterfaceWithWarmableInterface::class)->onlyMethods(['match','generate','getContext','setContext','getRouteCollection','warmUp'])->getMock();
2727
$containerMock->expects($this->any())->method('get')->with('router')->willReturn($routerMock);
2828
$routerCacheWarmer =newRouterCacheWarmer($containerMock);
2929

30-
$routerCacheWarmer->warmUp('/tmp');
31-
$routerMock->expects($this->any())->method('warmUp')->with('/tmp')->willReturn([]);
30+
$routerCacheWarmer->warmUp('/tmp/cache','/tmp/build');
31+
$routerMock->expects($this->any())->method('warmUp')->with('/tmp/cache','/tmp/build')->willReturn([]);
3232
$this->addToAssertionCount(1);
3333
}
3434

35-
publicfunctiontestWarmUpWithoutWarmebleInterface()
35+
publicfunctiontestWarmUpWithoutWarmableInterfaceWithBuildDir()
3636
{
3737
$containerMock =$this->getMockBuilder(ContainerInterface::class)->onlyMethods(['get','has'])->getMock();
3838

39-
$routerMock =$this->getMockBuilder(testRouterInterfaceWithoutWarmebleInterface::class)->onlyMethods(['match','generate','getContext','setContext','getRouteCollection'])->getMock();
39+
$routerMock =$this->getMockBuilder(testRouterInterfaceWithoutWarmableInterface::class)->onlyMethods(['match','generate','getContext','setContext','getRouteCollection'])->getMock();
4040
$containerMock->expects($this->any())->method('get')->with('router')->willReturn($routerMock);
4141
$routerCacheWarmer =newRouterCacheWarmer($containerMock);
4242
$this->expectException(\LogicException::class);
4343
$this->expectExceptionMessage('cannot be warmed up because it does not implement "Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface"');
44-
$routerCacheWarmer->warmUp('/tmp');
44+
$routerCacheWarmer->warmUp('/tmp/cache','/tmp/build');
45+
}
46+
47+
publicfunctiontestWarmUpWithWarmableInterfaceWithoutBuildDir()
48+
{
49+
$containerMock =$this->getMockBuilder(ContainerInterface::class)->onlyMethods(['get','has'])->getMock();
50+
51+
$routerMock =$this->getMockBuilder(testRouterInterfaceWithWarmableInterface::class)->onlyMethods(['match','generate','getContext','setContext','getRouteCollection','warmUp'])->getMock();
52+
$containerMock->expects($this->any())->method('get')->with('router')->willReturn($routerMock);
53+
$routerCacheWarmer =newRouterCacheWarmer($containerMock);
54+
55+
$preload =$routerCacheWarmer->warmUp('/tmp');
56+
$routerMock->expects($this->never())->method('warmUp');
57+
self::assertSame([],$preload);
58+
$this->addToAssertionCount(1);
59+
}
60+
61+
publicfunctiontestWarmUpWithoutWarmableInterfaceWithoutBuildDir()
62+
{
63+
$containerMock =$this->getMockBuilder(ContainerInterface::class)->onlyMethods(['get','has'])->getMock();
64+
65+
$routerMock =$this->getMockBuilder(testRouterInterfaceWithoutWarmableInterface::class)->onlyMethods(['match','generate','getContext','setContext','getRouteCollection'])->getMock();
66+
$containerMock->expects($this->any())->method('get')->with('router')->willReturn($routerMock);
67+
$routerCacheWarmer =newRouterCacheWarmer($containerMock);
68+
$preload =$routerCacheWarmer->warmUp('/tmp');
69+
self::assertSame([],$preload);
4570
}
4671
}
4772

48-
interfacetestRouterInterfaceWithWarmebleInterfaceextends RouterInterface, WarmableInterface
73+
interfacetestRouterInterfaceWithWarmableInterfaceextends RouterInterface, WarmableInterface
4974
{
5075
}
5176

52-
interfacetestRouterInterfaceWithoutWarmebleInterfaceextends RouterInterface
77+
interfacetestRouterInterfaceWithoutWarmableInterfaceextends RouterInterface
5378
{
5479
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ protected static function getBundleDefaultConfig()
634634
'https_port' =>443,
635635
'strict_requirements' =>true,
636636
'utf8' =>true,
637-
'cache_dir' =>'%kernel.cache_dir%',
637+
'cache_dir' =>'%kernel.build_dir%',
638638
],
639639
'session' => [
640640
'enabled' =>false,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp