tweaked previous merge
authorFabien Potencier <fabien.potencier@gmail.com>
Wed, 28 Dec 2011 19:34:32 +0000 (20:34 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Wed, 28 Dec 2011 19:34:32 +0000 (20:34 +0100)
CHANGELOG
doc/filters/number_format.rst
lib/Twig/Extension/Core.php

index b75a347..a53f805 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+* 1.5.0-RC2
+
+ * added a number_format filter
+
 * 1.5.0-RC1 (2011-12-26)
 
  * removed the need to quote hash keys
index 8b5f90b..ccc8f2f 100644 (file)
@@ -1,8 +1,8 @@
 ``number_format``
 =================
 
-.. versionadded:: 1.6
-    The number_format filter was added in Twig 1.6
+.. versionadded:: 1.5
+    The number_format filter was added in Twig 1.5
 
 The ``number_format`` filter formats numbers.  It is a wrapper around PHP's
 `number_format`_ function:
@@ -36,4 +36,3 @@ The defaults set for ``number_format`` can be over-ridden upon each call using t
 additional parameters.
 
 .. _`number_format`: http://php.net/number_format
-
index e247c95..126ff97 100644 (file)
@@ -93,10 +93,10 @@ class Twig_Extension_Core extends Twig_Extension
     {
         $filters = array(
             // formatting filters
-            'date'    => new Twig_Filter_Function('twig_date_format_filter', array('needs_environment' => true)),
-            'format'  => new Twig_Filter_Function('sprintf'),
-            'replace' => new Twig_Filter_Function('strtr'),
-            'number_format'  => new Twig_Filter_Function('twig_number_format_filter', array('needs_environment' => true)),
+            'date'          => new Twig_Filter_Function('twig_date_format_filter', array('needs_environment' => true)),
+            'format'        => new Twig_Filter_Function('sprintf'),
+            'replace'       => new Twig_Filter_Function('strtr'),
+            'number_format' => new Twig_Filter_Function('twig_number_format_filter', array('needs_environment' => true)),
 
             // encoding
             'url_encode'       => new Twig_Filter_Function('twig_urlencode_filter'),
@@ -352,15 +352,18 @@ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $
 function twig_number_format_filter(Twig_Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null)
 {
     $defaults = $env->getExtension('core')->getNumberFormat();
-    if ($decimal === null) {
+    if (null === $decimal) {
         $decimal = $defaults[0];
     }
-    if ($decimalPoint === null) {
+
+    if (null === $decimalPoint) {
         $decimalPoint = $defaults[1];
     }
-    if ($thousandSep === null) {
+
+    if (null === $thousandSep) {
         $thousandSep = $defaults[2];
     }
+
     return number_format((float) $number, $decimal, $decimalPoint, $thousandSep);
 }