Skip to content

Commit c35b930

Browse files
committed
Merge branch '3.4' into 4.1
* 3.4: Update twig_extension.rst Fixed more occurrences of app/console Change app to bin . Added missing chapters to TOC in file constraints reference
2 parents 37adcb5 + cdb5ee0 commit c35b930

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

console/input.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ separation at all (e.g. ``-i 5`` or ``-i5``).
183183

184184
While it is possible to separate an option from its value with a white space,
185185
using this form leads to an ambiguity should the option appear before the
186-
command name. For example, ``php app/console --iterations 5 app:greet Fabien``
186+
command name. For example, ``php bin/console --iterations 5 app:greet Fabien``
187187
is ambiguous; Symfony would interpret ``5`` as the command name. To avoid
188188
this situation, always place options after the command name, or avoid using
189189
a space to separate the option name from its value.

reference/constraints/File.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ form field.
2929
| | - `notReadableMessage`_ |
3030
| | - `uploadIniSizeErrorMessage`_ |
3131
| | - `uploadFormSizeErrorMessage`_ |
32+
| | - `uploadPartialErrorMessage`_ |
33+
| | - `uploadNoFileErrorMessage`_ |
34+
| | - `uploadNoTmpDirErrorMessage`_ |
35+
| | - `uploadCantWriteErrorMessage`_ |
36+
| | - `uploadExtensionErrorMessage`_ |
3237
| | - `uploadErrorMessage`_ |
3338
| | - `payload`_ |
3439
+----------------+---------------------------------------------------------------------+

templating/twig_extension.rst

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ Create a class that extends ``AbstractExtension`` and fill in the logic::
4545
public function getFilters()
4646
{
4747
return array(
48-
new TwigFilter('price', array($this, 'priceFilter')),
48+
new TwigFilter('price', array($this, 'formatPrice')),
4949
);
5050
}
5151

52-
public function priceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
52+
public function formatPrice($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
5353
{
5454
$price = number_format($number, $decimals, $decPoint, $thousandsSep);
5555
$price = '$'.$price;
@@ -58,9 +58,33 @@ Create a class that extends ``AbstractExtension`` and fill in the logic::
5858
}
5959
}
6060

61+
If you want to create a function instead of a filter, define the ``getFunctions()``
62+
method:
63+
64+
// src/Twig/AppExtension.php
65+
namespace App\Twig;
66+
67+
use Twig\Extension\AbstractExtension;
68+
use Twig\TwigFunction;
69+
70+
class AppExtension extends AbstractExtension
71+
{
72+
public function getFunctions()
73+
{
74+
return array(
75+
new TwigFunction('area', array($this, 'calculateArea')),
76+
);
77+
}
78+
79+
public function calculateArea(int $width, int $length)
80+
{
81+
return $width * $length;
82+
}
83+
}
84+
6185
.. tip::
6286

63-
Along with custom filters, you can also add custom `functions`_ and register
87+
Along with custom filters and functions, you can also register
6488
`global variables`_.
6589

6690
Register an Extension as a Service

0 commit comments

Comments
 (0)