From df6163756288f720e57bc6a1f925bfd657619518 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Wed, 12 Dec 2012 11:56:07 -0800 Subject: [PATCH 1/2] updated to work with twig formula loader changes --- .gitignore | 1 + Resources/config/assetic.xml | 1 - Resources/config/templating_php.xml | 1 + Resources/config/templating_twig.xml | 9 ++------- Tests/FunctionalTest.php | 13 ++----------- Twig/AsseticExtension.php | 11 ++++++----- composer.json | 2 +- 7 files changed, 13 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 68521000..1e31ec7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ phpunit.xml vendor composer.lock +Tests/Resources/cache/ diff --git a/Resources/config/assetic.xml b/Resources/config/assetic.xml index 7d059791..090421b4 100644 --- a/Resources/config/assetic.xml +++ b/Resources/config/assetic.xml @@ -8,7 +8,6 @@ Symfony\Bundle\AsseticBundle\Factory\AssetFactory Assetic\Factory\LazyAssetManager Symfony\Bundle\AsseticBundle\CacheWarmer\AssetManagerCacheWarmer - Assetic\Factory\Loader\CachedFormulaLoader Assetic\Cache\ConfigCache Symfony\Bundle\AsseticBundle\Factory\Loader\ConfigurationLoader Symfony\Bundle\AsseticBundle\Factory\Resource\ConfigurationResource diff --git a/Resources/config/templating_php.xml b/Resources/config/templating_php.xml index b6843d92..741419f6 100644 --- a/Resources/config/templating_php.xml +++ b/Resources/config/templating_php.xml @@ -8,6 +8,7 @@ Symfony\Bundle\AsseticBundle\Templating\DynamicAsseticHelper Symfony\Bundle\AsseticBundle\Templating\StaticAsseticHelper Symfony\Bundle\AsseticBundle\Factory\Loader\AsseticHelperFormulaLoader + Assetic\Factory\Loader\CachedFormulaLoader diff --git a/Resources/config/templating_twig.xml b/Resources/config/templating_twig.xml index 8ab025bb..9e8cb92c 100644 --- a/Resources/config/templating_twig.xml +++ b/Resources/config/templating_twig.xml @@ -14,20 +14,15 @@ + %assetic.use_controller% %assetic.twig_extension.functions% %assetic.bundles% - + - - - - %kernel.debug% - - diff --git a/Tests/FunctionalTest.php b/Tests/FunctionalTest.php index 814c1cdb..f2043d83 100644 --- a/Tests/FunctionalTest.php +++ b/Tests/FunctionalTest.php @@ -29,18 +29,9 @@ protected function setUp() } $this->cacheDir = __DIR__.'/Resources/cache'; - if (file_exists($this->cacheDir)) { - $filesystem = new Filesystem(); - $filesystem->remove($this->cacheDir); + if (!file_exists($this->cacheDir)) { + mkdir($this->cacheDir, 0777, true); } - - mkdir($this->cacheDir, 0777, true); - } - - protected function tearDown() - { - $filesystem = new Filesystem(); - $filesystem->remove($this->cacheDir); } public function testTwigRenderDebug() diff --git a/Twig/AsseticExtension.php b/Twig/AsseticExtension.php index 3e84fe3f..5e72a252 100644 --- a/Twig/AsseticExtension.php +++ b/Twig/AsseticExtension.php @@ -11,9 +11,10 @@ namespace Symfony\Bundle\AsseticBundle\Twig; -use Assetic\ValueSupplierInterface; +use Assetic\Cache\ConfigCache; use Assetic\Extension\Twig\AsseticExtension as BaseAsseticExtension; use Assetic\Factory\AssetFactory; +use Assetic\ValueSupplierInterface; use Symfony\Component\Templating\TemplateNameParserInterface; /** @@ -27,9 +28,9 @@ class AsseticExtension extends BaseAsseticExtension private $templateNameParser; private $enabledBundles; - public function __construct(AssetFactory $factory, TemplateNameParserInterface $templateNameParser, $useController = false, $functions = array(), $enabledBundles = array(), ValueSupplierInterface $valueSupplier = null) + public function __construct(AssetFactory $factory, ConfigCache $cache, TemplateNameParserInterface $templateNameParser, $useController = false, $functions = array(), $enabledBundles = array(), ValueSupplierInterface $valueSupplier = null) { - parent::__construct($factory, $functions, $valueSupplier); + parent::__construct($factory, $cache, $functions, $valueSupplier); $this->useController = $useController; $this->templateNameParser = $templateNameParser; @@ -47,9 +48,9 @@ public function getTokenParsers() public function getNodeVisitors() { - return array( + return array_merge(parent::getNodeVisitors(), array( new AsseticNodeVisitor($this->templateNameParser, $this->enabledBundles), - ); + )); } public function getGlobals() diff --git a/composer.json b/composer.json index c3396a48..608c30e6 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": { "php": ">=5.3.0", "symfony/framework-bundle": ">=2.1.0,<2.3-dev", - "kriswallsmith/assetic": "1.1.*" + "kriswallsmith/assetic": "dev-node-visitor" }, "require-dev": { "symfony/twig-bundle": ">=2.1.0,<2.3-dev", From 344ad10f707bd202d18fb279b7c29fbeb53b3928 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Wed, 12 Dec 2012 12:10:35 -0800 Subject: [PATCH 2/2] cleaned up cleanup Files in the cache directory need to be removed in these static methods, otherwise Twig will see class_exists() return true in ->loadTemplate() and skip re-compiling because of that, but the node visitor's ConfigCache file for that template will be gone. --- .gitignore | 1 - Tests/FunctionalTest.php | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 1e31ec7e..68521000 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ phpunit.xml vendor composer.lock -Tests/Resources/cache/ diff --git a/Tests/FunctionalTest.php b/Tests/FunctionalTest.php index f2043d83..090785f5 100644 --- a/Tests/FunctionalTest.php +++ b/Tests/FunctionalTest.php @@ -20,18 +20,27 @@ */ class FunctionalTest extends \PHPUnit_Framework_TestCase { - protected $cacheDir; + static protected $cacheDir; - protected function setUp() + static public function setUpBeforeClass() { if (!class_exists('Assetic\\AssetManager')) { - $this->markTestSkipped('Assetic is not available.'); + self::markTestSkipped('Assetic is not available.'); } - $this->cacheDir = __DIR__.'/Resources/cache'; - if (!file_exists($this->cacheDir)) { - mkdir($this->cacheDir, 0777, true); + self::$cacheDir = __DIR__.'/Resources/cache'; + if (file_exists(self::$cacheDir)) { + $filesystem = new Filesystem(); + $filesystem->remove(self::$cacheDir); } + + mkdir(self::$cacheDir, 0777, true); + } + + static public function tearDownAfterClass() + { + $filesystem = new Filesystem(); + $filesystem->remove(self::$cacheDir); } public function testTwigRenderDebug()