moved Twig form templates to the Twig bridge

This commit is contained in:
Fabien Potencier 2011-06-07 16:32:42 +02:00
parent 1363068686
commit 89f544afb6
9 changed files with 25 additions and 46 deletions

View File

@ -9,6 +9,17 @@ timeline closely anyway.
beta4 to beta5 beta4 to beta5
-------------- --------------
* Default Twig form templates have been moved to the Twig bridge. Here is how
you can reference them now from a template or in a configuration setting:
Before:
`TwigBundle:Form:div_layout.html.twig`
After:
`div_layout.html.twig`
* All settings regarding the cache warmers have been removed. * All settings regarding the cache warmers have been removed.
* `Response::isRedirected()` has been merged with `Response::isRedirect()` * `Response::isRedirected()` has been merged with `Response::isRedirect()`

View File

@ -1,4 +1,4 @@
{% use "TwigBundle:Form:div_layout.html.twig" %} {% use "div_layout.html.twig" %}
{% block field_row %} {% block field_row %}
{% spaceless %} {% spaceless %}

View File

@ -62,11 +62,11 @@ class Configuration implements ConfigurationInterface
->children() ->children()
->arrayNode('resources') ->arrayNode('resources')
->addDefaultsIfNotSet() ->addDefaultsIfNotSet()
->defaultValue(array('TwigBundle:Form:div_layout.html.twig')) ->defaultValue(array('div_layout.html.twig'))
->validate() ->validate()
->always() ->always()
->then(function($v){ ->then(function($v){
return array_merge(array('TwigBundle:Form:div_layout.html.twig'), $v); return array_merge(array('div_layout.html.twig'), $v);
}) })
->end() ->end()
->prototype('scalar')->end() ->prototype('scalar')->end()

View File

@ -42,6 +42,7 @@ class TwigExtension extends Extension
$config = $processor->processConfiguration($configuration, $configs); $config = $processor->processConfiguration($configuration, $configs);
$container->setParameter('twig.form.resources', $config['form']['resources']); $container->setParameter('twig.form.resources', $config['form']['resources']);
$container->getDefinition('twig.loader')->addMethodCall('addPath', array(__DIR__.'/../../../Bridge/Twig/Resources/views/Form'));
if (!empty($config['globals'])) { if (!empty($config['globals'])) {
$def = $container->getDefinition('twig'); $def = $container->getDefinition('twig');

View File

@ -21,7 +21,7 @@ use Symfony\Component\Templating\TemplateReferenceInterface;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class FilesystemLoader implements \Twig_LoaderInterface class FilesystemLoader extends \Twig_Loader_Filesystem
{ {
protected $locator; protected $locator;
protected $parser; protected $parser;
@ -40,43 +40,6 @@ class FilesystemLoader implements \Twig_LoaderInterface
$this->cache = array(); $this->cache = array();
} }
/**
* Gets the source code of a template, given its name.
*
* @param mixed $name The template name or a TemplateReferenceInterface instance
*
* @return string The template source code
*/
public function getSource($name)
{
return file_get_contents($this->findTemplate($name));
}
/**
* Gets the cache key to use for the cache for a given template name.
*
* @param mixed $name The template name or a TemplateReferenceInterface instance
*
* @return string The cache key
*/
public function getCacheKey($name)
{
return $this->findTemplate($name);
}
/**
* Returns true if the template is still fresh.
*
* @param mixed $name The template name or a TemplateReferenceInterface instance
* @param timestamp $time The last modification time of the cached template
*
* @throws \Twig_Error_Loader if the template does not exist
*/
public function isFresh($name, $time)
{
return filemtime($this->findTemplate($name)) < $time;
}
/** /**
* Returns the path to the template file * Returns the path to the template file
* *
@ -86,7 +49,11 @@ class FilesystemLoader implements \Twig_LoaderInterface
*/ */
protected function findTemplate($name) protected function findTemplate($name)
{ {
$tpl = $this->parser->parse($name); try {
$tpl = $this->parser->parse($name);
} catch (\Exception $e) {
return parent::findTemplate($name);
}
if (isset($this->cache[$key = $tpl->getLogicalName()])) { if (isset($this->cache[$key = $tpl->getLogicalName()])) {
return $this->cache[$key]; return $this->cache[$key];

View File

@ -31,7 +31,7 @@ class TwigExtensionTest extends TestCase
$this->compileContainer($container); $this->compileContainer($container);
$this->assertEquals('Twig_Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file'); $this->assertEquals('Twig_Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file');
$this->assertContains('TwigBundle:Form:div_layout.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources'); $this->assertContains('div_layout.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources');
// Twig options // Twig options
$options = $container->getParameter('twig.options'); $options = $container->getParameter('twig.options');
@ -60,7 +60,7 @@ class TwigExtensionTest extends TestCase
// Form resources // Form resources
$resources = $container->getParameter('twig.form.resources'); $resources = $container->getParameter('twig.form.resources');
$this->assertContains('TwigBundle:Form:div_layout.html.twig', $resources, '->load() includes default template for form resources'); $this->assertContains('div_layout.html.twig', $resources, '->load() includes default template for form resources');
$this->assertContains('MyBundle::form.html.twig', $resources, '->load() merges new templates into form resources'); $this->assertContains('MyBundle::form.html.twig', $resources, '->load() merges new templates into form resources');
// Globals // Globals

View File

@ -32,7 +32,7 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
parent::setUp(); parent::setUp();
$loader = new StubFilesystemLoader(array( $loader = new StubFilesystemLoader(array(
__DIR__.'/../../../../../../src/Symfony/Bundle/TwigBundle/Resources/views/Form', __DIR__.'/../../../../../../src/Symfony/Bridge/Twig/Resources/views/Form',
__DIR__, __DIR__,
)); ));

View File

@ -32,7 +32,7 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
parent::setUp(); parent::setUp();
$loader = new StubFilesystemLoader(array( $loader = new StubFilesystemLoader(array(
__DIR__.'/../../../../../../src/Symfony/Bundle/TwigBundle/Resources/views/Form', __DIR__.'/../../../../../../src/Symfony/Bridge/Twig/Resources/views/Form',
__DIR__, __DIR__,
)); ));