@@ -133,7 +133,7 @@ be significant.
133
133
134
134
That's why Twig allows to decouple the extension definition from its
135
135
implementation. Following the same example as before, the first change would be
136
- to remove the ``priceFilter () `` method from the extension and update the PHP
136
+ to remove the ``formatPrice () `` method from the extension and update the PHP
137
137
callable defined in ``getFilters() ``::
138
138
139
139
// src/Twig/AppExtension.php
@@ -149,14 +149,14 @@ callable defined in ``getFilters()``::
149
149
{
150
150
return [
151
151
// the logic of this filter is now implemented in a different class
152
- new TwigFilter('price', [AppRuntime::class, 'priceFilter ']),
152
+ new TwigFilter('price', [AppRuntime::class, 'formatPrice ']),
153
153
];
154
154
}
155
155
}
156
156
157
157
Then, create the new ``AppRuntime `` class (it's not required but these classes
158
158
are suffixed with ``Runtime `` by convention) and include the logic of the
159
- previous ``priceFilter () `` method::
159
+ previous ``formatPrice () `` method::
160
160
161
161
// src/Twig/AppRuntime.php
162
162
namespace App\Twig;
@@ -171,7 +171,7 @@ previous ``priceFilter()`` method::
171
171
// extensions, you'll need to inject services using this constructor
172
172
}
173
173
174
- public function priceFilter ($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
174
+ public function formatPrice ($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
175
175
{
176
176
$price = number_format($number, $decimals, $decPoint, $thousandsSep);
177
177
$price = '$'.$price;
0 commit comments