From 4f5b44bd3bd490309eb2ba7b44df4769816ba729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 19:26:54 +0200 Subject: twig implementation --- inc/3rdparty/Twig/Extensions/Autoloader.php | 45 ------- inc/3rdparty/Twig/Extensions/Extension/Debug.php | 34 ------ inc/3rdparty/Twig/Extensions/Extension/I18n.php | 44 ------- inc/3rdparty/Twig/Extensions/Extension/Intl.php | 66 ---------- inc/3rdparty/Twig/Extensions/Extension/Text.php | 109 ----------------- inc/3rdparty/Twig/Extensions/Gettext/Extractor.php | 95 --------------- .../Twig/Extensions/Gettext/Loader/Filesystem.php | 58 --------- .../Gettext/Routing/Generator/UrlGenerator.php | 39 ------ .../Twig/Extensions/Gettext/Test/ExtractorTest.php | 123 ------------------- .../Gettext/Test/Fixtures/twig/empty.twig | 1 - .../Gettext/Test/Fixtures/twig/plural.twig | 5 - .../Gettext/Test/Fixtures/twig/singular.twig | 9 -- inc/3rdparty/Twig/Extensions/Grammar.php | 30 ----- inc/3rdparty/Twig/Extensions/Grammar/Arguments.php | 22 ---- inc/3rdparty/Twig/Extensions/Grammar/Array.php | 22 ---- inc/3rdparty/Twig/Extensions/Grammar/Body.php | 39 ------ inc/3rdparty/Twig/Extensions/Grammar/Boolean.php | 24 ---- inc/3rdparty/Twig/Extensions/Grammar/Constant.php | 37 ------ .../Twig/Extensions/Grammar/Expression.php | 22 ---- inc/3rdparty/Twig/Extensions/Grammar/Hash.php | 22 ---- inc/3rdparty/Twig/Extensions/Grammar/Number.php | 24 ---- inc/3rdparty/Twig/Extensions/Grammar/Optional.php | 69 ----------- inc/3rdparty/Twig/Extensions/Grammar/Switch.php | 24 ---- inc/3rdparty/Twig/Extensions/Grammar/Tag.php | 56 --------- inc/3rdparty/Twig/Extensions/GrammarInterface.php | 18 --- inc/3rdparty/Twig/Extensions/Node/Debug.php | 69 ----------- inc/3rdparty/Twig/Extensions/Node/Trans.php | 133 --------------------- inc/3rdparty/Twig/Extensions/SimpleTokenParser.php | 132 -------------------- inc/3rdparty/Twig/Extensions/TokenParser/Debug.php | 42 ------- inc/3rdparty/Twig/Extensions/TokenParser/Trans.php | 80 ------------- 30 files changed, 1493 deletions(-) delete mode 100644 inc/3rdparty/Twig/Extensions/Autoloader.php delete mode 100644 inc/3rdparty/Twig/Extensions/Extension/Debug.php delete mode 100644 inc/3rdparty/Twig/Extensions/Extension/I18n.php delete mode 100644 inc/3rdparty/Twig/Extensions/Extension/Intl.php delete mode 100644 inc/3rdparty/Twig/Extensions/Extension/Text.php delete mode 100644 inc/3rdparty/Twig/Extensions/Gettext/Extractor.php delete mode 100644 inc/3rdparty/Twig/Extensions/Gettext/Loader/Filesystem.php delete mode 100644 inc/3rdparty/Twig/Extensions/Gettext/Routing/Generator/UrlGenerator.php delete mode 100644 inc/3rdparty/Twig/Extensions/Gettext/Test/ExtractorTest.php delete mode 100644 inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/empty.twig delete mode 100644 inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/plural.twig delete mode 100644 inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/singular.twig delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar.php delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar/Arguments.php delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar/Array.php delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar/Body.php delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar/Boolean.php delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar/Constant.php delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar/Expression.php delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar/Hash.php delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar/Number.php delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar/Optional.php delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar/Switch.php delete mode 100644 inc/3rdparty/Twig/Extensions/Grammar/Tag.php delete mode 100644 inc/3rdparty/Twig/Extensions/GrammarInterface.php delete mode 100644 inc/3rdparty/Twig/Extensions/Node/Debug.php delete mode 100644 inc/3rdparty/Twig/Extensions/Node/Trans.php delete mode 100644 inc/3rdparty/Twig/Extensions/SimpleTokenParser.php delete mode 100644 inc/3rdparty/Twig/Extensions/TokenParser/Debug.php delete mode 100644 inc/3rdparty/Twig/Extensions/TokenParser/Trans.php (limited to 'inc/3rdparty/Twig/Extensions') diff --git a/inc/3rdparty/Twig/Extensions/Autoloader.php b/inc/3rdparty/Twig/Extensions/Autoloader.php deleted file mode 100644 index f23cced6..00000000 --- a/inc/3rdparty/Twig/Extensions/Autoloader.php +++ /dev/null @@ -1,45 +0,0 @@ - - */ -class Twig_Extensions_Autoloader -{ - /** - * Registers Twig_Extensions_Autoloader as an SPL autoloader. - */ - static public function register() - { - spl_autoload_register(array(new self, 'autoload')); - } - - /** - * Handles autoloading of classes. - * - * @param string $class A class name. - * - * @return boolean Returns true if the class has been loaded - */ - static public function autoload($class) - { - if (0 !== strpos($class, 'Twig_Extensions')) { - return; - } - - if (file_exists($file = dirname(__FILE__).'/../../'.str_replace('_', '/', $class).'.php')) { - require $file; - } - } -} diff --git a/inc/3rdparty/Twig/Extensions/Extension/Debug.php b/inc/3rdparty/Twig/Extensions/Extension/Debug.php deleted file mode 100644 index 8974ce20..00000000 --- a/inc/3rdparty/Twig/Extensions/Extension/Debug.php +++ /dev/null @@ -1,34 +0,0 @@ - new Twig_Filter_Function('gettext'), - ); - } - - /** - * Returns the name of the extension. - * - * @return string The extension name - */ - public function getName() - { - return 'i18n'; - } -} diff --git a/inc/3rdparty/Twig/Extensions/Extension/Intl.php b/inc/3rdparty/Twig/Extensions/Extension/Intl.php deleted file mode 100644 index 40f7fc20..00000000 --- a/inc/3rdparty/Twig/Extensions/Extension/Intl.php +++ /dev/null @@ -1,66 +0,0 @@ - new Twig_Filter_Function('twig_localized_date_filter', array('needs_environment' => true)), - ); - } - - /** - * Returns the name of the extension. - * - * @return string The extension name - */ - public function getName() - { - return 'intl'; - } -} - -function twig_localized_date_filter(Twig_Environment $env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null) -{ - $date = twig_date_converter($env, $date, $timezone); - - $formatValues = array( - 'none' => IntlDateFormatter::NONE, - 'short' => IntlDateFormatter::SHORT, - 'medium' => IntlDateFormatter::MEDIUM, - 'long' => IntlDateFormatter::LONG, - 'full' => IntlDateFormatter::FULL, - ); - - $formatter = IntlDateFormatter::create( - $locale !== null ? $locale : Locale::getDefault(), - $formatValues[$dateFormat], - $formatValues[$timeFormat], - $date->getTimezone()->getName(), - IntlDateFormatter::GREGORIAN, - $format - ); - - return $formatter->format($date->getTimestamp()); -} diff --git a/inc/3rdparty/Twig/Extensions/Extension/Text.php b/inc/3rdparty/Twig/Extensions/Extension/Text.php deleted file mode 100644 index 0a3dc35e..00000000 --- a/inc/3rdparty/Twig/Extensions/Extension/Text.php +++ /dev/null @@ -1,109 +0,0 @@ - - * @package Twig - * @subpackage Twig-extensions - */ -class Twig_Extensions_Extension_Text extends Twig_Extension -{ - /** - * Returns a list of filters. - * - * @return array - */ - public function getFilters() - { - $filters = array( - 'truncate' => new Twig_Filter_Function('twig_truncate_filter', array('needs_environment' => true)), - 'wordwrap' => new Twig_Filter_Function('twig_wordwrap_filter', array('needs_environment' => true)), - ); - - if (version_compare(Twig_Environment::VERSION, '1.5.0-DEV', '<')) { - $filters['nl2br'] = new Twig_Filter_Function('twig_nl2br_filter', array('pre_escape' => 'html', 'is_safe' => array('html'))); - } - - return $filters; - } - - /** - * Name of this extension - * - * @return string - */ - public function getName() - { - return 'Text'; - } -} - -function twig_nl2br_filter($value, $sep = '
') -{ - return str_replace("\n", $sep."\n", $value); -} - -if (function_exists('mb_get_info')) { - function twig_truncate_filter(Twig_Environment $env, $value, $length = 30, $preserve = false, $separator = '...') - { - if (mb_strlen($value, $env->getCharset()) > $length) { - if ($preserve) { - if (false !== ($breakpoint = mb_strpos($value, ' ', $length, $env->getCharset()))) { - $length = $breakpoint; - } - } - - return rtrim(mb_substr($value, 0, $length, $env->getCharset())) . $separator; - } - - return $value; - } - - function twig_wordwrap_filter(Twig_Environment $env, $value, $length = 80, $separator = "\n", $preserve = false) - { - $sentences = array(); - - $previous = mb_regex_encoding(); - mb_regex_encoding($env->getCharset()); - - $pieces = mb_split($separator, $value); - mb_regex_encoding($previous); - - foreach ($pieces as $piece) { - while(!$preserve && mb_strlen($piece, $env->getCharset()) > $length) { - $sentences[] = mb_substr($piece, 0, $length, $env->getCharset()); - $piece = mb_substr($piece, $length, 2048, $env->getCharset()); - } - - $sentences[] = $piece; - } - - return implode($separator, $sentences); - } -} else { - function twig_truncate_filter(Twig_Environment $env, $value, $length = 30, $preserve = false, $separator = '...') - { - if (strlen($value) > $length) { - if ($preserve) { - if (false !== ($breakpoint = strpos($value, ' ', $length))) { - $length = $breakpoint; - } - } - - return rtrim(substr($value, 0, $length)) . $separator; - } - - return $value; - } - - function twig_wordwrap_filter(Twig_Environment $env, $value, $length = 80, $separator = "\n", $preserve = false) - { - return wordwrap($value, $length, $separator, !$preserve); - } -} \ No newline at end of file diff --git a/inc/3rdparty/Twig/Extensions/Gettext/Extractor.php b/inc/3rdparty/Twig/Extensions/Gettext/Extractor.php deleted file mode 100644 index e7fa1af2..00000000 --- a/inc/3rdparty/Twig/Extensions/Gettext/Extractor.php +++ /dev/null @@ -1,95 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Twig\Gettext; - -use Symfony\Component\Filesystem\Filesystem; - -/** - * Extracts translations from twig templates. - * - * @author Саша Стаменковић - */ -class Extractor -{ - /** - * @var \Twig_Environment - */ - protected $environment; - - /** - * Template cached file names. - * - * @var string[] - */ - protected $templates; - - /** - * Gettext parameters. - * - * @var string[] - */ - protected $parameters; - - public function __construct(\Twig_Environment $environment) - { - $this->environment = $environment; - $this->reset(); - } - - protected function reset() - { - $this->templates = array(); - $this->parameters = array(); - } - - public function addTemplate($path) - { - $this->environment->loadTemplate($path); - $this->templates[] = $this->environment->getCacheFilename($path); - } - - public function addGettextParameter($parameter) - { - $this->parameters[] = $parameter; - } - - public function setGettextParameters(array $parameters) - { - $this->parameters = $parameters; - } - - public function extract() - { - $command = 'xgettext'; - $command .= ' '.join(' ', $this->parameters); - $command .= ' '.join(' ', $this->templates); - - $error = 0; - $output = system($command, $error); - if (0 !== $error) { - throw new \RuntimeException(sprintf( - 'Gettext command "%s" failed with error code %s and output: %s', - $command, - $error, - $output - )); - } - - $this->reset(); - } - - public function __destruct() - { - $filesystem = new Filesystem(); - $filesystem->remove($this->environment->getCache()); - } -} diff --git a/inc/3rdparty/Twig/Extensions/Gettext/Loader/Filesystem.php b/inc/3rdparty/Twig/Extensions/Gettext/Loader/Filesystem.php deleted file mode 100644 index b011b032..00000000 --- a/inc/3rdparty/Twig/Extensions/Gettext/Loader/Filesystem.php +++ /dev/null @@ -1,58 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Twig\Gettext\Loader; - -/** - * Loads template from the filesystem. - * - * @author Саша Стаменковић - */ -class Filesystem extends \Twig_Loader_Filesystem -{ - /** - * Hacked find template to allow loading templates by absolute path. - * - * @param string $name template name or absolute path - */ - protected function findTemplate($name) - { - // normalize name - $name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')); - - if (isset($this->cache[$name])) { - return $this->cache[$name]; - } - - $this->validateName($name); - - $namespace = '__main__'; - if (isset($name[0]) && '@' == $name[0]) { - if (false === $pos = strpos($name, '/')) { - throw new \InvalidArgumentException(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); - } - - $namespace = substr($name, 1, $pos - 1); - - $name = substr($name, $pos + 1); - } - - if (!isset($this->paths[$namespace])) { - throw new \Twig_Error_Loader(sprintf('There are no registered paths for namespace "%s".', $namespace)); - } - - if (is_file($name)) { - return $this->cache[$name] = $name; - } - - return __DIR__.'/../Test/Fixtures/twig/empty.twig'; - } -} diff --git a/inc/3rdparty/Twig/Extensions/Gettext/Routing/Generator/UrlGenerator.php b/inc/3rdparty/Twig/Extensions/Gettext/Routing/Generator/UrlGenerator.php deleted file mode 100644 index 9e3431bd..00000000 --- a/inc/3rdparty/Twig/Extensions/Gettext/Routing/Generator/UrlGenerator.php +++ /dev/null @@ -1,39 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Twig\Gettext\Routing\Generator; - -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -use Symfony\Component\Routing\RequestContext; - -/** - * Dummy url generator. - * - * @author Саша Стаменковић - */ -class UrlGenerator implements UrlGeneratorInterface -{ - protected $context; - - public function generate($name, $parameters = array(), $absolute = false) - { - } - - public function getContext() - { - return $this->context; - } - - public function setContext(RequestContext $context) - { - $this->context = $context; - } -} diff --git a/inc/3rdparty/Twig/Extensions/Gettext/Test/ExtractorTest.php b/inc/3rdparty/Twig/Extensions/Gettext/Test/ExtractorTest.php deleted file mode 100644 index d467835f..00000000 --- a/inc/3rdparty/Twig/Extensions/Gettext/Test/ExtractorTest.php +++ /dev/null @@ -1,123 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Twig\Gettext\Test; - -use Twig\Gettext\Extractor; -use Twig\Gettext\Loader\Filesystem; -use Symfony\Component\Translation\Loader\PoFileLoader; - -/** - * @author Саша Стаменковић - */ -class ExtractorTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Twig_Environment - */ - protected $twig; - - /** - * @var PoFileLoader - */ - protected $loader; - - protected function setUp() - { - $this->twig = new \Twig_Environment(new Filesystem('/'), array( - 'cache' => '/tmp/cache/'.uniqid(), - 'auto_reload' => true - )); - $this->twig->addExtension(new \Twig_Extensions_Extension_I18n()); - - $this->loader = new PoFileLoader(); - } - - /** - * @dataProvider testExtractDataProvider - */ - public function testExtract(array $templates, array $parameters, array $messages) - { - $extractor = new Extractor($this->twig); - - foreach ($templates as $template) { - $extractor->addTemplate($template); - } - foreach ($parameters as $parameter) { - $extractor->addGettextParameter($parameter); - } - - $extractor->extract(); - - $catalog = $this->loader->load($this->getPotFile(), null); - - foreach ($messages as $message) { - $this->assertTrue( - $catalog->has($message), - sprintf('Message "%s" not found in catalog.', $message) - ); - } - } - - public function testExtractDataProvider() - { - return array( - array( - array( - __DIR__.'/Fixtures/twig/singular.twig', - __DIR__.'/Fixtures/twig/plural.twig', - ), - $this->getGettextParameters(), - array( - 'Hello %name%!', - 'Hello World!', - 'Hey %name%, I have one apple.', - 'Hey %name%, I have %count% apples.', - ), - ), - ); - } - - public function testExtractNoTranslations() - { - $extractor = new Extractor($this->twig); - - $extractor->addTemplate(__DIR__.'/Fixtures/twig/empty.twig'); - $extractor->setGettextParameters($this->getGettextParameters()); - - $extractor->extract(); - - $catalog = $this->loader->load($this->getPotFile(), null); - - $this->assertEmpty($catalog->all('messages')); - } - - private function getPotFile() - { - return __DIR__.'/Fixtures/messages.pot'; - } - - private function getGettextParameters() - { - return array( - '--force-po', - '-o', - $this->getPotFile(), - ); - } - - protected function tearDown() - { - if (file_exists($this->getPotFile())) { - unlink($this->getPotFile()); - } - } -} diff --git a/inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/empty.twig b/inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/empty.twig deleted file mode 100644 index 05f0d26a..00000000 --- a/inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/empty.twig +++ /dev/null @@ -1 +0,0 @@ -Nothing to translate here. diff --git a/inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/plural.twig b/inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/plural.twig deleted file mode 100644 index f9754ff4..00000000 --- a/inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/plural.twig +++ /dev/null @@ -1,5 +0,0 @@ -{% trans %} - Hey {{ name }}, I have one apple. -{% plural apple_count %} - Hey {{ name }}, I have {{ count }} apples. -{% endtrans %} diff --git a/inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/singular.twig b/inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/singular.twig deleted file mode 100644 index d757cf90..00000000 --- a/inc/3rdparty/Twig/Extensions/Gettext/Test/Fixtures/twig/singular.twig +++ /dev/null @@ -1,9 +0,0 @@ -{% trans "Hello World!" %} - -{% trans %} - Hello World! -{% endtrans %} - -{% trans %} - Hello {{ name }}! -{% endtrans %} diff --git a/inc/3rdparty/Twig/Extensions/Grammar.php b/inc/3rdparty/Twig/Extensions/Grammar.php deleted file mode 100644 index 4d031b19..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar.php +++ /dev/null @@ -1,30 +0,0 @@ -name = $name; - } - - public function setParser(Twig_ParserInterface $parser) - { - $this->parser = $parser; - } - - public function getName() - { - return $this->name; - } -} diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Arguments.php b/inc/3rdparty/Twig/Extensions/Grammar/Arguments.php deleted file mode 100644 index 158c05ac..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar/Arguments.php +++ /dev/null @@ -1,22 +0,0 @@ -', $this->name); - } - - public function parse(Twig_Token $token) - { - return $this->parser->getExpressionParser()->parseArguments(); - } -} diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Array.php b/inc/3rdparty/Twig/Extensions/Grammar/Array.php deleted file mode 100644 index 34aece0f..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar/Array.php +++ /dev/null @@ -1,22 +0,0 @@ -', $this->name); - } - - public function parse(Twig_Token $token) - { - return $this->parser->getExpressionParser()->parseArrayExpression(); - } -} diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Body.php b/inc/3rdparty/Twig/Extensions/Grammar/Body.php deleted file mode 100644 index 540cfc75..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar/Body.php +++ /dev/null @@ -1,39 +0,0 @@ -end = null === $end ? 'end'.$name : $end; - } - - public function __toString() - { - return sprintf('<%s:body>', $this->name); - } - - public function parse(Twig_Token $token) - { - $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - return $this->parser->subparse(array($this, 'decideBlockEnd'), true); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test($this->end); - } -} diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Boolean.php b/inc/3rdparty/Twig/Extensions/Grammar/Boolean.php deleted file mode 100644 index c0048090..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar/Boolean.php +++ /dev/null @@ -1,24 +0,0 @@ -', $this->name); - } - - public function parse(Twig_Token $token) - { - $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, array('true', 'false')); - - return new Twig_Node_Expression_Constant('true' === $token->getValue() ? true : false, $token->getLine()); - } -} diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Constant.php b/inc/3rdparty/Twig/Extensions/Grammar/Constant.php deleted file mode 100644 index 9df60458..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar/Constant.php +++ /dev/null @@ -1,37 +0,0 @@ -name = $name; - $this->type = null === $type ? Twig_Token::NAME_TYPE : $type; - } - - public function __toString() - { - return $this->name; - } - - public function parse(Twig_Token $token) - { - $this->parser->getStream()->expect($this->type, $this->name); - - return $this->name; - } - - public function getType() - { - return $this->type; - } -} diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Expression.php b/inc/3rdparty/Twig/Extensions/Grammar/Expression.php deleted file mode 100644 index 4c33df0e..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar/Expression.php +++ /dev/null @@ -1,22 +0,0 @@ -', $this->name); - } - - public function parse(Twig_Token $token) - { - return $this->parser->getExpressionParser()->parseExpression(); - } -} diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Hash.php b/inc/3rdparty/Twig/Extensions/Grammar/Hash.php deleted file mode 100644 index 98b07d20..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar/Hash.php +++ /dev/null @@ -1,22 +0,0 @@ -', $this->name); - } - - public function parse(Twig_Token $token) - { - return $this->parser->getExpressionParser()->parseHashExpression(); - } -} diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Number.php b/inc/3rdparty/Twig/Extensions/Grammar/Number.php deleted file mode 100644 index f0857d20..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar/Number.php +++ /dev/null @@ -1,24 +0,0 @@ -', $this->name); - } - - public function parse(Twig_Token $token) - { - $this->parser->getStream()->expect(Twig_Token::NUMBER_TYPE); - - return new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - } -} diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Optional.php b/inc/3rdparty/Twig/Extensions/Grammar/Optional.php deleted file mode 100644 index da427485..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar/Optional.php +++ /dev/null @@ -1,69 +0,0 @@ -grammar = array(); - foreach (func_get_args() as $grammar) { - $this->addGrammar($grammar); - } - } - - public function __toString() - { - $repr = array(); - foreach ($this->grammar as $grammar) { - $repr[] = (string) $grammar; - } - - return sprintf('[%s]', implode(' ', $repr)); - } - - public function addGrammar(Twig_Extensions_GrammarInterface $grammar) - { - $this->grammar[] = $grammar; - } - - public function parse(Twig_Token $token) - { - // test if we have the optional element before consuming it - if ($this->grammar[0] instanceof Twig_Extensions_Grammar_Constant) { - if (!$this->parser->getStream()->test($this->grammar[0]->getType(), $this->grammar[0]->getName())) { - return array(); - } - } elseif ($this->grammar[0] instanceof Twig_Extensions_Grammar_Name) { - if (!$this->parser->getStream()->test(Twig_Token::NAME_TYPE)) { - return array(); - } - } elseif ($this->parser->getStream()->test(Twig_Token::BLOCK_END_TYPE)) { - // if this is not a Constant or a Name, it must be the last element of the tag - - return array(); - } - - $elements = array(); - foreach ($this->grammar as $grammar) { - $grammar->setParser($this->parser); - - $element = $grammar->parse($token); - if (is_array($element)) { - $elements = array_merge($elements, $element); - } else { - $elements[$grammar->getName()] = $element; - } - } - - return $elements; - } -} diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Switch.php b/inc/3rdparty/Twig/Extensions/Grammar/Switch.php deleted file mode 100644 index 4245f2c8..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar/Switch.php +++ /dev/null @@ -1,24 +0,0 @@ -', $this->name); - } - - public function parse(Twig_Token $token) - { - $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, $this->name); - - return new Twig_Node_Expression_Constant(true, $token->getLine()); - } -} diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Tag.php b/inc/3rdparty/Twig/Extensions/Grammar/Tag.php deleted file mode 100644 index 727f2610..00000000 --- a/inc/3rdparty/Twig/Extensions/Grammar/Tag.php +++ /dev/null @@ -1,56 +0,0 @@ -grammar = array(); - foreach (func_get_args() as $grammar) { - $this->addGrammar($grammar); - } - } - - public function __toString() - { - $repr = array(); - foreach ($this->grammar as $grammar) { - $repr[] = (string) $grammar; - } - - return implode(' ', $repr); - } - - public function addGrammar(Twig_Extensions_GrammarInterface $grammar) - { - $this->grammar[] = $grammar; - } - - public function parse(Twig_Token $token) - { - $elements = array(); - foreach ($this->grammar as $grammar) { - $grammar->setParser($this->parser); - - $element = $grammar->parse($token); - if (is_array($element)) { - $elements = array_merge($elements, $element); - } else { - $elements[$grammar->getName()] = $element; - } - } - - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - return $elements; - } -} diff --git a/inc/3rdparty/Twig/Extensions/GrammarInterface.php b/inc/3rdparty/Twig/Extensions/GrammarInterface.php deleted file mode 100644 index 22713bf2..00000000 --- a/inc/3rdparty/Twig/Extensions/GrammarInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - * @version SVN: $Id$ - */ -class Twig_Extensions_Node_Debug extends Twig_Node -{ - public function __construct(Twig_Node_Expression $expr = null, $lineno, $tag = null) - { - parent::__construct(array('expr' => $expr), array(), $lineno, $tag); - } - - /** - * Compiles the node to PHP. - * - * @param Twig_Compiler A Twig_Compiler instance - */ - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - - $compiler - ->write("if (\$this->env->isDebug()) {\n") - ->indent() - ; - - if (null === $this->getNode('expr')) { - // remove embedded templates (macros) from the context - $compiler - ->write("\$vars = array();\n") - ->write("foreach (\$context as \$key => \$value) {\n") - ->indent() - ->write("if (!\$value instanceof Twig_Template) {\n") - ->indent() - ->write("\$vars[\$key] = \$value;\n") - ->outdent() - ->write("}\n") - ->outdent() - ->write("}\n") - ->write("var_dump(\$vars);\n") - ; - } else { - $compiler - ->write("var_dump(") - ->subcompile($this->getNode('expr')) - ->raw(");\n") - ; - } - - $compiler - ->outdent() - ->write("}\n") - ; - } -} diff --git a/inc/3rdparty/Twig/Extensions/Node/Trans.php b/inc/3rdparty/Twig/Extensions/Node/Trans.php deleted file mode 100644 index d12564a7..00000000 --- a/inc/3rdparty/Twig/Extensions/Node/Trans.php +++ /dev/null @@ -1,133 +0,0 @@ - - */ -class Twig_Extensions_Node_Trans extends Twig_Node -{ - public function __construct(Twig_NodeInterface $body, Twig_NodeInterface $plural = null, Twig_Node_Expression $count = null, $lineno, $tag = null) - { - parent::__construct(array('count' => $count, 'body' => $body, 'plural' => $plural), array(), $lineno, $tag); - } - - /** - * Compiles the node to PHP. - * - * @param Twig_Compiler A Twig_Compiler instance - */ - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - - list($msg, $vars) = $this->compileString($this->getNode('body')); - - if (null !== $this->getNode('plural')) { - list($msg1, $vars1) = $this->compileString($this->getNode('plural')); - - $vars = array_merge($vars, $vars1); - } - - $function = null === $this->getNode('plural') ? 'gettext' : 'ngettext'; - - if ($vars) { - $compiler - ->write('echo strtr('.$function.'(') - ->subcompile($msg) - ; - - if (null !== $this->getNode('plural')) { - $compiler - ->raw(', ') - ->subcompile($msg1) - ->raw(', abs(') - ->subcompile($this->getNode('count')) - ->raw(')') - ; - } - - $compiler->raw('), array('); - - foreach ($vars as $var) { - if ('count' === $var->getAttribute('name')) { - $compiler - ->string('%count%') - ->raw(' => abs(') - ->subcompile($this->getNode('count')) - ->raw('), ') - ; - } else { - $compiler - ->string('%'.$var->getAttribute('name').'%') - ->raw(' => ') - ->subcompile($var) - ->raw(', ') - ; - } - } - - $compiler->raw("));\n"); - } else { - $compiler - ->write('echo '.$function.'(') - ->subcompile($msg) - ; - - if (null !== $this->getNode('plural')) { - $compiler - ->raw(', ') - ->subcompile($msg1) - ->raw(', abs(') - ->subcompile($this->getNode('count')) - ->raw(')') - ; - } - - $compiler->raw(");\n"); - } - } - - protected function compileString(Twig_NodeInterface $body) - { - if ($body instanceof Twig_Node_Expression_Name || $body instanceof Twig_Node_Expression_Constant || $body instanceof Twig_Node_Expression_TempName) { - return array($body, array()); - } - - $vars = array(); - if (count($body)) { - $msg = ''; - - foreach ($body as $node) { - if (get_class($node) === 'Twig_Node' && $node->getNode(0) instanceof Twig_Node_SetTemp) { - $node = $node->getNode(1); - } - - if ($node instanceof Twig_Node_Print) { - $n = $node->getNode('expr'); - while ($n instanceof Twig_Node_Expression_Filter) { - $n = $n->getNode('node'); - } - $msg .= sprintf('%%%s%%', $n->getAttribute('name')); - $vars[] = new Twig_Node_Expression_Name($n->getAttribute('name'), $n->getLine()); - } else { - $msg .= $node->getAttribute('data'); - } - } - } else { - $msg = $body->getAttribute('data'); - } - - return array(new Twig_Node(array(new Twig_Node_Expression_Constant(trim($msg), $body->getLine()))), $vars); - } -} diff --git a/inc/3rdparty/Twig/Extensions/SimpleTokenParser.php b/inc/3rdparty/Twig/Extensions/SimpleTokenParser.php deleted file mode 100644 index 49546487..00000000 --- a/inc/3rdparty/Twig/Extensions/SimpleTokenParser.php +++ /dev/null @@ -1,132 +0,0 @@ -getGrammar(); - if (!is_object($grammar)) { - $grammar = self::parseGrammar($grammar); - } - - $grammar->setParser($this->parser); - $values = $grammar->parse($token); - - return $this->getNode($values, $token->getLine()); - } - - /** - * Gets the grammar as an object or as a string. - * - * @return string|Twig_Extensions_Grammar A Twig_Extensions_Grammar instance or a string - */ - abstract protected function getGrammar(); - - /** - * Gets the nodes based on the parsed values. - * - * @param array $values An array of values - * @param integer $line The parser line - */ - abstract protected function getNode(array $values, $line); - - protected function getAttribute($node, $attribute, $arguments = array(), $type = Twig_Node_Expression_GetAttr::TYPE_ANY, $line = -1) - { - return new Twig_Node_Expression_GetAttr( - $node instanceof Twig_NodeInterface ? $node : new Twig_Node_Expression_Name($node, $line), - $attribute instanceof Twig_NodeInterface ? $attribute : new Twig_Node_Expression_Constant($attribute, $line), - $arguments instanceof Twig_NodeInterface ? $arguments : new Twig_Node($arguments), - $type, - $line - ); - } - - protected function call($node, $attribute, $arguments = array(), $line = -1) - { - return $this->getAttribute($node, $attribute, $arguments, Twig_Node_Expression_GetAttr::TYPE_METHOD, $line); - } - - protected function markAsSafe(Twig_NodeInterface $node, $line = -1) - { - return new Twig_Node_Expression_Filter( - $node, - new Twig_Node_Expression_Constant('raw', $line), - new Twig_Node(), - $line - ); - } - - protected function output(Twig_NodeInterface $node, $line = -1) - { - return new Twig_Node_Print($node, $line); - } - - protected function getNodeValues(array $values) - { - $nodes = array(); - foreach ($values as $value) { - if ($value instanceof Twig_NodeInterface) { - $nodes[] = $value; - } - } - - return $nodes; - } - - static public function parseGrammar($str, $main = true) - { - static $cursor; - - if (true === $main) { - $cursor = 0; - $grammar = new Twig_Extensions_Grammar_Tag(); - } else { - $grammar = new Twig_Extensions_Grammar_Optional(); - } - - while ($cursor < strlen($str)) { - if (preg_match('/\s+/A', $str, $match, null, $cursor)) { - $cursor += strlen($match[0]); - } elseif (preg_match('/<(\w+)(?:\:(\w+))?>/A', $str, $match, null, $cursor)) { - $class = sprintf('Twig_Extensions_Grammar_%s', ucfirst(isset($match[2]) ? $match[2] : 'Expression')); - if (!class_exists($class)) { - throw new Twig_Error_Runtime(sprintf('Unable to understand "%s" in grammar (%s class does not exist)', $match[0], $class)); - } - $grammar->addGrammar(new $class($match[1])); - $cursor += strlen($match[0]); - } elseif (preg_match('/\w+/A', $str, $match, null, $cursor)) { - $grammar->addGrammar(new Twig_Extensions_Grammar_Constant($match[0])); - $cursor += strlen($match[0]); - } elseif (preg_match('/,/A', $str, $match, null, $cursor)) { - $grammar->addGrammar(new Twig_Extensions_Grammar_Constant($match[0], Twig_Token::PUNCTUATION_TYPE)); - $cursor += strlen($match[0]); - } elseif (preg_match('/\[/A', $str, $match, null, $cursor)) { - $cursor += strlen($match[0]); - $grammar->addGrammar(self::parseGrammar($str, false)); - } elseif (true !== $main && preg_match('/\]/A', $str, $match, null, $cursor)) { - $cursor += strlen($match[0]); - - return $grammar; - } else { - throw new Twig_Error_Runtime(sprintf('Unable to parse grammar "%s" near "...%s..."', $str, substr($str, $cursor, 10))); - } - } - - return $grammar; - } -} diff --git a/inc/3rdparty/Twig/Extensions/TokenParser/Debug.php b/inc/3rdparty/Twig/Extensions/TokenParser/Debug.php deleted file mode 100644 index 4a7dfcc0..00000000 --- a/inc/3rdparty/Twig/Extensions/TokenParser/Debug.php +++ /dev/null @@ -1,42 +0,0 @@ -getLine(); - - $expr = null; - if (!$this->parser->getStream()->test(Twig_Token::BLOCK_END_TYPE)) { - $expr = $this->parser->getExpressionParser()->parseExpression(); - } - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Extensions_Node_Debug($expr, $lineno, $this->getTag()); - } - - /** - * Gets the tag name associated with this token parser. - * - * @param string The tag name - */ - public function getTag() - { - return 'debug'; - } -} diff --git a/inc/3rdparty/Twig/Extensions/TokenParser/Trans.php b/inc/3rdparty/Twig/Extensions/TokenParser/Trans.php deleted file mode 100644 index 5e2dc464..00000000 --- a/inc/3rdparty/Twig/Extensions/TokenParser/Trans.php +++ /dev/null @@ -1,80 +0,0 @@ -getLine(); - $stream = $this->parser->getStream(); - $count = null; - $plural = null; - - if (!$stream->test(Twig_Token::BLOCK_END_TYPE)) { - $body = $this->parser->getExpressionParser()->parseExpression(); - } else { - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'decideForFork')); - if ('plural' === $stream->next()->getValue()) { - $count = $this->parser->getExpressionParser()->parseExpression(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $plural = $this->parser->subparse(array($this, 'decideForEnd'), true); - } - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $this->checkTransString($body, $lineno); - - return new Twig_Extensions_Node_Trans($body, $plural, $count, $lineno, $this->getTag()); - } - - public function decideForFork(Twig_Token $token) - { - return $token->test(array('plural', 'endtrans')); - } - - public function decideForEnd(Twig_Token $token) - { - return $token->test('endtrans'); - } - - /** - * Gets the tag name associated with this token parser. - * - * @param string The tag name - */ - public function getTag() - { - return 'trans'; - } - - protected function checkTransString(Twig_NodeInterface $body, $lineno) - { - foreach ($body as $i => $node) { - if ( - $node instanceof Twig_Node_Text - || - ($node instanceof Twig_Node_Print && $node->getNode('expr') instanceof Twig_Node_Expression_Name) - ) { - continue; - } - - throw new Twig_Error_Syntax(sprintf('The text to be translated with "trans" can only contain references to simple variables'), $lineno); - } - } -} -- cgit v1.2.3