From 54bb5cba6af635724cf141cb8f3cef1010a4c426 Mon Sep 17 00:00:00 2001 From: lkolndeep Date: Sat, 30 Mar 2024 16:00:11 +0100 Subject: [PATCH 1/3] MapQueryParameter regex example correction --- controller.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller.rst b/controller.rst index 7a3e7aec0f2..436326aa700 100644 --- a/controller.rst +++ b/controller.rst @@ -375,7 +375,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 From be86770f22c5c6d802163cc6777930df45874069 Mon Sep 17 00:00:00 2001 From: Sudhakar Krishnan Date: Thu, 28 Mar 2024 11:08:51 +0530 Subject: [PATCH 2/3] Update micro_kernel_trait.rst --- configuration/micro_kernel_trait.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/configuration/micro_kernel_trait.rst b/configuration/micro_kernel_trait.rst index 4b538f1b6e4..280255a4064 100644 --- a/configuration/micro_kernel_trait.rst +++ b/configuration/micro_kernel_trait.rst @@ -230,6 +230,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; From ca016d741a7f58f31e3bbe3b141fcc94f78ea2b8 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 26 Mar 2024 15:02:17 +0100 Subject: [PATCH 3/3] [ExpressionLanguage] Update the docs about the null-coalescing operator --- components/expression_language.rst | 15 +++-------- reference/formats/expression_language.rst | 33 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/components/expression_language.rst b/components/expression_language.rst index b75c3d13c34..f622326944e 100644 --- a/components/expression_language.rst +++ b/components/expression_language.rst @@ -80,19 +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'`` - -.. versionadded:: 6.2 +.. note:: - The null-coalescing operator was introduced in Symfony 6.2. + This content has been moved to the ref:`null coalescing operator ` + section of ExpressionLanguage syntax reference page. Parsing and Linting Expressions ............................... diff --git a/reference/formats/expression_language.rst b/reference/formats/expression_language.rst index af03b6a07d1..370dbfd6f00 100644 --- a/reference/formats/expression_language.rst +++ b/reference/formats/expression_language.rst @@ -99,6 +99,8 @@ JavaScript:: This will print out ``Hi Hi Hi!``. +.. _component-expression-null-safe-operator: + Null-safe Operator .................. @@ -118,6 +120,29 @@ operator):: The null safe operator was introduced in Symfony 6.1. +.. _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. + +.. versionadded:: 6.2 + + The null-coalescing operator was introduced in Symfony 6.2. + .. _component-expression-functions: Working with Functions @@ -391,6 +416,12 @@ Ternary Operators * ``foo ?: 'no'`` (equal to ``foo ? foo : 'no'``) * ``foo ? 'yes'`` (equal to ``foo ? 'yes' : ''``) +Other Operators +~~~~~~~~~~~~~~~ + +* ``?.`` (:ref:`null-safe operator `) +* ``??`` (:ref:`null-coalescing operator `) + Built-in Objects and Variables ------------------------------ @@ -401,3 +432,5 @@ expressions (e.g. the request, the current user, etc.): * :doc:`Variables available in security expressions `; * :doc:`Variables available in service container expressions `; * :ref:`Variables available in routing expressions `. + +.. _`null-coalescing operator in PHP`: https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce