Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
feature #151 fixed compat with Twig 2.0 (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.2.x-dev branch.

Discussion
----------

fixed compat with Twig 2.0

Commits
-------

bba7d7b fixed CS
ab7651c updated .travis.yml
1411b68 fixed compat with Twig 2.0
  • Loading branch information
fabpot committed Aug 22, 2015
2 parents 5cc242e + bba7d7b commit 01b42bf
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 86 deletions.
31 changes: 23 additions & 8 deletions .travis.yml
@@ -1,14 +1,29 @@
language: php

sudo: false

cache:
directories:
- vendor
- $HOME/.composer/cache

env:
globals:
- deps=no

before_script:
- composer install --prefer-source
- if [ "$deps" = "low" ]; then composer --prefer-lowest --prefer-stable update; fi;
- if [ "$deps" = "no" ]; then composer install; fi;

script: phpunit

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
matrix:
include:
- php: hhvm
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
env: deps=low
- php: 7.0
fast_finish: true
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"twig/twig": "~1.12"
"twig/twig": "~1.20|~2.0"
},
"require-dev": {
"symfony/translation": "~2.3"
Expand All @@ -23,6 +23,7 @@
"autoload": {
"psr-0": { "Twig_Extensions_": "lib/" }
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
Expand Down
11 changes: 5 additions & 6 deletions lib/Twig/Extensions/Autoloader.php
Expand Up @@ -12,27 +12,26 @@
/**
* Autoloads Twig Extensions classes.
*
* @package twig
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class Twig_Extensions_Autoloader
{
/**
* Registers Twig_Extensions_Autoloader as an SPL autoloader.
*/
static public function register()
public static function register()
{
spl_autoload_register(array(new self, 'autoload'));
spl_autoload_register(array(new self(), 'autoload'));
}

/**
* Handles autoloading of classes.
*
* @param string $class A class name.
* @param string $class A class name.
*
* @return boolean Returns true if the class has been loaded
* @return bool Returns true if the class has been loaded
*/
static public function autoload($class)
public static function autoload($class)
{
if (0 !== strpos($class, 'Twig_Extensions')) {
return;
Expand Down
7 changes: 3 additions & 4 deletions lib/Twig/Extensions/Extension/Array.php
Expand Up @@ -9,8 +9,6 @@
* file that was distributed with this source code.
*
* @author Ricard Clau <ricard.clau@gmail.com>
* @package Twig
* @subpackage Twig-extensions
*/
class Twig_Extensions_Extension_Array extends Twig_Extension
{
Expand All @@ -28,7 +26,7 @@ public function getFilters()
return $filters;
}
/**
* Name of this extension
* Name of this extension.
*
* @return string
*/
Expand All @@ -42,6 +40,7 @@ public function getName()
* Shuffles an array.
*
* @param array|Traversable $array An array
*
* @return array
*/
function twig_shuffle_filter($array)
Expand All @@ -53,4 +52,4 @@ function twig_shuffle_filter($array)
shuffle($array);

return $array;
}
}
8 changes: 3 additions & 5 deletions lib/Twig/Extensions/Extension/Date.php
Expand Up @@ -7,17 +7,15 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/

use Symfony\Component\Translation\TranslatorInterface;

/**
* @author Robin van der Vleuten <robinvdvleuten@gmail.com>
*/
class Twig_Extensions_Extension_Date extends Twig_Extension
{
static $units = array(
public static $units = array(
'y' => 'year',
'm' => 'month',
'd' => 'day',
Expand Down Expand Up @@ -50,13 +48,13 @@ public function getFilters()
{
return array(
new Twig_SimpleFilter('time_diff', array($this, 'diff'), array(
'needs_environment' => true
'needs_environment' => true,
)),
);
}

/**
* Name of this extension
* Name of this extension.
*
* @return string
*/
Expand Down
38 changes: 19 additions & 19 deletions lib/Twig/Extensions/Extension/Intl.php
Expand Up @@ -48,11 +48,11 @@ function twig_localized_date_filter(Twig_Environment $env, $date, $dateFormat =
$date = twig_date_converter($env, $date, $timezone);

$formatValues = array(
'none' => IntlDateFormatter::NONE,
'short' => IntlDateFormatter::SHORT,
'none' => IntlDateFormatter::NONE,
'short' => IntlDateFormatter::SHORT,
'medium' => IntlDateFormatter::MEDIUM,
'long' => IntlDateFormatter::LONG,
'full' => IntlDateFormatter::FULL,
'long' => IntlDateFormatter::LONG,
'full' => IntlDateFormatter::FULL,
);

$formatter = IntlDateFormatter::create(
Expand All @@ -70,11 +70,11 @@ function twig_localized_date_filter(Twig_Environment $env, $date, $dateFormat =
function twig_localized_number_filter($number, $style = 'decimal', $type = 'default', $locale = null)
{
static $typeValues = array(
'default' => NumberFormatter::TYPE_DEFAULT,
'int32' => NumberFormatter::TYPE_INT32,
'int64' => NumberFormatter::TYPE_INT64,
'double' => NumberFormatter::TYPE_DOUBLE,
'currency' => NumberFormatter::TYPE_CURRENCY,
'default' => NumberFormatter::TYPE_DEFAULT,
'int32' => NumberFormatter::TYPE_INT32,
'int64' => NumberFormatter::TYPE_INT64,
'double' => NumberFormatter::TYPE_DOUBLE,
'currency' => NumberFormatter::TYPE_CURRENCY,
);

$formatter = twig_get_number_formatter($locale, $style);
Expand All @@ -94,10 +94,10 @@ function twig_localized_currency_filter($number, $currency = null, $locale = nul
}

/**
* Gets a number formatter instance according to given locale and formatter
* Gets a number formatter instance according to given locale and formatter.
*
* @param string $locale Locale in which the number would be formatted
* @param int $style Style of the formatting
* @param string $locale Locale in which the number would be formatted
* @param int $style Style of the formatting
*
* @return NumberFormatter A NumberFormatter instance
*/
Expand All @@ -114,13 +114,13 @@ function twig_get_number_formatter($locale, $style)
}

static $styleValues = array(
'decimal' => NumberFormatter::DECIMAL,
'currency' => NumberFormatter::CURRENCY,
'percent' => NumberFormatter::PERCENT,
'scientific' => NumberFormatter::SCIENTIFIC,
'spellout' => NumberFormatter::SPELLOUT,
'ordinal' => NumberFormatter::ORDINAL,
'duration' => NumberFormatter::DURATION,
'decimal' => NumberFormatter::DECIMAL,
'currency' => NumberFormatter::CURRENCY,
'percent' => NumberFormatter::PERCENT,
'scientific' => NumberFormatter::SCIENTIFIC,
'spellout' => NumberFormatter::SPELLOUT,
'ordinal' => NumberFormatter::ORDINAL,
'duration' => NumberFormatter::DURATION,
);

if (!isset($styleValues[$style])) {
Expand Down
12 changes: 5 additions & 7 deletions lib/Twig/Extensions/Extension/Text.php
Expand Up @@ -9,8 +9,6 @@
* file that was distributed with this source code.
*
* @author Henrik Bjornskov <hb@peytz.dk>
* @package Twig
* @subpackage Twig-extensions
*/
class Twig_Extensions_Extension_Text extends Twig_Extension
{
Expand All @@ -28,7 +26,7 @@ public function getFilters()
}

/**
* Name of this extension
* Name of this extension.
*
* @return string
*/
Expand All @@ -51,7 +49,7 @@ function twig_truncate_filter(Twig_Environment $env, $value, $length = 30, $pres
$length = $breakpoint;
}

return rtrim(mb_substr($value, 0, $length, $env->getCharset())) . $separator;
return rtrim(mb_substr($value, 0, $length, $env->getCharset())).$separator;
}

return $value;
Expand All @@ -68,7 +66,7 @@ function twig_wordwrap_filter(Twig_Environment $env, $value, $length = 80, $sepa
mb_regex_encoding($previous);

foreach ($pieces as $piece) {
while(!$preserve && mb_strlen($piece, $env->getCharset()) > $length) {
while (!$preserve && mb_strlen($piece, $env->getCharset()) > $length) {
$sentences[] = mb_substr($piece, 0, $length, $env->getCharset());
$piece = mb_substr($piece, $length, 2048, $env->getCharset());
}
Expand All @@ -88,7 +86,7 @@ function twig_truncate_filter(Twig_Environment $env, $value, $length = 30, $pres
}
}

return rtrim(substr($value, 0, $length)) . $separator;
return rtrim(substr($value, 0, $length)).$separator;
}

return $value;
Expand All @@ -98,4 +96,4 @@ function twig_wordwrap_filter(Twig_Environment $env, $value, $length = 80, $sepa
{
return wordwrap($value, $length, $separator, !$preserve);
}
}
}
6 changes: 3 additions & 3 deletions lib/Twig/Extensions/Grammar.php
Expand Up @@ -22,9 +22,9 @@ public function __construct($name)
}

/**
* @param Twig_ParserInterface $parser
*/
public function setParser(Twig_ParserInterface $parser)
* @param Twig_Parser $parser
*/
public function setParser(Twig_Parser $parser)
{
$this->parser = $parser;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Twig/Extensions/GrammarInterface.php
Expand Up @@ -10,9 +10,9 @@
*/
interface Twig_Extensions_GrammarInterface
{
function setParser(Twig_ParserInterface $parser);
public function setParser(Twig_Parser $parser);

function parse(Twig_Token $token);
public function parse(Twig_Token $token);

function getName();
public function getName();
}
9 changes: 4 additions & 5 deletions lib/Twig/Extensions/Node/Trans.php
Expand Up @@ -12,12 +12,11 @@
/**
* Represents a trans node.
*
* @package twig
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class Twig_Extensions_Node_Trans extends Twig_Node
{
public function __construct(Twig_NodeInterface $body, Twig_NodeInterface $plural = null, Twig_Node_Expression $count = null, Twig_NodeInterface $notes = null, $lineno, $tag = null)
public function __construct(Twig_Node $body, Twig_Node $plural = null, Twig_Node_Expression $count = null, Twig_Node $notes = null, $lineno, $tag = null)
{
parent::__construct(array('count' => $count, 'body' => $body, 'plural' => $plural, 'notes' => $notes), array(), $lineno, $tag);
}
Expand Down Expand Up @@ -45,7 +44,7 @@ public function compile(Twig_Compiler $compiler)
$message = trim($notes->getAttribute('data'));

// line breaks are not allowed cause we want a single line comment
$message = str_replace(array("\n", "\r"), " ", $message);
$message = str_replace(array("\n", "\r"), ' ', $message);
$compiler->write("// notes: {$message}\n");
}

Expand Down Expand Up @@ -107,11 +106,11 @@ public function compile(Twig_Compiler $compiler)
}

/**
* @param Twig_NodeInterface $body A Twig_NodeInterface instance
* @param Twig_Node $body A Twig_Node instance
*
* @return array
*/
protected function compileString(Twig_NodeInterface $body)
protected function compileString(Twig_Node $body)
{
if ($body instanceof Twig_Node_Expression_Name || $body instanceof Twig_Node_Expression_Constant || $body instanceof Twig_Node_Expression_TempName) {
return array($body, array());
Expand Down

0 comments on commit 01b42bf

Please sign in to comment.