@@ -34,11 +34,11 @@ Create a class that extends ``AbstractExtension`` and fill in the logic::
3434 public function getFilters()
3535 {
3636 return [
37- new TwigFilter('price', [$this, 'priceFilter ']),
37+ new TwigFilter('price', [$this, 'formatPrice ']),
3838 ];
3939 }
4040
41- public function priceFilter ($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
41+ public function formatPrice ($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
4242 {
4343 $price = number_format($number, $decimals, $decPoint, $thousandsSep);
4444 $price = '$'.$price;
@@ -111,7 +111,7 @@ be significant.
111111
112112That's why Twig allows to decouple the extension definition from its
113113implementation. Following the same example as before, the first change would be
114- to remove the ``priceFilter () `` method from the extension and update the PHP
114+ to remove the ``formatPrice () `` method from the extension and update the PHP
115115callable defined in ``getFilters() ``::
116116
117117 // src/AppBundle/Twig/AppExtension.php
@@ -127,14 +127,14 @@ callable defined in ``getFilters()``::
127127 {
128128 return [
129129 // the logic of this filter is now implemented in a different class
130- new TwigFilter('price', [AppRuntime::class, 'priceFilter ']),
130+ new TwigFilter('price', [AppRuntime::class, 'formatPrice ']),
131131 ];
132132 }
133133 }
134134
135135Then, create the new ``AppRuntime `` class (it's not required but these classes
136136are suffixed with ``Runtime `` by convention) and include the logic of the
137- previous ``priceFilter () `` method::
137+ previous ``formatPrice () `` method::
138138
139139 // src/AppBundle/Twig/AppRuntime.php
140140 namespace AppBundle\Twig;
@@ -149,7 +149,7 @@ previous ``priceFilter()`` method::
149149 // extensions, you'll need to inject services using this constructor
150150 }
151151
152- public function priceFilter ($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
152+ public function formatPrice ($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
153153 {
154154 $price = number_format($number, $decimals, $decPoint, $thousandsSep);
155155 $price = '$'.$price;
0 commit comments