From 424e8987093e9b90190a91d91cb39ed75895744d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Thu, 24 Feb 2011 07:47:45 +0100 Subject: [PATCH 1/4] moved twig's translation extension to Twig-extensions package --- autoload.php.dist | 1 + .../TwigBundle/Extension/TransExtension.php | 78 ------------ .../Bundle/TwigBundle/Node/TransNode.php | 117 ------------------ .../TwigBundle/Resources/config/twig.xml | 2 +- .../TokenParser/TransChoiceTokenParser.php | 80 ------------ .../TokenParser/TransTokenParser.php | 89 ------------- 6 files changed, 2 insertions(+), 365 deletions(-) delete mode 100644 src/Symfony/Bundle/TwigBundle/Extension/TransExtension.php delete mode 100644 src/Symfony/Bundle/TwigBundle/Node/TransNode.php delete mode 100644 src/Symfony/Bundle/TwigBundle/TokenParser/TransChoiceTokenParser.php delete mode 100644 src/Symfony/Bundle/TwigBundle/TokenParser/TransTokenParser.php diff --git a/autoload.php.dist b/autoload.php.dist index fea397bb8ad16..436b1acb84fc0 100644 --- a/autoload.php.dist +++ b/autoload.php.dist @@ -16,6 +16,7 @@ $loader->registerNamespaces(array( 'Doctrine' => __DIR__.'/vendor/doctrine/lib', 'Zend' => __DIR__.'/vendor/zend/library', 'Assetic' => __DIR__.'/vendor/assetic/src', + 'Twig\\Extension' => __DIR__.'/vendor/Twig-extensions/lib/src', )); $loader->registerPrefixes(array( 'Swift_' => __DIR__.'/vendor/swiftmailer/lib/classes', diff --git a/src/Symfony/Bundle/TwigBundle/Extension/TransExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/TransExtension.php deleted file mode 100644 index 4be8b7dce1e3a..0000000000000 --- a/src/Symfony/Bundle/TwigBundle/Extension/TransExtension.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Extension; - -use Symfony\Bundle\TwigBundle\TokenParser\TransTokenParser; -use Symfony\Bundle\TwigBundle\TokenParser\TransChoiceTokenParser; -use Symfony\Component\Translation\TranslatorInterface; - -/** - * - * @author Fabien Potencier - */ -class TransExtension extends \Twig_Extension -{ - protected $translator; - - public function __construct(TranslatorInterface $translator) - { - $this->translator = $translator; - } - - public function getTranslator() - { - return $this->translator; - } - - /** - * {@inheritdoc} - */ - public function getFilters() - { - return array( - 'trans' => new \Twig_Filter_Method($this, 'trans'), - ); - } - - /** - * Returns the token parser instance to add to the existing list. - * - * @return array An array of Twig_TokenParser instances - */ - public function getTokenParsers() - { - return array( - // {% trans "Symfony is great!" %} - new TransTokenParser(), - - // {% transchoice count %} - // {0} There is no apples|{1} There is one apple|]1,Inf] There is {{ count }} apples - // {% endtranschoice %} - new TransChoiceTokenParser(), - ); - } - - public function trans($message, array $arguments = array(), $domain = "messages") - { - return $this->translator->trans($message, $arguments, $domain); - } - - /** - * Returns the name of the extension. - * - * @return string The extension name - */ - public function getName() - { - return 'translator'; - } -} diff --git a/src/Symfony/Bundle/TwigBundle/Node/TransNode.php b/src/Symfony/Bundle/TwigBundle/Node/TransNode.php deleted file mode 100644 index 87d19674427cc..0000000000000 --- a/src/Symfony/Bundle/TwigBundle/Node/TransNode.php +++ /dev/null @@ -1,117 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Node; - -/** - * - * - * @author Fabien Potencier - */ -class TransNode extends \Twig_Node -{ - public function __construct(\Twig_NodeInterface $body, \Twig_NodeInterface $domain, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, $lineno, $tag = null) - { - parent::__construct(array('count' => $count, 'body' => $body, 'domain' => $domain, 'vars' => $vars), array(), $lineno, $tag); - } - - /** - * Compiles the node to PHP. - * - * @param \Twig_Compiler A Twig_Compiler instance - */ - public function compile(\Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - - $vars = $this->getNode('vars'); - $defaults = new \Twig_Node_Expression_Array(array(), -1); - if ($vars instanceof \Twig_Node_Expression_Array) { - $defaults = $this->getNode('vars'); - $vars = null; - } - - list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults); - - $method = null === $this->getNode('count') ? 'trans' : 'transChoice'; - - $compiler - ->write('echo $this->env->getExtension(\'translator\')->getTranslator()->'.$method.'(') - ->subcompile($msg) - ; - - $compiler->raw(', '); - - if (null !== $this->getNode('count')) { - $compiler - ->subcompile($this->getNode('count')) - ->raw(', ') - ; - } - - if (null !== $vars) { - $compiler->raw('array_merge('); - $this->compileDefaults($compiler, $defaults); - $compiler - ->raw(', ') - ->subcompile($this->getNode('vars')) - ->raw(')') - ; - } else { - $this->compileDefaults($compiler, $defaults); - } - - $compiler - ->raw(', ') - ->subcompile($this->getNode('domain')) - ->raw(");\n") - ; - } - - protected function compileDefaults(\Twig_Compiler $compiler, \Twig_Node_Expression_Array $defaults) - { - $compiler->raw('array('); - foreach ($defaults as $name => $default) { - $compiler - ->repr($name) - ->raw(' => ') - ->subcompile($default) - ->raw(', ') - ; - } - $compiler->raw(')'); - } - - protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars) - { - if ($body instanceof \Twig_Node_Expression_Constant) { - $msg = $body->getAttribute('value'); - } elseif ($body instanceof \Twig_Node_Text) { - $msg = $body->getAttribute('data'); - } else { - return array($body, $vars); - } - - $current = array(); - foreach ($vars as $name => $var) { - $current[$name] = true; - } - - preg_match_all('/\%([^\%]+)\%/', $msg, $matches); - foreach ($matches[1] as $var) { - if (!isset($current['%'.$var.'%'])) { - $vars->setNode('%'.$var.'%', new \Twig_Node_Expression_Name($var, $body->getLine())); - } - } - - return array(new \Twig_Node_Expression_Constant(trim($msg), $body->getLine()), $vars); - } -} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 8bff8774f3439..5a67ce2bd9194 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -37,7 +37,7 @@ - + diff --git a/src/Symfony/Bundle/TwigBundle/TokenParser/TransChoiceTokenParser.php b/src/Symfony/Bundle/TwigBundle/TokenParser/TransChoiceTokenParser.php deleted file mode 100644 index dce3d07034f62..0000000000000 --- a/src/Symfony/Bundle/TwigBundle/TokenParser/TransChoiceTokenParser.php +++ /dev/null @@ -1,80 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\TokenParser; - -use Symfony\Bundle\TwigBundle\Node\TransNode; - -/** - * - * - * @author Fabien Potencier - */ -class TransChoiceTokenParser extends TransTokenParser -{ - /** - * Parses a token and returns a node. - * - * @param \Twig_Token $token A Twig_Token instance - * - * @return \Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(\Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - - $vars = new \Twig_Node_Expression_Array(array(), $lineno); - - $count = $this->parser->getExpressionParser()->parseExpression(); - - $domain = new \Twig_Node_Expression_Constant('messages', $lineno); - - if ($stream->test('with')) { - // {% transchoice count with vars %} - $stream->next(); - $vars = $this->parser->getExpressionParser()->parseExpression(); - } - - if ($stream->test('from')) { - // {% transchoice count from "messages" %} - $stream->next(); - $domain = $this->parser->getExpressionParser()->parseExpression(); - } - - $stream->expect(\Twig_Token::BLOCK_END_TYPE); - - $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true); - - if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { - throw new \Twig_Error_Syntax('A message must be a simple text', -1); - } - - $stream->expect(\Twig_Token::BLOCK_END_TYPE); - - return new TransNode($body, $domain, $count, $vars, $lineno, $this->getTag()); - } - - public function decideTransChoiceFork($token) - { - return $token->test(array('endtranschoice')); - } - - /** - * Gets the tag name associated with this token parser. - * - * @param string The tag name - */ - public function getTag() - { - return 'transchoice'; - } -} diff --git a/src/Symfony/Bundle/TwigBundle/TokenParser/TransTokenParser.php b/src/Symfony/Bundle/TwigBundle/TokenParser/TransTokenParser.php deleted file mode 100644 index d4ef0e11b4d30..0000000000000 --- a/src/Symfony/Bundle/TwigBundle/TokenParser/TransTokenParser.php +++ /dev/null @@ -1,89 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\TokenParser; - -use Symfony\Bundle\TwigBundle\Node\TransNode; - -/** - * - * - * @author Fabien Potencier - */ -class TransTokenParser extends \Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param \Twig_Token $token A Twig_Token instance - * - * @return \Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(\Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - - $body = null; - $vars = new \Twig_Node_Expression_Array(array(), $lineno); - $domain = new \Twig_Node_Expression_Constant('messages', $lineno); - if (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { - if (!$stream->test('from') && !$stream->test('with')) { - // {% trans "message" %} - // {% trans message %} - $body = $this->parser->getExpressionParser()->parseExpression(); - } - - if ($stream->test('with')) { - // {% trans "message" with vars %} - $stream->next(); - $vars = $this->parser->getExpressionParser()->parseExpression(); - } - - if ($stream->test('from')) { - // {% trans "message" from "messages" %} - $stream->next(); - $domain = $this->parser->getExpressionParser()->parseExpression(); - } elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { - throw new \Twig_Error_Syntax(sprintf('Unexpected token. Twig was looking for the "from" keyword line %s)', $lineno), -1); - } - } - - if (null === $body) { - // {% trans %}message{% endtrans %} - $stream->expect(\Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'decideTransFork'), true); - } - - if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { - throw new \Twig_Error_Syntax('A message must be a simple text', -1); - } - - $stream->expect(\Twig_Token::BLOCK_END_TYPE); - - return new TransNode($body, $domain, null, $vars, $lineno, $this->getTag()); - } - - public function decideTransFork($token) - { - return $token->test(array('endtrans')); - } - - /** - * Gets the tag name associated with this token parser. - * - * @param string The tag name - */ - public function getTag() - { - return 'trans'; - } -} From 8091038f8490d8789d165da0b9a0afcf1f45e1a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Thu, 24 Feb 2011 08:29:16 +0100 Subject: [PATCH 2/4] moved Twig\Extension namespace to TwigX --- autoload.php.dist | 2 +- src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload.php.dist b/autoload.php.dist index 436b1acb84fc0..f7fb18f6613f5 100644 --- a/autoload.php.dist +++ b/autoload.php.dist @@ -16,7 +16,7 @@ $loader->registerNamespaces(array( 'Doctrine' => __DIR__.'/vendor/doctrine/lib', 'Zend' => __DIR__.'/vendor/zend/library', 'Assetic' => __DIR__.'/vendor/assetic/src', - 'Twig\\Extension' => __DIR__.'/vendor/Twig-extensions/lib/src', + 'TwigX' => __DIR__.'/vendor/Twig-extensions/lib/src', )); $loader->registerPrefixes(array( 'Swift_' => __DIR__.'/vendor/swiftmailer/lib/classes', diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 5a67ce2bd9194..0d93c0d03c1f5 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -37,7 +37,7 @@ - + From e665b83b3a6e51008b4de630fe3deaa358ecdd5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Fri, 25 Feb 2011 07:52:11 +0100 Subject: [PATCH 3/4] moved TwigX extensions path & namespace --- autoload.php.dist | 2 +- src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload.php.dist b/autoload.php.dist index f7fb18f6613f5..1872fabf328df 100644 --- a/autoload.php.dist +++ b/autoload.php.dist @@ -16,7 +16,7 @@ $loader->registerNamespaces(array( 'Doctrine' => __DIR__.'/vendor/doctrine/lib', 'Zend' => __DIR__.'/vendor/zend/library', 'Assetic' => __DIR__.'/vendor/assetic/src', - 'TwigX' => __DIR__.'/vendor/Twig-extensions/lib/src', + 'TwigX' => __DIR__.'/vendor/Twig-extensions/src', )); $loader->registerPrefixes(array( 'Swift_' => __DIR__.'/vendor/swiftmailer/lib/classes', diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 0d93c0d03c1f5..488565e3831b8 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -37,7 +37,7 @@ - + From f9a60cd8a1e3e70b4292afe9a3557a09661285e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Fri, 25 Feb 2011 08:01:23 +0100 Subject: [PATCH 4/4] moved Twig's form extension to Twig-extension package --- .../TwigBundle/Extension/FormExtension.php | 300 ------------------ .../Bundle/TwigBundle/Node/FormThemeNode.php | 49 --- .../TwigBundle/Resources/config/twig.xml | 2 +- .../TokenParser/FormThemeTokenParser.php | 55 ---- 4 files changed, 1 insertion(+), 405 deletions(-) delete mode 100644 src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php delete mode 100644 src/Symfony/Bundle/TwigBundle/Node/FormThemeNode.php delete mode 100644 src/Symfony/Bundle/TwigBundle/TokenParser/FormThemeTokenParser.php diff --git a/src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php deleted file mode 100644 index 4f96e842111bf..0000000000000 --- a/src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php +++ /dev/null @@ -1,300 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Extension; - -use Symfony\Component\Form\Form; -use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FieldInterface; -use Symfony\Component\Form\CollectionField; -use Symfony\Component\Form\HybridField; -use Symfony\Bundle\TwigBundle\TokenParser\FormThemeTokenParser; - -/** - * FormExtension extends Twig with form capabilities. - * - * @author Fabien Potencier - * @author Bernhard Schussek - */ -class FormExtension extends \Twig_Extension -{ - protected $resources; - protected $templates; - protected $environment; - protected $themes; - - public function __construct(array $resources = array()) - { - $this->themes = new \SplObjectStorage(); - $this->resources = $resources; - } - - /** - * {@inheritdoc} - */ - public function initRuntime(\Twig_Environment $environment) - { - $this->environment = $environment; - } - - /** - * Sets a theme for a given field. - * - * @param FieldInterface $field A FieldInterface instance - * @param array $resources An array of resources - */ - public function setTheme(FieldInterface $field, array $resources) - { - $this->themes->attach($field, $resources); - } - - /** - * Returns the token parser instance to add to the existing list. - * - * @return array An array of Twig_TokenParser instances - */ - public function getTokenParsers() - { - return array( - // {% form_theme form "SomeBungle::widgets.twig" %} - new FormThemeTokenParser(), - ); - } - - public function getFunctions() - { - return array( - 'form_enctype' => new \Twig_Function_Method($this, 'renderEnctype', array('is_safe' => array('html'))), - 'form_field' => new \Twig_Function_Method($this, 'renderField', array('is_safe' => array('html'))), - 'form_hidden' => new \Twig_Function_Method($this, 'renderHidden', array('is_safe' => array('html'))), - 'form_errors' => new \Twig_Function_Method($this, 'renderErrors', array('is_safe' => array('html'))), - 'form_label' => new \Twig_Function_Method($this, 'renderLabel', array('is_safe' => array('html'))), - 'form_data' => new \Twig_Function_Method($this, 'renderData', array('is_safe' => array('html'))), - 'form_row' => new \Twig_Function_Method($this, 'renderRow', array('is_safe' => array('html'))), - ); - } - - /** - * Renders the HTML enctype in the form tag, if necessary - * - * Example usage in Twig templates: - * - *
- * - * @param Form $form The form for which to render the encoding type - */ - public function renderEnctype(Form $form) - { - return $form->isMultipart() ? 'enctype="multipart/form-data"' : ''; - } - - /** - * Renders a field row. - * - * @param FieldInterface $field The field to render as a row - */ - public function renderRow(FieldInterface $field) - { - return $this->render($field, 'field_row', array( - 'child' => $field, - )); - } - - /** - * Renders the HTML for an individual form field - * - * Example usage in Twig: - * - * {{ form_field(field) }} - * - * You can pass attributes element during the call: - * - * {{ form_field(field, {'class': 'foo'}) }} - * - * Some fields also accept additional variables as parameters: - * - * {{ form_field(field, {}, {'separator': '+++++'}) }} - * - * @param FieldInterface $field The field to render - * @param array $attributes HTML attributes passed to the template - * @param array $parameters Additional variables passed to the template - * @param array|string $resources A resource or array of resources - */ - public function renderField(FieldInterface $field, array $attributes = array(), array $parameters = array(), $resources = null) - { - if (null !== $resources && !is_array($resources)) { - $resources = array($resources); - } - - return $this->render($field, 'field', array( - 'field' => $field, - 'attr' => $attributes, - 'params' => $parameters, - ), $resources); - } - - /** - * Renders all hidden fields of the given field group - * - * @param FormInterface $group The field group - * @param array $params Additional variables passed to the - * template - */ - public function renderHidden(FormInterface $group, array $parameters = array()) - { - return $this->render($group, 'hidden', array( - 'field' => $group, - 'params' => $parameters, - )); - } - - /** - * Renders the errors of the given field - * - * @param FieldInterface $field The field to render the errors for - * @param array $params Additional variables passed to the template - */ - public function renderErrors(FieldInterface $field, array $parameters = array()) - { - return $this->render($field, 'errors', array( - 'field' => $field, - 'params' => $parameters, - )); - } - - /** - * Renders the label of the given field - * - * @param FieldInterface $field The field to render the label for - * @param array $params Additional variables passed to the template - */ - public function renderLabel(FieldInterface $field, $label = null, array $parameters = array()) - { - return $this->render($field, 'label', array( - 'field' => $field, - 'params' => $parameters, - 'label' => null !== $label ? $label : ucfirst(strtolower(str_replace('_', ' ', $field->getKey()))), - )); - } - - /** - * Renders the widget data of the given field - * - * @param FieldInterface $field The field to render the data for - */ - public function renderData(FieldInterface $field) - { - return $field->getData(); - } - - protected function render(FieldInterface $field, $name, array $arguments, array $resources = null) - { - if ('field' === $name) { - list($name, $template) = $this->getWidget($field, $resources); - } else { - $template = $this->getTemplate($field, $name); - } - - return $template->renderBlock($name, $arguments); - } - - /** - * @param FieldInterface $field The field to get the widget for - * @param array $resources An array of template resources - * @return array - */ - protected function getWidget(FieldInterface $field, array $resources = null) - { - $class = get_class($field); - $templates = $this->getTemplates($field, $resources); - - // find a template for the given class or one of its parents - do { - $parts = explode('\\', $class); - $c = array_pop($parts); - - // convert the base class name (e.g. TextareaField) to underscores (e.g. textarea_field) - $underscore = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($c, '_', '.'))); - - if (isset($templates[$underscore])) { - return array($underscore, $templates[$underscore]); - } - } while (false !== $class = get_parent_class($class)); - - throw new \RuntimeException(sprintf('Unable to render the "%s" field.', $field->getKey())); - } - - protected function getTemplate(FieldInterface $field, $name, array $resources = null) - { - $templates = $this->getTemplates($field, $resources); - - return $templates[$name]; - } - - protected function getTemplates(FieldInterface $field, array $resources = null) - { - // templates are looked for in the following resources: - // * resources provided directly into the function call - // * resources from the themes (and its parents) - // * default resources - - // defaults - $all = $this->resources; - - // themes - $parent = $field; - do { - if (isset($this->themes[$parent])) { - $all = array_merge($all, $this->themes[$parent]); - } - } while ($parent = $parent->getParent()); - - // local - $all = array_merge($all, null !== $resources ? (array) $resources : array()); - - $templates = array(); - foreach ($all as $resource) { - if (!$resource instanceof \Twig_Template) { - $resource = $this->environment->loadTemplate($resource); - } - - $blocks = array(); - foreach ($this->getBlockNames($resource) as $name) { - $blocks[$name] = $resource; - } - - $templates = array_replace($templates, $blocks); - } - - return $templates; - } - - protected function getBlockNames($resource) - { - $names = $resource->getBlockNames(); - $parent = $resource; - while (false !== $parent = $parent->getParent(array())) { - $names = array_merge($names, $parent->getBlockNames()); - } - - return array_unique($names); - } - - /** - * Returns the name of the extension. - * - * @return string The extension name - */ - public function getName() - { - return 'form'; - } -} diff --git a/src/Symfony/Bundle/TwigBundle/Node/FormThemeNode.php b/src/Symfony/Bundle/TwigBundle/Node/FormThemeNode.php deleted file mode 100644 index edd31cd6a9a8d..0000000000000 --- a/src/Symfony/Bundle/TwigBundle/Node/FormThemeNode.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Node; - -/** - * - * - * @author Fabien Potencier - */ -class FormThemeNode extends \Twig_Node -{ - public function __construct(\Twig_NodeInterface $form, \Twig_NodeInterface $resources, $lineno, $tag = null) - { - parent::__construct(array('form' => $form, 'resources' => $resources), array(), $lineno, $tag); - } - - /** - * Compiles the node to PHP. - * - * @param \Twig_Compiler A Twig_Compiler instance - */ - public function compile(\Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('echo $this->env->getExtension(\'form\')->setTheme(') - ->subcompile($this->getNode('form')) - ->raw(', array(') - ; - - foreach ($this->getNode('resources') as $resource) { - $compiler - ->subcompile($resource) - ->raw(', ') - ; - } - - $compiler->raw('));'); - } -} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 488565e3831b8..cf0a88430d492 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -47,7 +47,7 @@ - + %twig.form.resources% diff --git a/src/Symfony/Bundle/TwigBundle/TokenParser/FormThemeTokenParser.php b/src/Symfony/Bundle/TwigBundle/TokenParser/FormThemeTokenParser.php deleted file mode 100644 index b9bb3980cdbad..0000000000000 --- a/src/Symfony/Bundle/TwigBundle/TokenParser/FormThemeTokenParser.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\TokenParser; - -use Symfony\Bundle\TwigBundle\Node\FormThemeNode; - -/** - * - * - * @author Fabien Potencier - */ -class FormThemeTokenParser extends \Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param \Twig_Token $token A Twig_Token instance - * - * @return \Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(\Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - - $form = $this->parser->getExpressionParser()->parseExpression(); - $resources = array(); - do { - $resources[] = $this->parser->getExpressionParser()->parseExpression(); - } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)); - - $stream->expect(\Twig_Token::BLOCK_END_TYPE); - - return new FormThemeNode($form, new \Twig_Node($resources), $lineno, $this->getTag()); - } - - /** - * Gets the tag name associated with this token parser. - * - * @param string The tag name - */ - public function getTag() - { - return 'form_theme'; - } -}