Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  [ExpressionLanguage] Update the docs about the null-coalescing operator
  Update micro_kernel_trait.rst
  MapQueryParameter regex example correction
  • Loading branch information
javiereguiluz committed Apr 2, 2024
2 parents 21025f8 + 3e350e2 commit 914d403
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
13 changes: 4 additions & 9 deletions components/expression_language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,10 @@ The main class of the component is
Null Coalescing Operator
........................

This is the same as the PHP `null-coalescing operator`_, which combines
the ternary operator and ``isset()``. It returns the left hand-side if it exists
and it's not ``null``; otherwise it returns the right hand-side. Note that you
can chain multiple coalescing operators.

* ``foo ?? 'no'``
* ``foo.baz ?? 'no'``
* ``foo[3] ?? 'no'``
* ``foo.baz ?? foo['baz'] ?? 'no'``
.. note::

This content has been moved to the ref:`null coalescing operator <component-expression-null-coalescing-operator>`
section of ExpressionLanguage syntax reference page.

Parsing and Linting Expressions
...............................
Expand Down
1 change: 1 addition & 0 deletions configuration/micro_kernel_trait.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ Now it looks like this::

use App\DependencyInjection\AppExtension;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
Expand Down
2 changes: 1 addition & 1 deletion controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ attribute, arguments of your controller's action can be automatically fulfilled:
// ...

public function dashboard(
#[MapQueryParameter(filter: \FILTER_VALIDATE_REGEXP, options: ['regexp' => '/^\w++$/'])] string $firstName,
#[MapQueryParameter(filter: \FILTER_VALIDATE_REGEXP, options: ['regexp' => '/^\w+$/'])] string $firstName,
#[MapQueryParameter] string $lastName,
#[MapQueryParameter(filter: \FILTER_VALIDATE_INT)] int $age,
): Response
Expand Down
29 changes: 29 additions & 0 deletions reference/formats/expression_language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ JavaScript::

This will print out ``Hi Hi Hi!``.

.. _component-expression-null-safe-operator:

Null-safe Operator
..................

Expand All @@ -109,6 +111,25 @@ operator)::
$expressionLanguage->evaluate('fruit?.color', ['fruit' => '...'])
$expressionLanguage->evaluate('fruit?.getStock()', ['fruit' => '...'])

.. _component-expression-null-coalescing-operator:

Null-Coalescing Operator
........................

It returns the left-hand side if it exists and it's not ``null``; otherwise it
returns the right-hand side. Expressions can chain multiple coalescing operators:

* ``foo ?? 'no'``
* ``foo.baz ?? 'no'``
* ``foo[3] ?? 'no'``
* ``foo.baz ?? foo['baz'] ?? 'no'``

.. note::

The main difference with the `null-coalescing operator in PHP`_ is that
ExpressionLanguage will throw an exception when trying to access a
non-existent variable.

.. _component-expression-functions:

Working with Functions
Expand Down Expand Up @@ -370,6 +391,12 @@ Ternary Operators
* ``foo ?: 'no'`` (equal to ``foo ? foo : 'no'``)
* ``foo ? 'yes'`` (equal to ``foo ? 'yes' : ''``)

Other Operators
~~~~~~~~~~~~~~~

* ``?.`` (:ref:`null-safe operator <component-expression-null-safe-operator>`)
* ``??`` (:ref:`null-coalescing operator <component-expression-null-coalescing-operator>`)

Built-in Objects and Variables
------------------------------

Expand All @@ -380,3 +407,5 @@ expressions (e.g. the request, the current user, etc.):
* :doc:`Variables available in security expressions </security/expressions>`;
* :doc:`Variables available in service container expressions </service_container/expression_language>`;
* :ref:`Variables available in routing expressions <routing-matching-expressions>`.

.. _`null-coalescing operator in PHP`: https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce

0 comments on commit 914d403

Please sign in to comment.