8000 merged branch dbu/router-cache-warmup-interface (PR #2451) · vatson/symfony@cb9ac13 · GitHub
[go: up one dir, main page]

Skip to content

Commit cb9ac13

Browse files
committed
merged branch dbu/router-cache-warmup-interface (PR symfony#2451)
Commits ------- 96235a6 cs fix 46a69f1 define a WarmableInterface and only warm the cache if it implements warmable to allow replacing the core router. this fixes symfony#2422. combining routers will only really work when symfony#2450 is merged too. Discussion ---------- define a WarmableInterface and only warm the cache if it implements warmable define a WarmableInterface and only warm the cache if it implements warmable to allow replacing the core router. this fixes symfony#2422. combining routers will only really work when symfony#2450 is merged too. Bug fix: yes Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: yes* Fixes the following tickets: symfony#2422 (*) tests: success for phpunit src/Symfony/Bundle/FrameworkBundle/Tests/ and phpunit tests/Symfony/Tests/Component/Routing/ but when running all tests, i have to put gc_disable() into autoload to avoid segmentation fault and then get (after 3000 successful tests): PHP Fatal error: Call to undefined method Symfony\Tests\Component\HttpKernel\Debug\StopwatchTest::assertCount() in /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/tests/Symfony/Tests/Component/HttpKernel/Debug/StopwatchTest.php on line 84 --------------------------------------------------------------------------- by stof at 2011/10/22 08:46:31 -0700 @dbu assertCount is new in PHP 3.6. It seems like the test of the new 2.1 feature has been written using 3.6-RC. ----------------------------------------------------------------------- 8000 ---- by dbu at 2011/10/22 09:40:07 -0700 @stof: ah, thanks for the hint. i hope you mean php 3.4 and not 3.6? but i assume symfony 2.1 should be able to run on 3.3, right? anyways, the tests run through if i disable the StopWatch, so i guess we can consider the tests succeeding. --------------------------------------------------------------------------- by stof at 2011/10/22 09:41:28 -0700 this is a method of PHPUnit TestCase class. I was talking about the PHPUnit version
2 parents 3134ef1 + 96235a6 commit cb9ac13

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
1313

1414
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
15-
use Symfony\Component\Routing\Router;
15+
use Symfony\Component\Routing\RouterInterface;
1616

1717
/**
1818
* Generates the router matcher and generator classes.
@@ -28,7 +28,7 @@ class RouterCacheWarmer implements CacheWarmerInterface
2828
*
2929
* @param Router $router A Router instance
3030
*/
31-
public function __construct(Router $router)
31+
public function __construct(RouterInterface $router)
3232
{
3333
$this->router = $router;
3434
}
@@ -40,14 +40,9 @@ public function __construct(Router $router)
4040
*/
4141
public function warmUp($cacheDir)
4242
{
43-
$currentDir = $this->router->getOption('cache_dir');
44-
45-
// force cache generation
46-
$this->router->setOption('cache_dir', $cacheDir);
47-
$this->router->getMatcher();
48-
$this->router->getGenerator();
49-
50-
$this->router->setOption('cache_dir', $currentDir);
43+
if ($this->router instanceof WarmableInterface) {
44+
$this->router->warmUp($cacheDir);
45+
}
5146
}
5247

5348
/**
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
13+
14+
/**
15+
* Interface for services that support warming their cache.
16+
*
17+
* @author Fabien Potencier <fabien@symfony.com>
18+
*/
19+
interface WarmableInterface
20+
{
21+
/**
22+
* Warms up the cache.
23+
*
24+
10000 * @param string $cacheDir The cache directory
25+
*/
26+
function warmUp($cacheDir);
27+
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
use Symfony\Component\Routing\RequestContext;
1616
use Symfony\Component\DependencyInjection\ContainerInterface;
1717
use Symfony\Component\Routing\RouteCollection;
18+
use Symfony\Bundle\FrameworkBundle\CacheWarmer\WarmableInterface;
1819

1920
/**
2021
* This Router only creates the Loader only when the cache is empty.
2122
*
2223
* @author Fabien Potencier <fabien@symfony.com>
2324
*/
24-
class Router extends BaseRouter
25+
class Router extends BaseRouter implements WarmableInterface
2526
{
2627
private $container;
2728

@@ -57,6 +58,21 @@ public function getRouteCollection()
5758
return $this->collection;
5859
}
5960

61+
/**
62+
* {@inheritdoc}
63+
*/
64+
public function warmUp($cacheDir)
65+
{
66+
$currentDir = $this->getOption('cache_dir');
67+
68+
// force cache generation
69+
$this->setOption('cache_dir', $cacheDir);
70+
$this->getMatcher();
71+
$this->getGenerator();
72+
73+
$this->setOption('cache_dir', $currentDir);
74+
}
75+
6076
/**
6177
* Replaces placeholders with service container parameter values in route defaults and requirements.
6278
*

0 commit comments

Comments
 (0)
0