diff --git a/src/Symfony/Bundle/AsseticBundle/AsseticBundle.php b/src/Symfony/Bundle/AsseticBundle/AsseticBundle.php index 06aa33286c6a4..a49da05e24599 100644 --- a/src/Symfony/Bundle/AsseticBundle/AsseticBundle.php +++ b/src/Symfony/Bundle/AsseticBundle/AsseticBundle.php @@ -28,8 +28,8 @@ public function build(ContainerBuilder $container) { parent::build($container); + $container->addCompilerPass(new TemplatingPass()); $container->addCompilerPass(new AssetManagerPass()); $container->addCompilerPass(new FilterManagerPass()); - $container->addCompilerPass(new TemplatingPass()); } } diff --git a/src/Symfony/Bundle/AsseticBundle/CacheWarmer/AssetManagerCacheWarmer.php b/src/Symfony/Bundle/AsseticBundle/CacheWarmer/AssetManagerCacheWarmer.php new file mode 100644 index 0000000000000..e8a81c1a9e33b --- /dev/null +++ b/src/Symfony/Bundle/AsseticBundle/CacheWarmer/AssetManagerCacheWarmer.php @@ -0,0 +1,35 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Symfony\Bundle\AsseticBundle\CacheWarmer; + +use Assetic\Factory\LazyAssetManager; +use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer; + +class AssetManagerCacheWarmer extends CacheWarmer +{ + protected $am; + + public function __construct(LazyAssetManager $am) + { + $this->am = $am; + } + + public function warmUp($cacheDir) + { + $this->am->load(); + } + + public function isOptional() + { + return true; + } +} diff --git a/src/Symfony/Bundle/AsseticBundle/CacheWarmer/PhpTemplatingAssetsCacheWarmer.php b/src/Symfony/Bundle/AsseticBundle/CacheWarmer/PhpTemplatingAssetsCacheWarmer.php deleted file mode 100644 index 3d2325b8b6962..0000000000000 --- a/src/Symfony/Bundle/AsseticBundle/CacheWarmer/PhpTemplatingAssetsCacheWarmer.php +++ /dev/null @@ -1,58 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Symfony\Bundle\AsseticBundle\CacheWarmer; - -use Symfony\Bundle\AsseticBundle\Templating\FormulaLoader; -use Symfony\Component\Finder\Finder; -use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer; -use Symfony\Component\HttpKernel\Kernel; - -class PhpTemplatingAssetsCacheWarmer extends CacheWarmer -{ - protected $kernel; - protected $loader; - - public function __construct(Kernel $kernel, FormulaLoader $loader) - { - $this->kernel = $kernel; - $this->loader = $loader; - } - - public function warmUp($cacheDir) - { - $formulae = array(); - foreach ($this->kernel->getBundles() as $name => $bundle) { - if (is_dir($dir = $bundle->getPath().'/Resources/views/')) { - $finder = new Finder(); - $finder->files()->name('*.php')->in($dir); - foreach ($finder as $file) { - $formulae += $this->loader->load($name.':'.substr($file->getPath(), strlen($dir)).':'.$file->getBasename()); - } - } - } - - if (is_dir($dir = $this->kernel->getRootDir().'/views/')) { - $finder = new Finder(); - $finder->files()->name('*.php')->in($dir); - foreach ($finder as $file) { - $formulae += $this->loader->load(':'.substr($file->getPath(), strlen($dir)).':'.$file->getBasename()); - } - } - - $this->writeCacheFile($cacheDir.'/assetic_php_templating_assets.php', ' - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Symfony\Bundle\AsseticBundle\CacheWarmer; - -use Assetic\Extension\Twig\FormulaLoader; -use Symfony\Component\Finder\Finder; -use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer; -use Symfony\Component\HttpKernel\Kernel; - -class TwigAssetsCacheWarmer extends CacheWarmer -{ - protected $kernel; - protected $loader; - - public function __construct(Kernel $kernel, FormulaLoader $loader) - { - $this->kernel = $kernel; - $this->loader = $loader; - } - - public function warmUp($cacheDir) - { - $formulae = array(); - foreach ($this->kernel->getBundles() as $name => $bundle) { - if (is_dir($dir = $bundle->getPath().'/Resources/views/')) { - $finder = new Finder(); - $finder->files()->name('*.twig')->in($dir)->sortByName(); - foreach ($finder as $file) { - $formulae += $this->loader->load($name.':'.substr($file->getPath(), strlen($dir)).':'.$file->getBasename()); - } - } - } - - if (is_dir($dir = $this->kernel->getRootDir().'/views/')) { - $finder = new Finder(); - $finder->files()->name('*.twig')->in($dir); - foreach ($finder as $file) { - $formulae += $this->loader->load(':'.substr($file->getPath(), strlen($dir)).':'.$file->getBasename()); - } - } - - $this->writeCacheFile($cacheDir.'/assetic_twig_assets.php', 'hasParameter('assetic.less.compress')) { $container->getDefinition('assetic.filter.less')->addMethodCall('setCompress', array('%assetic.less.compress%')); } + + $this->registerFormulaResources($container); + } + + protected function registerFormulaResources(ContainerBuilder $container) + { + // bundle views/ directories + $am = $container->getDefinition('assetic.asset_manager'); + foreach ($container->getParameter('kernel.bundles') as $name => $class) { + $rc = new \ReflectionClass($class); + if (is_dir($dir = dirname($rc->getFileName()).'/Resources/views')) { + foreach (array('twig', 'php') as $engine) { + $container->setDefinition( + 'assetic.'.$engine.'_directory_resource.'.$name, + $this->createDirectoryResourceDefinition($name, $dir, $engine) + ); + } + } + } + + // kernel views/ directory + if (is_dir($dir = $container->getParameter('kernel.root_dir').'/views')) { + foreach (array('twig', 'php') as $engine) { + $container->setDefinition( + 'assetic.'.$engine.'_directory_resource.kernel', + $this->createDirectoryResourceDefinition('', $dir, $engine) + ); + } + } + } + + /** + * @todo decorate an abstract xml definition + */ + protected function createDirectoryResourceDefinition($bundle, $dir, $engine) + { + $definition = new Definition('%assetic.directory_resource.class%'); + + $definition + ->addArgument(new Reference('templating.name_parser')) + ->addArgument(new Reference('templating.loader')) + ->addArgument($bundle) + ->addArgument($dir) + ->addArgument('/\.'.$engine.'$/') + ->addTag('assetic.templating.'.$engine) + ->addTag('assetic.formula_resource', array('loader' => $engine)) + ->setPublic(false) + ; + + return $definition; } /** diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/AssetManagerPass.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/AssetManagerPass.php index 1f2c1819293c3..d47a8fc276d63 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/AssetManagerPass.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/AssetManagerPass.php @@ -29,6 +29,8 @@ public function process(ContainerBuilder $container) } $am = $container->getDefinition('assetic.asset_manager'); + + // add assets foreach ($container->findTaggedServiceIds('assetic.asset') as $id => $attributes) { foreach ($attributes as $attr) { if (isset($attr['alias'])) { @@ -36,5 +38,25 @@ public function process(ContainerBuilder $container) } } } + + // add loaders + $loaders = array(); + foreach ($container->findTaggedServiceIds('assetic.formula_loader') as $id => $attributes) { + foreach ($attributes as $attr) { + if (isset($attr['alias'])) { + $loaders[$attr['alias']] = new Reference($id); + } + } + } + $am->setArgument(1, $loaders); + + // add resources + foreach ($container->findTaggedServiceIds('assetic.formula_resource') as $id => $attributes) { + foreach ($attributes as $attr) { + if (isset($attr['loader'])) { + $am->addMethodCall('addResource', array($attr['loader'], new Reference($id))); + } + } + } } } diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/TemplatingPass.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/TemplatingPass.php index c8570305c8178..80361c867d775 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/TemplatingPass.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/TemplatingPass.php @@ -14,6 +14,11 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +/** + * This pass removes services associated with unused templating engines. + * + * @author Kris Wallsmith + */ class TemplatingPass implements CompilerPassInterface { public function process(ContainerBuilder $container) @@ -25,17 +30,13 @@ public function process(ContainerBuilder $container) $am = $container->getDefinition('assetic.asset_manager'); $engines = $container->getParameterBag()->resolveValue($container->getParameter('templating.engines')); - if (in_array('twig', $engines)) { - $am->addMethodCall('addCacheFile', array('%kernel.cache_dir%/assetic_twig_assets.php')); - } else { + if (!in_array('twig', $engines)) { foreach ($container->findTaggedServiceIds('assetic.templating.twig') as $id => $attr) { $container->remove($id); } } - if (in_array('php', $engines)) { - // $am->addMethodCall('addCacheFile', array('%kernel.cache_dir%/assetic_php_assets.php')); - } else { + if (!in_array('php', $engines)) { foreach ($container->findTaggedServiceIds('assetic.templating.php') as $id => $attr) { $container->remove($id); } diff --git a/src/Symfony/Bundle/AsseticBundle/Factory/AssetManager.php b/src/Symfony/Bundle/AsseticBundle/Factory/AssetManager.php deleted file mode 100644 index 42bd4b4cfed53..0000000000000 --- a/src/Symfony/Bundle/AsseticBundle/Factory/AssetManager.php +++ /dev/null @@ -1,90 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Symfony\Bundle\AsseticBundle\Factory; - -use Assetic\Factory\LazyAssetManager; - -/** - * Loads asset formulae from the filesystem. - * - * @author Kris Wallsmith - */ -class AssetManager extends LazyAssetManager -{ - protected $cacheFiles = array(); - protected $fresh = true; - - /** - * Adds a cache file. - * - * Files added will be lazily loaded once needed. - * - * @param string $file A file that returns an array of formulae - */ - public function addCacheFile($file) - { - $this->cacheFiles[] = $file; - $this->fresh = false; - } - - public function getFormulae() - { - if (!$this->fresh) { - $this->loadCacheFiles(); - } - - return $this->formulae; - } - - public function get($name) - { - if (!$this->fresh) { - $this->loadCacheFiles(); - } - - return parent::get($name); - } - - public function has($name) - { - if (!$this->fresh) { - $this->loadCacheFiles(); - } - - return parent::has($name); - } - - public function all() - { - if (!$this->fresh) { - $this->loadCacheFiles(); - } - - return parent::all(); - } - - /** - * Loads formulae from the cache files. - */ - protected function loadCacheFiles() - { - while ($file = array_shift($this->cacheFiles)) { - if (!file_exists($file)) { - throw new \RuntimeException('The asset manager cache has not been warmed.'); - } - - $this->addFormulae(require $file); - } - - $this->fresh = true; - } -} diff --git a/src/Symfony/Bundle/AsseticBundle/Factory/DirectoryResource.php b/src/Symfony/Bundle/AsseticBundle/Factory/DirectoryResource.php new file mode 100644 index 0000000000000..33740a36518c2 --- /dev/null +++ b/src/Symfony/Bundle/AsseticBundle/Factory/DirectoryResource.php @@ -0,0 +1,48 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Symfony\Bundle\AsseticBundle\Factory; + +use Assetic\Factory\Resource\DirectoryResource as BaseDirectoryResource; +use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; +use Symfony\Component\Templating\Loader\LoaderInterface; + +/** + * A directory resource that creates Symfony2 resources. + * + * @author Kris Wallsmith + */ +class DirectoryResource extends BaseDirectoryResource +{ + protected $parser; + protected $loader; + protected $bundle; + protected $baseDirLength; + + public function __construct(TemplateNameParser $parser, LoaderInterface $loader, $bundle, $baseDir, $pattern = null) + { + $this->parser = $parser; + $this->loader = $loader; + $this->bundle = $bundle; + + $this->baseDirLength = strlen(rtrim($baseDir, '/')) + 1; + + parent::__construct($baseDir, $pattern); + } + + protected function createResource($path) + { + $template = $this->parser->parseFromFilename(substr($path, $this->baseDirLength)); + $template->set('bundle', $this->bundle); + + return new FileResource($this->loader, $template); + } +} diff --git a/src/Symfony/Bundle/AsseticBundle/Factory/FileResource.php b/src/Symfony/Bundle/AsseticBundle/Factory/FileResource.php new file mode 100644 index 0000000000000..ef7d9fea9e452 --- /dev/null +++ b/src/Symfony/Bundle/AsseticBundle/Factory/FileResource.php @@ -0,0 +1,43 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Symfony\Bundle\AsseticBundle\Factory; + +use Assetic\Factory\Resource\ResourceInterface; +use Symfony\Component\Templating\Loader\LoaderInterface; +use Symfony\Component\Templating\TemplateReferenceInterface; + +/** + * A file resource. + * + * @author Kris Wallsmith + */ +class FileResource implements ResourceInterface +{ + protected $loader; + protected $template; + + public function __construct(LoaderInterface $loader, TemplateReferenceInterface $template) + { + $this->loader = $loader; + $this->template = $template; + } + + public function isFresh($timestamp) + { + return $this->loader->isFresh($this->template, $timestamp); + } + + public function getContent() + { + return $this->loader->load($this->template)->getContent(); + } +} diff --git a/src/Symfony/Bundle/AsseticBundle/FilterManager.php b/src/Symfony/Bundle/AsseticBundle/FilterManager.php index 4b49121eab46f..c2a714bfc88bd 100644 --- a/src/Symfony/Bundle/AsseticBundle/FilterManager.php +++ b/src/Symfony/Bundle/AsseticBundle/FilterManager.php @@ -45,16 +45,11 @@ public function get($name) public function has($name) { - return isset($this->mappings) || parent::has($name); + return isset($this->mappings[$name]) || parent::has($name); } - public function all() + public function getNames() { - $filters = array(); - foreach ($this->mappings as $name => $id) { - $filters[$name] = $this->container->get($id); - } - - return $filters + parent::all(); + return array_unique(array_merge(array_keys($this->mappings), parent::getNames())); } } diff --git a/src/Symfony/Bundle/AsseticBundle/Resources/config/assetic.xml b/src/Symfony/Bundle/AsseticBundle/Resources/config/assetic.xml index 62c3729731c9f..fed878318ec1d 100644 --- a/src/Symfony/Bundle/AsseticBundle/Resources/config/assetic.xml +++ b/src/Symfony/Bundle/AsseticBundle/Resources/config/assetic.xml @@ -6,8 +6,12 @@ Symfony\Bundle\AsseticBundle\Factory\AssetFactory - Symfony\Bundle\AsseticBundle\Factory\AssetManager + Assetic\Factory\LazyAssetManager Symfony\Bundle\AsseticBundle\FilterManager + Assetic\Factory\Loader\CachedFormulaLoader + Assetic\Cache\ConfigCache + Symfony\Bundle\AsseticBundle\CacheWarmer\AssetManagerCacheWarmer + Symfony\Bundle\AsseticBundle\Factory\DirectoryResource Assetic\Filter\CoffeeScriptFilter Assetic\Filter\CssRewriteFilter @@ -24,6 +28,8 @@ /usr/bin/sprocketize /usr/bin/coffee + + %kernel.cache_dir%/assetic @@ -34,6 +40,7 @@ + @@ -79,5 +86,11 @@ PHP/CodeSniffer.php + + %assetic.cache_dir%/config + + + + diff --git a/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml b/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml index 2b372d97d1faa..1b895c3734590 100644 --- a/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml +++ b/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml @@ -8,7 +8,6 @@ Symfony\Bundle\AsseticBundle\Controller\AsseticController Symfony\Bundle\AsseticBundle\Routing\AsseticLoader Assetic\Cache\FilesystemCache - %kernel.cache_dir%/assetic @@ -22,7 +21,7 @@ - %assetic.cache_dir% + %assetic.cache_dir%/assets diff --git a/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_php.xml b/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_php.xml index c84cac30fad01..d30d4beeff4ef 100644 --- a/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_php.xml +++ b/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_php.xml @@ -6,8 +6,8 @@ Symfony\Bundle\AsseticBundle\Templating\AsseticHelper - Symfony\Bundle\AsseticBundle\CacheWarmer\PhpTemplatingAssetsCacheWarmer Symfony\Bundle\AsseticBundle\Templating\FormulaLoader + @@ -19,16 +19,14 @@ %assetic.default_javascripts_output% %assetic.default_stylesheets_output% - - + + - - + + - + - - diff --git a/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_twig.xml b/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_twig.xml index c2b60f5f10ae0..00ffb0d656e1c 100644 --- a/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_twig.xml +++ b/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_twig.xml @@ -7,8 +7,8 @@ Symfony\Bundle\AsseticBundle\Twig\DynamicExtension Symfony\Bundle\AsseticBundle\Twig\StaticExtension - Assetic\Extension\Twig\FormulaLoader - Symfony\Bundle\AsseticBundle\CacheWarmer\TwigAssetsCacheWarmer + Assetic\Extension\Twig\TwigFormulaLoader + @@ -20,13 +20,13 @@ %assetic.default_javascripts_output% %assetic.default_stylesheets_output% - - + + - - + + - + diff --git a/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php b/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php index 03bcb47d1ece7..04852a166eb0e 100644 --- a/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php +++ b/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php @@ -45,7 +45,9 @@ public function __construct(AssetManager $am) public function load($resource, $type = null) { $routes = new RouteCollection(); - foreach ($this->am->all() as $name => $asset) { + foreach ($this->am->getNames() as $name) { + $asset = $this->am->get($name); + $defaults = array( '_controller' => 'assetic.controller:render', 'name' => $name, diff --git a/src/Symfony/Bundle/AsseticBundle/Templating/FormulaLoader.php b/src/Symfony/Bundle/AsseticBundle/Templating/FormulaLoader.php index 2c55989dd3cac..05bc53f531891 100644 --- a/src/Symfony/Bundle/AsseticBundle/Templating/FormulaLoader.php +++ b/src/Symfony/Bundle/AsseticBundle/Templating/FormulaLoader.php @@ -11,32 +11,19 @@ namespace Symfony\Bundle\AsseticBundle\Templating; -use Symfony\Component\Templating\Loader\LoaderInterface; -use Symfony\Component\Templating\TemplateNameParser; +use Assetic\Factory\Loader\FormulaLoaderInterface; +use Assetic\Factory\Resource\ResourceInterface; /** * Loads formulae from PHP templates. * * @author Kris Wallsmith */ -class FormulaLoader +class FormulaLoader implements FormulaLoaderInterface { - protected $parser; - protected $loader; - - public function __construct(TemplateNameParser $parser, LoaderInterface $loader) + public function load(ResourceInterface $resource) { - $this->parser = $parser; - $this->loader = $loader; - } - - public function load($templateName) - { - if (!$template = $this->loader->load($this->parser->parse($templateName))) { - return array(); - } - - $tokens = token_get_all($template->getContent()); + $tokens = token_get_all($resource->getContent()); /** * @todo Find and extract asset formulae from calls to the following: diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/TwigAssetsCacheWarmerTest.php b/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/TwigAssetsCacheWarmerTest.php deleted file mode 100644 index 0fba854e6cc0f..0000000000000 --- a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/TwigAssetsCacheWarmerTest.php +++ /dev/null @@ -1,69 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Symfony\Bundle\AsseticBundle\Tests\CacheWarmer; - -use Symfony\Bundle\AsseticBundle\CacheWarmer\TwigAssetsCacheWarmer; - -class TwigAssetsCacheWarmerTest extends \PHPUnit_Framework_TestCase -{ - protected function setUp() - { - if (!class_exists('Assetic\\AssetManager')) { - $this->markTestSkipped('Assetic is not available.'); - } - - $this->kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel') - ->disableOriginalConstructor() - ->setMethods(array('registerRootDir', 'registerBundles', 'registerContainerConfiguration', 'getBundles')) - ->getMock(); - $this->loader = $this->getMockBuilder('Assetic\\Extension\\Twig\\FormulaLoader') - ->disableOriginalConstructor() - ->getMock(); - - $this->cacheWarmer = new TwigAssetsCacheWarmer($this->kernel, $this->loader); - - // cache dir - $this->cacheDir = sys_get_temp_dir(); - @unlink($this->cacheDir.'/twig_assets.php'); - } - - protected function tearDown() - { - @unlink($this->cacheDir.'/twig_assets.php'); - } - - public function testCacheWarmer() - { - $bundle = $this->getMock('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface'); - - $this->kernel->expects($this->once()) - ->method('getBundles') - ->will($this->returnValue(array('MyBundle' => $bundle))); - $bundle->expects($this->once()) - ->method('getPath') - ->will($this->returnValue(strtr(__DIR__.'/bundle', '\\', '/'))); - $this->loader->expects($this->at(0)) - ->method('load') - ->with('MyBundle:Parents/Children:child.html.twig') - ->will($this->returnValue(array('child' => array()))); - $this->loader->expects($this->at(1)) - ->method('load') - ->with('MyBundle:Parents:parent.html.twig') - ->will($this->returnValue(array('parent' => array()))); - $this->loader->expects($this->at(2)) - ->method('load') - ->with('MyBundle::grandparent.html.twig') - ->will($this->returnValue(array('grandparent' => array()))); - - $this->cacheWarmer->warmUp($this->cacheDir); - } -} diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/bundle/Resources/views/Parents/Children/child.html.twig b/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/bundle/Resources/views/Parents/Children/child.html.twig deleted file mode 100644 index c87fa99172151..0000000000000 --- a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/bundle/Resources/views/Parents/Children/child.html.twig +++ /dev/null @@ -1 +0,0 @@ -{# empty #} \ No newline at end of file diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/bundle/Resources/views/Parents/parent.html.twig b/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/bundle/Resources/views/Parents/parent.html.twig deleted file mode 100644 index c87fa99172151..0000000000000 --- a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/bundle/Resources/views/Parents/parent.html.twig +++ /dev/null @@ -1 +0,0 @@ -{# empty #} \ No newline at end of file diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/bundle/Resources/views/grandparent.html.twig b/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/bundle/Resources/views/grandparent.html.twig deleted file mode 100644 index c87fa99172151..0000000000000 --- a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/bundle/Resources/views/grandparent.html.twig +++ /dev/null @@ -1 +0,0 @@ -{# empty #} \ No newline at end of file diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php b/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php index 33668a0a7f377..4ad56670a20be 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php +++ b/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php @@ -43,6 +43,10 @@ protected function setUp() $this->markTestSkipped('Assetic is not available.'); } + if (false === @include 'PHP/CodeSniffer.php') { + $this->markTestSkipped('PHP_CodeSniffer is not installed.'); + } + $this->kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel') ->disableOriginalConstructor() ->getMock(); diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/Factory/AssetManagerTest.php b/src/Symfony/Bundle/AsseticBundle/Tests/Factory/AssetManagerTest.php deleted file mode 100644 index 3e959461ac6d4..0000000000000 --- a/src/Symfony/Bundle/AsseticBundle/Tests/Factory/AssetManagerTest.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Symfony\Bundle\AsseticBundle\Tests\Factory; - -use Symfony\Bundle\AsseticBundle\Factory\AssetManager; - -class AssetManagerTest extends \PHPUnit_Framework_TestCase -{ - protected function setUp() - { - if (!class_exists('Assetic\\AssetManager')) { - $this->markTestSkipped('Assetic is not available.'); - } - } - - public function testLoadFormulae() - { - $file = tempnam(sys_get_temp_dir(), 'assetic'); - file_put_contents($file, ' array());'); - - $factory = $this->getMockBuilder('Assetic\\Factory\\AssetFactory') - ->disableOriginalConstructor() - ->getMock(); - - $am = new AssetManager($factory); - $am->addCacheFile($file); - - $this->assertTrue($am->has('foo'), '->loadFormulae() loads formulae'); - - unlink($file); - } -} diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/FilterManagerTest.php b/src/Symfony/Bundle/AsseticBundle/Tests/FilterManagerTest.php index 08bddde3b9faf..385ae37588488 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/FilterManagerTest.php +++ b/src/Symfony/Bundle/AsseticBundle/Tests/FilterManagerTest.php @@ -46,19 +46,14 @@ public function testHas() $this->assertTrue($fm->has('foo'), '->has() returns true for lazily mapped filters'); } - public function testAll() + public function testGetNames() { $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $filter = $this->getMock('Assetic\\Filter\\FilterInterface'); - $container->expects($this->once()) - ->method('get') - ->with('assetic.filter.bar') - ->will($this->returnValue($filter)); - $fm = new FilterManager($container, array('foo' => 'assetic.filter.bar')); $fm->set('bar', $filter); - $all = $fm->all(); - $this->assertEquals(2, count($all), '->all() returns all lazy and normal filters'); + + $this->assertEquals(array('foo', 'bar'), $fm->getNames(), '->getNames() returns all lazy and normal filter names'); } } diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/FunctionalTest.php b/src/Symfony/Bundle/AsseticBundle/Tests/FunctionalTest.php index 0eb20a1f41395..f0e74818d7630 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/FunctionalTest.php +++ b/src/Symfony/Bundle/AsseticBundle/Tests/FunctionalTest.php @@ -44,11 +44,10 @@ public function testKernel($debug, $count) $kernel = new TestKernel('test', $debug); $kernel->boot(); $container = $kernel->getContainer(); - $container->get('cache_warmer')->warmUp($container->getParameter('kernel.cache_dir')); - $assets = $container->get('assetic.asset_manager')->all(); + $names = $container->get('assetic.asset_manager')->getNames(); - $this->assertEquals($count, count($assets)); + $this->assertEquals($count, count($names)); } /** @@ -59,7 +58,6 @@ public function testRoutes($debug, $count) $kernel = new TestKernel('test', $debug); $kernel->boot(); $container = $kernel->getContainer(); - $container->get('cache_warmer')->warmUp($container->getParameter('kernel.cache_dir')); $routes = $container->get('router')->getRouteCollection()->all(); @@ -80,7 +78,6 @@ public function testTwigRenderDebug() $container = $kernel->getContainer(); $container->enterScope('request'); $container->set('request', new Request()); - $container->get('cache_warmer')->warmUp($container->getParameter('kernel.cache_dir')); $content = $container->get('templating')->render('::layout.html.twig'); $crawler = new Crawler($content); @@ -98,7 +95,6 @@ public function testPhpRenderDebug() $container = $kernel->getContainer(); $container->enterScope('request'); $container->set('request', new Request()); - $container->get('cache_warmer')->warmUp($container->getParameter('kernel.cache_dir')); $content = $container->get('templating')->render('::layout.html.php'); $crawler = new Crawler($content); diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/Kernel/config/config.yml b/src/Symfony/Bundle/AsseticBundle/Tests/Kernel/config/config.yml index e54251f107c2a..3086cca89a8a4 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/Kernel/config/config.yml +++ b/src/Symfony/Bundle/AsseticBundle/Tests/Kernel/config/config.yml @@ -6,7 +6,7 @@ framework: secret: xxxxxxxxxx router: { resource: "%kernel.root_dir%/config/routing.yml" } validation: { enabled: true, annotations: true } - templating: { engines: ['twig', 'php'] } + templating: { engines: ['twig'] } session: default_locale: en lifetime: 3600 diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/DynamicNode.php b/src/Symfony/Bundle/AsseticBundle/Twig/DynamicNode.php index 2836118cb0f1a..6031f07e4c86b 100644 --- a/src/Symfony/Bundle/AsseticBundle/Twig/DynamicNode.php +++ b/src/Symfony/Bundle/AsseticBundle/Twig/DynamicNode.php @@ -11,14 +11,14 @@ namespace Symfony\Bundle\AsseticBundle\Twig; -use Assetic\Extension\Twig\Node; +use Assetic\Extension\Twig\AsseticNode; /** * The "dynamic" node uses a controller to render assets. * * @author Kris Wallsmith */ -class DynamicNode extends Node +class DynamicNode extends AsseticNode { /** * Renders the asset URL using Symfony's path() function. diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/DynamicTokenParser.php b/src/Symfony/Bundle/AsseticBundle/Twig/DynamicTokenParser.php index cfbc97889dcde..84619939e6229 100644 --- a/src/Symfony/Bundle/AsseticBundle/Twig/DynamicTokenParser.php +++ b/src/Symfony/Bundle/AsseticBundle/Twig/DynamicTokenParser.php @@ -11,14 +11,14 @@ namespace Symfony\Bundle\AsseticBundle\Twig; -use Assetic\Extension\Twig\TokenParser; +use Assetic\Extension\Twig\AsseticTokenParser; /** * Parses the {% assets %} tag. * * @author Kris Wallsmith */ -class DynamicTokenParser extends TokenParser +class DynamicTokenParser extends AsseticTokenParser { static protected function createNode(\Twig_NodeInterface $body, array $sourceUrls, $targetUrl, array $filterNames, $assetName, $debug = false, $lineno = 0, $tag = null) { diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/StaticNode.php b/src/Symfony/Bundle/AsseticBundle/Twig/StaticNode.php index 443dcf91b80e7..d71b3f4cde4a9 100644 --- a/src/Symfony/Bundle/AsseticBundle/Twig/StaticNode.php +++ b/src/Symfony/Bundle/AsseticBundle/Twig/StaticNode.php @@ -11,14 +11,14 @@ namespace Symfony\Bundle\AsseticBundle\Twig; -use Assetic\Extension\Twig\Node; +use Assetic\Extension\Twig\AsseticNode; /** * The "static" node references a file in the web directory. * * @author Kris Wallsmith */ -class StaticNode extends Node +class StaticNode extends AsseticNode { /** * Renders the asset URL using Symfony's asset() function. diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/StaticTokenParser.php b/src/Symfony/Bundle/AsseticBundle/Twig/StaticTokenParser.php index a5bada738c3ed..35f1ed43b2117 100644 --- a/src/Symfony/Bundle/AsseticBundle/Twig/StaticTokenParser.php +++ b/src/Symfony/Bundle/AsseticBundle/Twig/StaticTokenParser.php @@ -11,14 +11,14 @@ namespace Symfony\Bundle\AsseticBundle\Twig; -use Assetic\Extension\Twig\TokenParser; +use Assetic\Extension\Twig\AsseticTokenParser; /** * Parses the {% assets %} tag. * * @author Kris Wallsmith */ -class StaticTokenParser extends TokenParser +class StaticTokenParser extends AsseticTokenParser { static protected function createNode(\Twig_NodeInterface $body, array $sourceUrls, $targetUrl, array $filterNames, $assetName, $debug = false, $lineno = 0, $tag = null) {