From aabb62e72fc8173f454efe82564ece273f138dbc Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Mon, 15 Aug 2022 00:50:08 +0200 Subject: [PATCH 001/205] Removing 2 distracting scenarios Reason: Too many numbers are only distracting from the message - anybody can image that all numbers are just arbitrary examples... Other problem: The axis legends "1 hour window" in the SVG are overlapping: https://symfony.com/doc/5.4/rate_limiter.html#fixed-window-rate-limiter Maybe either reduce the font size, or reword to just "window" --- rate_limiter.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rate_limiter.rst b/rate_limiter.rst index 65a0243e5e8..a5b73ac4735 100644 --- a/rate_limiter.rst +++ b/rate_limiter.rst @@ -35,8 +35,7 @@ Fixed Window Rate Limiter ~~~~~~~~~~~~~~~~~~~~~~~~~ This is the simplest technique and it's based on setting a limit for a given -interval of time (e.g. 5,000 requests per hour or 3 login attempts every 15 -minutes). +interval of time. In the diagram below, the limit is set to "5 tokens per hour". Each window starts at the first hit (i.e. 10:15, 11:30 and 12:30). As soon as there are @@ -48,11 +47,11 @@ squares). Its main drawback is that resource usage is not evenly distributed in time and -it can overload the server at the window edges. In the previous example, +it can overload the server at the window edges. In this example, there were 6 accepted requests between 11:00 and 12:00. This is more significant with bigger limits. For instance, with 5,000 requests -per hour, a user could make the 4,999 requests in the last minute of some +per hour, a user could make 4,999 requests in the last minute of some hour and another 5,000 requests during the first minute of the next hour, making 9,999 requests in total in two minutes and possibly overloading the server. These periods of excessive usage are called "bursts". From 9262483ce3346eda0dc167b53bfea42adf2c98d1 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 10 Nov 2022 22:54:22 +0100 Subject: [PATCH 002/205] Consistent naming of `FormLoginAuthenticator` Reason: Make it more clear that we're always talking about the same **built-in** thing. --- security.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/security.rst b/security.rst index 583f5e19f9a..abfa7c1e7c8 100644 --- a/security.rst +++ b/security.rst @@ -660,7 +660,7 @@ Form Login Most websites have a login form where users authenticate using an identifier (e.g. email address or username) and a password. This -functionality is provided by the *form login authenticator*. +functionality is provided by the built-in :class:`Symfony\\Component\\Security\\Http\Authenticator\\FormLoginAuthenticator`. First, create a controller for the login form: @@ -691,7 +691,7 @@ First, create a controller for the login form: } } -Then, enable the form login authenticator using the ``form_login`` setting: +Then, enable the ``FormLoginAuthenticator`` using the ``form_login`` setting: .. configuration-block:: @@ -784,8 +784,8 @@ Edit the login controller to render the login form: } } -Don't let this controller confuse you. Its job is only to *render* the form: -the ``form_login`` authenticator will handle the form *submission* automatically. +Don't let this controller confuse you. Its job is only to *render* the form. +The ``FormLoginAuthenticator`` will handle the form *submission* automatically. If the user submits an invalid email or password, that authenticator will store the error and redirect back to this controller, where we read the error (using ``AuthenticationUtils``) so that it can be displayed back to the user. @@ -857,7 +857,7 @@ To review the whole process: #. The ``/login`` page renders login form via the route and controller created in this example; #. The user submits the login form to ``/login``; -#. The security system (i.e. the ``form_login`` authenticator) intercepts the +#. The security system (i.e. the ``FormLoginAuthenticator``) intercepts the request, checks the user's submitted credentials, authenticates the user if they are correct, and sends the user back to the login form if they are not. From 6c19fa7a835ca9407bde4b7f91c9b2cb6fbc052f Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 6 Dec 2022 16:46:57 +0100 Subject: [PATCH 003/205] Changing versionadded 5.1 to note Reasons: * Info about 5.1 doesn't make sense in 5.4 anymore. * Link to `configureContainer` was dead anyway. --- configuration.rst | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/configuration.rst b/configuration.rst index 6d2638008fa..bf00e080262 100644 --- a/configuration.rst +++ b/configuration.rst @@ -60,13 +60,11 @@ configure your applications. Symfony lets you choose between YAML, XML and PHP and throughout the Symfony documentation, all configuration examples will be shown in these three formats. -.. versionadded:: 5.1 +.. note:: - Starting from Symfony 5.1, by default Symfony only loads the configuration + By default, Symfony only loads the configuration files defined in YAML format. If you define configuration in XML and/or PHP - formats, update the ``src/Kernel.php`` file to add support for the ``.xml`` - and ``.php`` file extensions by overriding the - :method:`Symfony\\Component\\HttpKernel\\Kernel::configureContainer` method:: + formats, update the ``src/Kernel.php`` file:: // src/Kernel.php use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; @@ -93,8 +91,8 @@ shown in these three formats. } There isn't any practical difference between formats. In fact, Symfony -transforms and caches all of them into PHP before running the application, so -there's not even any performance difference between them. +transforms all of them into PHP and caches them before running the application, so +there's not even any performance difference. YAML is used by default when installing packages because it's concise and very readable. These are the main advantages and disadvantages of each format: From 3d9dfe669f4557cc10d0ae0b188151113e736334 Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Fri, 7 Apr 2023 17:09:46 +0200 Subject: [PATCH 004/205] [DependencyInjection] Document ServiceConfigurator remove method --- service_container/remove.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 service_container/remove.rst diff --git a/service_container/remove.rst b/service_container/remove.rst new file mode 100644 index 00000000000..da4fbf2e54e --- /dev/null +++ b/service_container/remove.rst @@ -0,0 +1,23 @@ +How to Remove a Service +======================= + +A service can be removed from the service container if needed +(for instance in the test or a specific environment): + +.. configuration-block:: + + .. code-block:: php + + // config/services_test.php + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + use App\RemovedService; + + return function(ContainerConfigurator $containerConfigurator) { + $services = $containerConfigurator->services(); + + $services->remove(RemovedService::class); + }; + +Now, the container will not contain the ``App\RemovedService`` +in the test environment. From 09d44cb4931c9572941799331ebbe26e012a72f3 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 11 Apr 2023 18:13:38 +0200 Subject: [PATCH 005/205] Adding more details on `action` and `method` --- forms.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/forms.rst b/forms.rst index 17223e15e10..a78eb2f4fe5 100644 --- a/forms.rst +++ b/forms.rst @@ -755,8 +755,9 @@ Set the ``label`` option on fields to define their labels explicitly:: Changing the Action and HTTP Method ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -By default, a form will be submitted via an HTTP POST request to the same -URL under which the form was rendered. When building the form in the controller, +By default, the ``
`` tag will be rendered with a ``method="post"`` attribute, +and no ``action`` attribute, causing it to be submitted via an HTTP POST request to the same +URL under which it was rendered. When building the form, use the ``setAction()`` and ``setMethod()`` methods to change this:: // src/Controller/TaskController.php From 2e55bdadcb86479328bf09aea2d9f79b0a1643f4 Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Wed, 12 Apr 2023 23:47:39 +0200 Subject: [PATCH 006/205] Flex private recipes with Gitlab --- setup/flex_private_recipes.rst | 101 +++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 6 deletions(-) diff --git a/setup/flex_private_recipes.rst b/setup/flex_private_recipes.rst index 5941ba2908f..14300e70258 100644 --- a/setup/flex_private_recipes.rst +++ b/setup/flex_private_recipes.rst @@ -8,7 +8,7 @@ private Symfony Flex recipe repositories, and seamlessly integrate them into the This is particularly useful when you have private bundles or packages that must perform their own installation tasks. To do this, you need to complete several steps: -* Create a private GitHub repository; +* Create a private repository; * Create your private recipes; * Create an index to the recipes; * Store your recipes in the private repository; @@ -16,14 +16,26 @@ perform their own installation tasks. To do this, you need to complete several s * Configure your project's ``composer.json`` file; and * Install the recipes in your project. -Create a Private GitHub Repository ----------------------------------- +.. _create-a-private-github-repository + +Create a Private Repository +--------------------------- + +GitHub +~~~~~~ Log in to your GitHub.com account, click your account icon in the top-right corner, and select **Your Repositories**. Then click the **New** button, fill in the **repository name**, select the **Private** radio button, and click the **Create Repository** button. +Gitlab +~~~~~~ + +Log in to your Gitlab.com account, click the **New project** button, select **Create blank project**, fill in +the **Project name**, select the **Private** radio button, and click the +**Create project** button. + Create Your Private Recipes --------------------------- @@ -124,6 +136,9 @@ Create an Index to the Recipes The next step is to create an ``index.json`` file, which will contain entries for all your private recipes, and other general configuration information. +GitHub +~~~~~~ + The ``index.json`` file has the following format: .. code-block:: json @@ -134,11 +149,11 @@ The ``index.json`` file has the following format: "1.0" ] }, - "branch": "master", + "branch": "main", "is_contrib": true, "_links": { "repository": "github.com/your-github-account-name/your-recipes-repository", - "origin_template": "{package}:{version}@github.com/your-github-account-name/your-recipes-repository:master", + "origin_template": "{package}:{version}@github.com/your-github-account-name/your-recipes-repository:main", "recipe_template": "https://api.github.com/repos/your-github-account-name/your-recipes-repository/contents/{package_dotted}.{version}.json" } } @@ -146,15 +161,43 @@ The ``index.json`` file has the following format: Create an entry in ``"recipes"`` for each of your bundle recipes. Replace ``your-github-account-name`` and ``your-recipes-repository`` with your own details. +Gitlab +~~~~~~ + +The ``index.json`` file has the following format: + +.. code-block:: json + + { + "recipes": { + "acme/private-bundle": [ + "1.0" + ] + }, + "branch": "main", + "is_contrib": true, + "_links": { + "repository": "gitlab.com/your-gitlab-account-name/your-recipes-repository", + "origin_template": "{package}:{version}@gitlab.com/your-gitlab-account-name/your-recipes-repository:main", + "recipe_template": "https://gitlab.com/api/v4/projects/your-gitlab-project-id/repository/files/{package_dotted}.{version}.json/raw?ref=main" + } + } + +Create an entry in ``"recipes"`` for each of your bundle recipes. Replace +``your-gitlab-account-name``, ``your-gitlab-repository`` and ``your-gitlab-project-id`` with your own details. + Store Your Recipes in the Private Repository -------------------------------------------- Upload the recipe ``.json`` file(s) and the ``index.json`` file into the root -directory of your private GitHub repository. +directory of your private repository. Grant ``composer`` Access to the Private Repository --------------------------------------------------- +GitHub +~~~~~~ + In your GitHub account, click your account icon in the top-right corner, select ``Settings`` and ``Developer Settings``. Then select ``Personal Access Tokens``. @@ -168,9 +211,29 @@ computer, and execute the following command: Replace ``[token]`` with the value of your GitHub personal access token. +Gitlab +~~~~~~ + +In your Gitlab account, click your account icon in the top-right corner, select +``Preferences`` and ``Access Tokens``. + +Generate a new personal access token with ``read_api`` and ``read_repository`` +scopes. Copy the access token value, switch to the terminal of your local +computer, and execute the following command: + +.. code-block:: terminal + + $ composer config --global --auth gitlab-oauth.gitlab.com [token] + +Replace ``[token]`` with the value of your Gitlab personal access token. + + Configure Your Project's ``composer.json`` File ----------------------------------------------- +GitHub +~~~~~~ + Add the following to your project's ``composer.json`` file: .. code-block:: json @@ -199,6 +262,32 @@ Replace ``your-github-account-name`` and ``your-recipes-repository`` with your o The ``endpoint`` URL **must** point to ``https://api.github.com/repos`` and **not** to ``https://www.github.com``. +Gitlab +~~~~~~ + +Add the following to your project's ``composer.json`` file: + +.. code-block:: json + + { + "extra": { + "symfony": { + "endpoint": [ + "https://gitlab.com/api/v4/projects/your-gitlab-project-id/repository/files/index.json/raw?ref=main", + "flex://defaults" + ] + } + } + } + +Replace ``your-gitlab-project-id`` with your own details. + +.. tip:: + + The ``extra.symfony`` key will most probably already exist in your + ``composer.json``. In that case, add the ``"endpoint"`` key to the existing + ``extra.symfony`` entry. + Install the Recipes in Your Project ----------------------------------- From 173203c187bd805a171a94218b06a0427374feb5 Mon Sep 17 00:00:00 2001 From: Matthieu Lempereur Date: Tue, 18 Apr 2023 17:43:17 +0200 Subject: [PATCH 007/205] improve links label in rememberMe doc --- security/remember_me.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/security/remember_me.rst b/security/remember_me.rst index 58fbeb6e959..1d69cc9a555 100644 --- a/security/remember_me.rst +++ b/security/remember_me.rst @@ -266,12 +266,14 @@ Signature based tokens By default, the remember me cookie contains a signature based on properties of the user. If the properties change, the signature changes and already generated tokens are no longer considered valid. See - :ref:`security-remember-me-signature` for more information. + :ref:`how to use them ` for more + information. Persistent tokens Persistent tokens store any generated token (e.g. in a database). This allows you to invalidate tokens by changing the rows in the database. - See :ref:`security-remember-me-persistent` for more information. + See :ref:`how to store tokens ` for more + information. .. note:: From 7b5868bade8bd79cd8f3be46011ef00bee3ad94d Mon Sep 17 00:00:00 2001 From: Yannick Date: Thu, 20 Apr 2023 10:36:09 +0200 Subject: [PATCH 008/205] Update dynamic_form_modification.rst Hi mates, The JavaScript parts use jQuery and, IMHO, it's not relevant. Also, performing an Ajax request is easier since fetch is available for JavaScript. That's why I propose this piece of code. Also, to use `form.getAttribute('action')` , you must manually define the URL called by the form. To do this, I give a third parameter to `createForm` and I set the action value in `SportMeetupType` with `$builder->setAction()` Yannick --- form/dynamic_form_modification.rst | 67 ++++++++++++++++++------------ 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/form/dynamic_form_modification.rst b/form/dynamic_form_modification.rst index 0911a40f999..0d321880cb3 100644 --- a/form/dynamic_form_modification.rst +++ b/form/dynamic_form_modification.rst @@ -447,7 +447,7 @@ The type would now look like:: class SportMeetupType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void - { + { $builder ->add('sport', EntityType::class, [ 'class' => Sport::class, @@ -487,6 +487,10 @@ The type would now look like:: $formModifier($event->getForm()->getParent(), $sport); } ); + + // by default, action does not appear in the form tag + // you can set this value by passing the controller route + $builder->setAction($options['action']); } // ... @@ -518,10 +522,11 @@ your application. Assume that you have a sport meetup creation controller:: class MeetupController extends AbstractController { + #[Route('/create', name: 'app_meetup_create', methods: ['GET', 'POST'])] public function create(Request $request): Response { $meetup = new SportMeetup(); - $form = $this->createForm(SportMeetupType::class, $meetup); + $form = $this->createForm(SportMeetupType::class, $meetup, ['action' => $this->generateUrl('app_meetup_create')]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { // ... save the meetup, redirect etc. @@ -541,36 +546,46 @@ field according to the current selection in the ``sport`` field: .. code-block:: html+twig {# templates/meetup/create.html.twig #} - {{ form_start(form) }} + {{ form_start(form, { 'attr' : { 'id' : 'supply_history_form' } }) }} {{ form_row(form.sport) }} {# ``) + +When using these helpers, you must write all the HTML contents for all form fields, which some people prefer to better +control the generated HTML without having to deal with form themes: + +.. code-block:: html+twig + + + + + +.. versionadded:: 5.2 + + The ``field_*()`` helpers were introduced in Symfony 5.2. + Form Rendering Variables ------------------------ diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index 38d96910fd2..0ee70b0929d 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -365,6 +365,12 @@ explained in the article about :doc:`customizing form rendering ` * :ref:`form_row() ` * :ref:`form_rest() ` +* :ref:`field_name() ` +* :ref:`field_value() ` +* :ref:`field_label() ` +* :ref:`field_help() ` +* :ref:`field_errors() ` +* :ref:`field_choices() ` .. _reference-twig-filters: From 8578924939c1ebe1ccdd0cdd88581c772998f3e1 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 4 May 2023 15:31:55 +0200 Subject: [PATCH 023/205] Tweaks --- form/form_customization.rst | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/form/form_customization.rst b/form/form_customization.rst index 9db536dfbd6..87be104c7f1 100644 --- a/form/form_customization.rst +++ b/form/form_customization.rst @@ -92,22 +92,23 @@ control over how each form field is rendered, so you can fully customize them: Form Field Helpers ------------------ -The ``form_*()`` helpers render each part of the form field, including all its needed HTML elements. Most developers -like this behavior, but some designers struggle with it, because it hides all the HTML in form themes which are not -easy to manage by them. - -That's why some Twig form helpers are available to render the value of each form field part without adding any -HTML around it: - -* ``field_name`` -* ``field_value`` -* ``field_label`` -* ``field_help`` -* ``field_errors`` -* ``field_choices`` (an iterator of the field choices; e.g. for ````) + +When using these helpers, you must write all the HTML contents for all form +fields, so you no longer have to deal with form themes: .. code-block:: html+twig From b3bc5aca3e6fa3f7c5d0c2b52f334cc2d28a0be5 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 18 Apr 2023 17:03:05 +0200 Subject: [PATCH 024/205] Don't use double backquotes in the comments --- .../cache/adapters/array_cache_adapter.rst | 2 +- event_dispatcher.rst | 2 +- service_container/autowiring.rst | 20 +++++++++---------- testing.rst | 5 ++--- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/components/cache/adapters/array_cache_adapter.rst b/components/cache/adapters/array_cache_adapter.rst index 7429593f993..1d8cd87269a 100644 --- a/components/cache/adapters/array_cache_adapter.rst +++ b/components/cache/adapters/array_cache_adapter.rst @@ -15,7 +15,7 @@ method:: // until the current PHP process finishes) $defaultLifetime = 0, - // if ``true``, the values saved in the cache are serialized before storing them + // if true, the values saved in the cache are serialized before storing them $storeSerialized = true, // the maximum lifetime (in seconds) of the entire cache (after this time, the diff --git a/event_dispatcher.rst b/event_dispatcher.rst index ae13f5d61a6..c04e309eb46 100644 --- a/event_dispatcher.rst +++ b/event_dispatcher.rst @@ -796,7 +796,7 @@ could listen to the ``mailer.post_send`` event and change the method's return va public function onMailerPostSend(AfterSendMailEvent $event) { $returnValue = $event->getReturnValue(); - // modify the original ``$returnValue`` value + // modify the original $returnValue value $event->setReturnValue($returnValue); } diff --git a/service_container/autowiring.rst b/service_container/autowiring.rst index 39fa1ba5299..60baa01b261 100644 --- a/service_container/autowiring.rst +++ b/service_container/autowiring.rst @@ -216,8 +216,8 @@ adding a service alias: # ... # but this fixes it! - # the ``app.rot13.transformer`` service will be injected when - # an ``App\Util\Rot13Transformer`` type-hint is detected + # the "app.rot13.transformer" service will be injected when + # an App\Util\Rot13Transformer type-hint is detected App\Util\Rot13Transformer: '@app.rot13.transformer' .. code-block:: xml @@ -251,8 +251,8 @@ adding a service alias: ->autowire(); // but this fixes it! - // the ``app.rot13.transformer`` service will be injected when - // an ``App\Util\Rot13Transformer`` type-hint is detected + // the "app.rot13.transformer" service will be injected when + // an App\Util\Rot13Transformer type-hint is detected $services->alias(Rot13Transformer::class, 'app.rot13.transformer'); }; @@ -355,8 +355,8 @@ To fix that, add an :ref:`alias `: $services->set(Rot13Transformer::class); - // the ``App\Util\Rot13Transformer`` service will be injected when - // an ``App\Util\TransformerInterface`` type-hint is detected + // the App\Util\Rot13Transformer service will be injected when + // an App\Util\TransformerInterface type-hint is detected $services->alias(TransformerInterface::class, Rot13Transformer::class); }; @@ -526,13 +526,13 @@ the injection:: $services->set(Rot13Transformer::class)->autowire(); $services->set(UppercaseTransformer::class)->autowire(); - // the ``App\Util\UppercaseTransformer`` service will be - // injected when an ``App\Util\TransformerInterface`` - // type-hint for a ``$shoutyTransformer`` argument is detected. + // the App\Util\UppercaseTransformer service will be + // injected when an App\Util\TransformerInterface + // type-hint for a $shoutyTransformer argument is detected. $services->alias(TransformerInterface::class.' $shoutyTransformer', UppercaseTransformer::class); // If the argument used for injection does not match, but the - // type-hint still matches, the ``App\Util\Rot13Transformer`` + // type-hint still matches, the App\Util\Rot13Transformer // service will be injected. $services->alias(TransformerInterface::class, Rot13Transformer::class); diff --git a/testing.rst b/testing.rst index c7885328242..3ca9f5e6e8a 100644 --- a/testing.rst +++ b/testing.rst @@ -566,11 +566,10 @@ In the above example, the test validates that the HTTP response was successful and the request body contains a ``

`` tag with ``"Hello world"``. The ``request()`` method also returns a crawler, which you can use to -create more complex assertions in your tests:: +create more complex assertions in your tests (e.g. to count the number of page +elements that match a given CSS selector):: $crawler = $client->request('GET', '/post/hello-world'); - - // for instance, count the number of ``.comment`` elements on the page $this->assertCount(4, $crawler->filter('.comment')); You can learn more about the crawler in :doc:`/testing/dom_crawler`. From f1698a449d2446c5f1615b232595a29b1740c84e Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Mon, 10 Apr 2023 21:01:00 -0400 Subject: [PATCH 025/205] Revamping Multiple Kernels documentation --- configuration/multiple_kernels.rst | 467 +++++++++++++++++++---------- 1 file changed, 306 insertions(+), 161 deletions(-) diff --git a/configuration/multiple_kernels.rst b/configuration/multiple_kernels.rst index dc7e4c5b390..12ebaf67eda 100644 --- a/configuration/multiple_kernels.rst +++ b/configuration/multiple_kernels.rst @@ -1,244 +1,389 @@ -How To Create Symfony Applications with Multiple Kernels -======================================================== +How to Create Multiple Symfony Applications with a Single Kernel +================================================================ -.. caution:: +In most Symfony applications, incoming requests are processed by the front controller at ``public/index.php``, which +instantiates the ``src/Kernel.php`` class to create the application kernel. This kernel loads the bundles, configurations, +and handles the request to generate the response. - Creating applications with multiple kernels is no longer recommended by - Symfony. Consider creating multiple small applications instead. +The current implementation of the Kernel class serves as a convenient default for a single application. However, it can +also manage multiple applications. While the Kernel typically runs the same application with different configurations +based on various :ref:`environments ` , it can be adapted to run different applications with +specific bundles and configurations. -In most Symfony applications, incoming requests are processed by the -``public/index.php`` front controller, which instantiates the ``src/Kernel.php`` -class to create the application kernel that loads the bundles and handles the -request to generate the response. +These are some of the common use cases for creating multiple applications with a single Kernel: -This single kernel approach is a convenient default, but Symfony applications -can define any number of kernels. Whereas -:ref:`environments ` run the same application with -different configurations, kernels can run different parts of the same -application. +* An application that defines an API can be divided into two segments to improve performance. The first segment serves + the regular web application, while the second segment exclusively responds to API requests. This approach requires + loading fewer bundles and enabling fewer features for the second part, thus optimizing performance; +* A highly sensitive application could be divided into two parts for enhanced security. The first part would only load + routes corresponding to the publicly exposed sections of the application. The second part would load the remainder of + the application, with its access safeguarded by the web server; +* A monolithic application could be gradually transformed into a more distributed architecture, such as micro-services. + This approach allows for a seamless migration of a large application while still sharing common configurations and + components. -These are some of the common use cases for creating multiple kernels: +Turning a Single Application into Multiple Applications +------------------------------------------------------- -* An application that defines an API could define two kernels for performance - reasons. The first kernel would serve the regular application and the second - one would only respond to the API requests, loading less bundles and enabling - less features; -* A highly sensitive application could define two kernels. The first one would - only load the routes that match the parts of the application exposed publicly. - The second kernel would load the rest of the application and its access would - be protected by the web server; -* A micro-services oriented application could define several kernels to - enable/disable services selectively turning a traditional monolith application - into several micro-applications. +Let's explore the steps required to convert a single application into a new one that supports multiple applications: -Adding a new Kernel to the Application --------------------------------------- +1. Create a new application; +2. Update the Kernel class to support multiple applications; +3. Add a new ``APP_ID`` environment variable; +4. Update the front controllers. -Creating a new kernel in a Symfony application is a three-step process: +The following example shows how to create a new application for the API of a new Symfony project. -1. Create a new front controller to load the new kernel; -2. Create the new kernel class; -3. Define the configuration loaded by the new kernel. +Step 1) Create a new Application +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The following example shows how to create a new kernel for the API of a given -Symfony application. +In this example, we will use the `Shared Kernel`_ pattern, where, although all applications maintain an isolated context, +they can share common bundles, configurations, and code if desired. The optimal approach will depend on your specific +needs and requirements, so it's up to you to decide which best suits your project. -Step 1) Create a new Front Controller -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +First, let's create a new ``apps`` directory at the root of your project, which will hold all the necessary applications. +Each application will follow a simplified directory structure like the one described in :ref:`Symfony Best Practice `: -Instead of creating the new front controller from scratch, it's easier to -duplicate the existing one. For example, create ``public/api.php`` from -``public/index.php``. +.. code-block:: text -Then, update the code of the new front controller to instantiate the new kernel -class instead of the usual ``Kernel`` class:: + your-project/ + ├─ apps/ + │ └─ api/ + │ ├─ config/ + │ │ ├─ bundles.php + │ │ ├─ routes.yaml + │ │ └─ services.yaml + │ └─ src/ + ├─ bin/ + │ └─ console + ├─ config/ + ├─ public/ + │ └─ index.php + ├─ src/ + │ └─ Kernel.php - // public/api.php - // ... - $kernel = new ApiKernel( - $_SERVER['APP_ENV'] ?? 'dev', - $_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev')) - ); - // ... +.. note:: + + Note that the ``config/`` and ``src/`` directories at the root of the project will represent the shared context among + all applications within the ``apps/`` directory. Therefore, you should carefully consider what is common and what + should be placed in the specific application. .. tip:: - Another approach is to keep the existing ``index.php`` front controller, but - add an ``if`` statement to load the different kernel based on the URL (e.g. - if the URL starts with ``/api``, use the ``ApiKernel``). + You might also consider renaming the namespace for the shared context, from ``App`` to ``Shared``, as it will make it + easier to distinguish and provide clearer meaning to this context. -Step 2) Create the new Kernel Class -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Since the new ``apps/api/src/`` directory will host the PHP code related to the API, we need to update the ``composer.json`` +file to include it in the autoload section: -Now you need to define the ``ApiKernel`` class used by the new front controller. -The easiest way to do this is by duplicating the existing ``src/Kernel.php`` -file and make the needed changes. +.. code-block:: json -In this example, the ``ApiKernel`` will load fewer bundles than the default -Kernel. Be sure to also change the location of the cache, logs and configuration -files so they don't collide with the files from ``src/Kernel.php``:: + { + "autoload": { + "psr-4": { + "Shared\\": "src/", + "Api\\": "apps/api/src/" + } + } + } - // src/ApiKernel.php - use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; - use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; - use Symfony\Component\HttpKernel\Kernel as BaseKernel; - use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; +Additionally, don't forget to run `composer dump-autoload` to generate the autoload files. - class ApiKernel extends Kernel +Step 2) Update the Kernel class to support Multiple Applications +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Since we aim to support multiple applications, we will add a new property ``string $id`` to the Kernel to identify the +application being loaded. This property will also allow us to split the cache, logs, and configuration files in order to +avoid collisions with other applications. Moreover, it contributes to performance optimization, as each application will +load only the required resources:: + + // src/Kernel.php + namespace Shared; + + // ... + + class Kernel extends BaseKernel { use MicroKernelTrait; - public function getProjectDir(): string + public function __construct(string $environment, bool $debug, private string $id) + { + parent::__construct($environment, $debug); + } + + public function getSharedConfigDir(): string + { + return $this->getProjectDir().'/config'; + } + + public function getAppConfigDir(): string + { + return $this->getProjectDir().'/apps/'.$this->id.'/config'; + } + + public function registerBundles(): iterable { - return \dirname(__DIR__); + $sharedBundles = require $this->getSharedConfigDir().'/bundles.php'; + $appBundles = require $this->getAppConfigDir().'/bundles.php'; + + // load common bundles, such as the FrameworkBundle, as well as + // specific bundles required exclusively for the app itself + foreach (array_merge($sharedBundles, $appBundles) as $class => $envs) { + if ($envs[$this->environment] ?? $envs['all'] ?? false) { + yield new $class(); + } + } } public function getCacheDir(): string { - return $this->getProjectDir().'/var/cache/api/'.$this->environment; + // divide cache for each application + return ($_SERVER['APP_CACHE_DIR'] ?? $this->getProjectDir().'/var/cache').'/'.$this->id.'/'.$this->environment; } public function getLogDir(): string { - return $this->getProjectDir().'/var/log/api'; + // divide logs for each application + return ($_SERVER['APP_LOG_DIR'] ?? $this->getProjectDir().'/var/log').'/'.$this->id; } - protected function configureContainer(ContainerConfigurator $containerConfigurator): void + protected function configureContainer(ContainerConfigurator $container): void { - $containerConfigurator->import('../config/api/{packages}/*.yaml'); - $containerConfigurator->import('../config/api/{packages}/'.$this->environment.'/*.yaml'); - - if (is_file(\dirname(__DIR__).'/config/api/services.yaml')) { - $containerConfigurator->import('../config/api/services.yaml'); - $containerConfigurator->import('../config/api/{services}_'.$this->environment.'.yaml'); - } else { - $containerConfigurator->import('../config/api/{services}.php'); - } + // load common config files, such as the framework.yaml, as well as + // specific configs required exclusively for the app itself + $this->doConfigureContainer($container, $this->getSharedConfigDir()); + $this->doConfigureContainer($container, $this->getAppConfigDir()); } protected function configureRoutes(RoutingConfigurator $routes): void { - $routes->import('../config/api/{routes}/'.$this->environment.'/*.yaml'); - $routes->import('../config/api/{routes}/*.yaml'); - // ... load only the config routes strictly needed for the API + // load common routes files, such as the routes/framework.yaml, as well as + // specific routes required exclusively for the app itself + $this->doConfigureRoutes($routes, $this->getSharedConfigDir()); + $this->doConfigureRoutes($routes, $this->getAppConfigDir()); } - // If you need to run some logic to decide which bundles to load, - // you might prefer to use the registerBundles() method instead - private function getBundlesPath(): string + private function doConfigureContainer(ContainerConfigurator $container, string $configDir): void { - // load only the bundles strictly needed for the API - return $this->getProjectDir().'/config/api_bundles.php'; + $container->import($configDir.'/{packages}/*.{php,yaml}'); + $container->import($configDir.'/{packages}/'.$this->environment.'/*.{php,yaml}'); + + if (is_file($configDir.'/services.yaml')) { + $container->import($configDir.'/services.yaml'); + $container->import($configDir.'/{services}_'.$this->environment.'.yaml'); + } else { + $container->import($configDir.'/{services}.php'); + } + } + + private function doConfigureRoutes(RoutingConfigurator $routes, string $configDir): void + { + $routes->import($configDir.'/{routes}/'.$this->environment.'/*.{php,yaml}'); + $routes->import($configDir.'/{routes}/*.{php,yaml}'); + + if (is_file($configDir.'/routes.yaml')) { + $routes->import($configDir.'/routes.yaml'); + } else { + $routes->import($configDir.'/{routes}.php'); + } + + if (false !== ($fileName = (new \ReflectionObject($this))->getFileName())) { + $routes->import($fileName, 'annotation'); + } } } -.. versionadded:: 5.4 +In this example, we reuse the default implementation to import configuration and routes based on a given configuration +directory. As we saw earlier, this approach will import both shared and app-specific resources. - The ``getBundlesPath()`` method was introduced in Symfony 5.4. +Step 3) Add a new APP_ID environment variable +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Step 3) Define the Kernel Configuration -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Now, let's introduce a new environment variable that identifies the current application. This new variable can be added +to the ``.env`` file to provide a default value, but it should typically be added to your web server configuration. -Finally, define the configuration files that the new ``ApiKernel`` will load. -According to the above code, this config will live in one or multiple files -stored in ``config/api/`` and ``config/api/ENVIRONMENT_NAME/`` directories. +.. code-block:: bash -The new configuration files can be created from scratch when you load only a few -bundles, because it will be small. Otherwise, duplicate the existing -config files in ``config/packages/`` or better, import them and override the -needed options. + # .env + APP_ID=api -Executing Commands with a Different Kernel ------------------------------------------- +.. caution:: -The ``bin/console`` script used to run Symfony commands always uses the default -``Kernel`` class to build the application and load the commands. If you need -to run console commands using the new kernel, duplicate the ``bin/console`` -script and rename it (e.g. ``bin/api``). + The value of this variable must match the application directory within ``apps/`` as it is used in the Kernel to load + the specific application configuration. -Then, replace the ``Kernel`` instance by your own kernel instance -(e.g. ``ApiKernel``). Now you can run commands using the new kernel -(e.g. ``php bin/api cache:clear``). +Step 4) Update the Front Controllers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. note:: +In this final step, we will update the front controllers ``public/index.php`` and ``bin/console`` to pass the value of +the ``APP_ID`` variable to the Kernel instance. This will allow the Kernel to load and run the specified application:: - The commands available for each console script (e.g. ``bin/console`` and - ``bin/api``) can differ because they depend on the bundles enabled for each - kernel, which could be different. + // public/index.php + use Shared\Kernel; + // ... + + return function (array $context) { + return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG'], $context['APP_ID']); + }; + +Similar to configuring the required ``APP_ENV`` and ``APP_DEBUG`` values, the third argument of the Kernel constructor +is now also necessary to setting the application ID, which is derived from an external configuration. + +For the second front controller, we will define a new console option to allow passing the application ID we want to run +under CLI context:: + + // bin/console + use Shared\Kernel; + // ... + + return function (InputInterface $input, array $context) { + $kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG'], $input->getParameterOption(['--id', '-i'], $context['APP_ID'])); + + $application = new Application($kernel); + $application->getDefinition() + ->addOption(new InputOption('--id', '-i', InputOption::VALUE_REQUIRED, 'The App ID')) + ; + + return $application; + }; + +That's it! + +Executing Commands +------------------ + +The ``bin/console`` script, which is used to run Symfony commands, always uses the ``Kernel`` class to build the +application and load the commands. If you need to run console commands for a specific application, you can provide the +``--id`` option along with the appropriate identity value: + +.. code-block:: terminal + + php bin/console cache:clear --id=api + // or + php bin/console cache:clear -iapi + + // alternatively + export APP_ID=api + php bin/console cache:clear + +You might want to update the composer auto-scripts section to run multiple commands simultaneously. In this example, +we assume you have a second application for managing the configuration (admin): + +.. code-block:: json + + { + "scripts": { + "auto-scripts": { + "cache:clear -iapi": "symfony-cmd", + "cache:clear -iadmin": "symfony-cmd", + "assets:install %PUBLIC_DIR% -iapi": "symfony-cmd", + "assets:install %PUBLIC_DIR% -iadmin --no-cleanup": "symfony-cmd" + } + } + } + +Then, run `composer auto-scripts` to test it! + +.. note:: -Rendering Templates Defined in a Different Kernel -------------------------------------------------- + The commands available for each console script (e.g. ``bin/console -iapi`` and ``bin/console -iadmin``) can differ + because they depend on the bundles enabled for each application, which could be different. -If you follow the Symfony Best Practices, the templates of the default kernel -will be stored in ``templates/``. Trying to render those templates in a -different kernel will result in a *There are no registered paths for namespace -"__main__"* error. +Rendering Templates +------------------- -In order to solve this issue, add the following configuration to your kernel: +Let's assume there is now another app called ``admin``. If you follow the :ref:`Symfony Best Practices `, the shared Kernel +templates will be located in the ``templates/`` directory at the project's root. For admin-specific templates, you can +create a new directory ``apps/admin/templates/`` which you will need to manually configure under the Admin application: .. code-block:: yaml - # config/api/twig.yaml + # apps/admin/config/packages/twig.yaml twig: paths: - # allows to use api/templates/ dir in the ApiKernel - "%kernel.project_dir%/api/templates": ~ + '%kernel.project_dir%/apps/admin/templates': Admin + +Then, use this Twig namespace to reference any template within the Admin application only, for example ``@Admin/form/fields.html.twig``. -Running Tests Using a Different Kernel --------------------------------------- +Running Tests +------------- -In Symfony applications, functional tests extend by default from the -:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\WebTestCase` class. Inside that -class, a method called ``getKernelClass()`` tries to find the class of the kernel -to use to run the application during tests. The logic of this method does not -support multiple kernel applications, so your tests won't use the right kernel. +In Symfony applications, functional tests typically extend from the :class:`Symfony\\Bundle\\FrameworkBundle\\Test\\WebTestCase` +class by default. Within its parent class, ``KernelTestCase``, there is a method called ``createKernel()`` that attempts to +create the kernel responsible for running the application during tests. However, the current logic of this method doesn't +include our new application ID argument, so we need to make an update:: -The solution is to create a custom base class for functional tests extending -from ``WebTestCase`` class and overriding the ``getKernelClass()`` method to -return the fully qualified class name of the kernel to use:: + // apps/api/tests/ApiTestCase.php + namespace Api\Tests; + use Shared\Kernel; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + use Symfony\Component\HttpKernel\KernelInterface; - // tests needing the ApiKernel to work, now must extend this - // ApiTestCase class instead of the default WebTestCase class class ApiTestCase extends WebTestCase { - protected static function getKernelClass() + protected static function createKernel(array $options = []): KernelInterface { - return 'App\ApiKernel'; + $env = $options['environment'] ?? $_ENV['APP_ENV'] ?? $_SERVER['APP_ENV'] ?? 'test'; + $debug = $options['debug'] ?? (bool) ($_ENV['APP_DEBUG'] ?? $_SERVER['APP_DEBUG'] ?? true); + + return new Kernel($env, $debug, 'api'); } + } - // this is needed because the KernelTestCase class keeps a reference to - // the previously created kernel in its static $kernel property. Thus, - // if your functional tests do not run in isolated processes, a later run - // test for a different kernel will reuse the previously created instance, - // which points to a different kernel - protected function tearDown() - { - parent::tearDown(); +.. note:: + + Keep in mind that we will set a fixed application ID value in this instance, as the specific test cases extending + from ``ApiTestCase`` will focus solely on the ``api`` tests. + +In this situation, we have created a ``tests/`` directory inside the ``apps/api/`` application. As a result, we need to +inform both the ``composer.json`` file and our ``phpunit.xml`` configuration about its existence: - static::$class = null; +.. code-block:: json + + { + "autoload-dev": { + "psr-4": { + "Shared\\Tests\\": "tests/", + "Api\\Tests\\": "apps/api/tests/" + } } } -Adding more Kernels to the Application --------------------------------------- +Remember to run ``composer dump-autoload`` to generate the autoload files. + +And, here is the update needed for the ``phpunit.xml`` file: + +.. code-block:: xml -If your application is very complex and you create several kernels, it's better -to store them in their own directories instead of messing with lots of files in -the default ``src/`` directory: + + + tests + + + apps/api/tests + + + +Adding more Applications +------------------------ + +Now you can begin adding more applications as needed, such as an ``admin`` application to manage the project's +configuration and permissions. To do that, you will have to repeat the step 1 only: .. code-block:: text - project/ - ├─ src/ - │ ├─ ... - │ └─ Kernel.php - ├─ api/ - │ ├─ ... - │ └─ ApiKernel.php - ├─ ... - └─ public/ - ├─ ... - ├─ api.php - └─ index.php + your-project/ + ├─ apps/ + │ ├─ admin/ + │ │ ├─ config/ + │ │ │ ├─ bundles.php + │ │ │ ├─ routes.yaml + │ │ │ └─ services.yaml + │ │ └─ src/ + │ └─ api/ + │ └─ ... + +Additionally, you might need to update your web server configuration to set the ``APP_ID=admin`` under a different domain. + +.. _`Shared Kernel`: http://ddd.fed.wiki.org/view/shared-kernel From b3bee8e81626f0d7ae17979f4aa9a27d0c988087 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 4 May 2023 16:35:20 +0200 Subject: [PATCH 026/205] Minor tweaks --- configuration/multiple_kernels.rst | 181 +++++++++++++++++------------ 1 file changed, 108 insertions(+), 73 deletions(-) diff --git a/configuration/multiple_kernels.rst b/configuration/multiple_kernels.rst index 12ebaf67eda..1b8504e0748 100644 --- a/configuration/multiple_kernels.rst +++ b/configuration/multiple_kernels.rst @@ -1,48 +1,59 @@ How to Create Multiple Symfony Applications with a Single Kernel ================================================================ -In most Symfony applications, incoming requests are processed by the front controller at ``public/index.php``, which -instantiates the ``src/Kernel.php`` class to create the application kernel. This kernel loads the bundles, configurations, -and handles the request to generate the response. - -The current implementation of the Kernel class serves as a convenient default for a single application. However, it can -also manage multiple applications. While the Kernel typically runs the same application with different configurations -based on various :ref:`environments ` , it can be adapted to run different applications with -specific bundles and configurations. - -These are some of the common use cases for creating multiple applications with a single Kernel: - -* An application that defines an API can be divided into two segments to improve performance. The first segment serves - the regular web application, while the second segment exclusively responds to API requests. This approach requires - loading fewer bundles and enabling fewer features for the second part, thus optimizing performance; -* A highly sensitive application could be divided into two parts for enhanced security. The first part would only load - routes corresponding to the publicly exposed sections of the application. The second part would load the remainder of - the application, with its access safeguarded by the web server; -* A monolithic application could be gradually transformed into a more distributed architecture, such as micro-services. - This approach allows for a seamless migration of a large application while still sharing common configurations and - components. +In Symfony applications, incoming requests are usually processed by the front +controller at ``public/index.php``, which instantiates the ``src/Kernel.php`` +class to create the application kernel. This kernel loads the bundles, the +configuration, and handles the request to generate the response. + +The current implementation of the Kernel class serves as a convenient default +for a single application. However, it can also manage multiple applications. +While the Kernel typically runs the same application with different +configurations based on various :ref:`environments `, +it can be adapted to run different applications with specific bundles and configuration. + +These are some of the common use cases for creating multiple applications with a +single Kernel: + +* An application that defines an API can be divided into two segments to improve + performance. The first segment serves the regular web application, while the + second segment exclusively responds to API requests. This approach requires + loading fewer bundles and enabling fewer features for the second part, thus + optimizing performance; +* A highly sensitive application could be divided into two parts for enhanced + security. The first part would only load routes corresponding to the publicly + exposed sections of the application. The second part would load the remainder + of the application, with its access safeguarded by the web server; +* A monolithic application could be gradually transformed into a more + distributed architecture, such as micro-services. This approach allows for a + seamless migration of a large application while still sharing common + configurations and components. Turning a Single Application into Multiple Applications ------------------------------------------------------- -Let's explore the steps required to convert a single application into a new one that supports multiple applications: +These are the steps required to convert a single application into a new one that +supports multiple applications: 1. Create a new application; 2. Update the Kernel class to support multiple applications; 3. Add a new ``APP_ID`` environment variable; 4. Update the front controllers. -The following example shows how to create a new application for the API of a new Symfony project. +The following example shows how to create a new application for the API of a new +Symfony project. Step 1) Create a new Application ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In this example, we will use the `Shared Kernel`_ pattern, where, although all applications maintain an isolated context, -they can share common bundles, configurations, and code if desired. The optimal approach will depend on your specific -needs and requirements, so it's up to you to decide which best suits your project. +This example follows the `Shared Kernel`_ pattern: all applications maintain an +isolated context, but they can share common bundles, configuration, and code if +desired. The optimal approach will depend on your specific needs and +requirements, so it's up to you to decide which best suits your project. -First, let's create a new ``apps`` directory at the root of your project, which will hold all the necessary applications. -Each application will follow a simplified directory structure like the one described in :ref:`Symfony Best Practice `: +First, create a new ``apps`` directory at the root of your project, which will +hold all the necessary applications. Each application will follow a simplified +directory structure like the one described in :ref:`Symfony Best Practice `: .. code-block:: text @@ -64,17 +75,20 @@ Each application will follow a simplified directory structure like the one descr .. note:: - Note that the ``config/`` and ``src/`` directories at the root of the project will represent the shared context among - all applications within the ``apps/`` directory. Therefore, you should carefully consider what is common and what - should be placed in the specific application. + Note that the ``config/`` and ``src/`` directories at the root of the + project will represent the shared context among all applications within the + ``apps/`` directory. Therefore, you should carefully consider what is + common and what should be placed in the specific application. .. tip:: - You might also consider renaming the namespace for the shared context, from ``App`` to ``Shared``, as it will make it - easier to distinguish and provide clearer meaning to this context. + You might also consider renaming the namespace for the shared context, from + ``App`` to ``Shared``, as it will make it easier to distinguish and provide + clearer meaning to this context. -Since the new ``apps/api/src/`` directory will host the PHP code related to the API, we need to update the ``composer.json`` -file to include it in the autoload section: +Since the new ``apps/api/src/`` directory will host the PHP code related to the +API, you have to update the ``composer.json`` file to include it in the autoload +section: .. code-block:: json @@ -87,15 +101,18 @@ file to include it in the autoload section: } } -Additionally, don't forget to run `composer dump-autoload` to generate the autoload files. +Additionally, don't forget to run ``composer dump-autoload`` to generate the +autoload files. Step 2) Update the Kernel class to support Multiple Applications ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Since we aim to support multiple applications, we will add a new property ``string $id`` to the Kernel to identify the -application being loaded. This property will also allow us to split the cache, logs, and configuration files in order to -avoid collisions with other applications. Moreover, it contributes to performance optimization, as each application will -load only the required resources:: +Since there will be multiple applications, it's better to add a new property +``string $id`` to the Kernel to identify the application being loaded. This +property will also allow you to split the cache, logs, and configuration files +in order to avoid collisions with other applications. Moreover, it contributes +to performance optimization, as each application will load only the required +resources:: // src/Kernel.php namespace Shared; @@ -193,14 +210,16 @@ load only the required resources:: } } -In this example, we reuse the default implementation to import configuration and routes based on a given configuration -directory. As we saw earlier, this approach will import both shared and app-specific resources. +This example reuses the default implementation to import the configuration and +routes based on a given configuration directory. As shown earlier, this +approach will import both the shared and the app-specific resources. Step 3) Add a new APP_ID environment variable ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Now, let's introduce a new environment variable that identifies the current application. This new variable can be added -to the ``.env`` file to provide a default value, but it should typically be added to your web server configuration. +Next, define a new environment variable that identifies the current application. +This new variable can be added to the ``.env`` file to provide a default value, +but it should typically be added to your web server configuration. .. code-block:: bash @@ -209,14 +228,17 @@ to the ``.env`` file to provide a default value, but it should typically be adde .. caution:: - The value of this variable must match the application directory within ``apps/`` as it is used in the Kernel to load - the specific application configuration. + The value of this variable must match the application directory within + ``apps/`` as it is used in the Kernel to load the specific application + configuration. Step 4) Update the Front Controllers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In this final step, we will update the front controllers ``public/index.php`` and ``bin/console`` to pass the value of -the ``APP_ID`` variable to the Kernel instance. This will allow the Kernel to load and run the specified application:: +In this final step, update the front controllers ``public/index.php`` and +``bin/console`` to pass the value of the ``APP_ID`` variable to the Kernel +instance. This will allow the Kernel to load and run the specified +application:: // public/index.php use Shared\Kernel; @@ -226,11 +248,12 @@ the ``APP_ID`` variable to the Kernel instance. This will allow the Kernel to lo return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG'], $context['APP_ID']); }; -Similar to configuring the required ``APP_ENV`` and ``APP_DEBUG`` values, the third argument of the Kernel constructor -is now also necessary to setting the application ID, which is derived from an external configuration. +Similar to configuring the required ``APP_ENV`` and ``APP_DEBUG`` values, the +third argument of the Kernel constructor is now also necessary to set the +application ID, which is derived from an external configuration. -For the second front controller, we will define a new console option to allow passing the application ID we want to run -under CLI context:: +For the second front controller, define a new console option to allow passing +the application ID to run under CLI context:: // bin/console use Shared\Kernel; @@ -252,8 +275,9 @@ That's it! Executing Commands ------------------ -The ``bin/console`` script, which is used to run Symfony commands, always uses the ``Kernel`` class to build the -application and load the commands. If you need to run console commands for a specific application, you can provide the +The ``bin/console`` script, which is used to run Symfony commands, always uses +the ``Kernel`` class to build the application and load the commands. If you +need to run console commands for a specific application, you can provide the ``--id`` option along with the appropriate identity value: .. code-block:: terminal @@ -266,8 +290,9 @@ application and load the commands. If you need to run console commands for a spe export APP_ID=api php bin/console cache:clear -You might want to update the composer auto-scripts section to run multiple commands simultaneously. In this example, -we assume you have a second application for managing the configuration (admin): +You might want to update the composer auto-scripts section to run multiple +commands simultaneously. This example shows the commands of two different +applications called ``api`` and ``admin``: .. code-block:: json @@ -282,19 +307,23 @@ we assume you have a second application for managing the configuration (admin): } } -Then, run `composer auto-scripts` to test it! +Then, run ``composer auto-scripts`` to test it! .. note:: - The commands available for each console script (e.g. ``bin/console -iapi`` and ``bin/console -iadmin``) can differ - because they depend on the bundles enabled for each application, which could be different. + The commands available for each console script (e.g. ``bin/console -iapi`` + and ``bin/console -iadmin``) can differ because they depend on the bundles + enabled for each application, which could be different. Rendering Templates ------------------- -Let's assume there is now another app called ``admin``. If you follow the :ref:`Symfony Best Practices `, the shared Kernel -templates will be located in the ``templates/`` directory at the project's root. For admin-specific templates, you can -create a new directory ``apps/admin/templates/`` which you will need to manually configure under the Admin application: +Let's consider that you need to create another app called ``admin``. If you +follow the :ref:`Symfony Best Practices `, the shared Kernel +templates will be located in the ``templates/`` directory at the project's root. +For admin-specific templates, you can create a new directory +``apps/admin/templates/`` which you will need to manually configure under the +Admin application: .. code-block:: yaml @@ -303,15 +332,18 @@ create a new directory ``apps/admin/templates/`` which you will need to manually paths: '%kernel.project_dir%/apps/admin/templates': Admin -Then, use this Twig namespace to reference any template within the Admin application only, for example ``@Admin/form/fields.html.twig``. +Then, use this Twig namespace to reference any template within the Admin +application only, for example ``@Admin/form/fields.html.twig``. Running Tests ------------- -In Symfony applications, functional tests typically extend from the :class:`Symfony\\Bundle\\FrameworkBundle\\Test\\WebTestCase` -class by default. Within its parent class, ``KernelTestCase``, there is a method called ``createKernel()`` that attempts to -create the kernel responsible for running the application during tests. However, the current logic of this method doesn't -include our new application ID argument, so we need to make an update:: +In Symfony applications, functional tests typically extend from +the :class:`Symfony\\Bundle\\FrameworkBundle\\Test\\WebTestCase` class by +default. Within its parent class, ``KernelTestCase``, there is a method called +``createKernel()`` that attempts to create the kernel responsible for running +the application during tests. However, the current logic of this method doesn't +include the new application ID argument, so you need to update it:: // apps/api/tests/ApiTestCase.php namespace Api\Tests; @@ -333,11 +365,12 @@ include our new application ID argument, so we need to make an update:: .. note:: - Keep in mind that we will set a fixed application ID value in this instance, as the specific test cases extending - from ``ApiTestCase`` will focus solely on the ``api`` tests. + This examples uses a hardcoded application ID value because the tests + extending this ``ApiTestCase`` class will focus solely on the ``api`` tests. -In this situation, we have created a ``tests/`` directory inside the ``apps/api/`` application. As a result, we need to -inform both the ``composer.json`` file and our ``phpunit.xml`` configuration about its existence: +Now, create a ``tests/`` directory inside the ``apps/api/`` application. Then, +update both the ``composer.json`` file and ``phpunit.xml`` configuration about +its existence: .. code-block:: json @@ -368,8 +401,9 @@ And, here is the update needed for the ``phpunit.xml`` file: Adding more Applications ------------------------ -Now you can begin adding more applications as needed, such as an ``admin`` application to manage the project's -configuration and permissions. To do that, you will have to repeat the step 1 only: +Now you can begin adding more applications as needed, such as an ``admin`` +application to manage the project's configuration and permissions. To do that, +you will have to repeat the step 1 only: .. code-block:: text @@ -384,6 +418,7 @@ configuration and permissions. To do that, you will have to repeat the step 1 on │ └─ api/ │ └─ ... -Additionally, you might need to update your web server configuration to set the ``APP_ID=admin`` under a different domain. +Additionally, you might need to update your web server configuration to set the +``APP_ID=admin`` under a different domain. .. _`Shared Kernel`: http://ddd.fed.wiki.org/view/shared-kernel From 397e74ffc6908e4947ae6c28f2c5bbc81e4fb117 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Thu, 4 May 2023 19:51:52 +0200 Subject: [PATCH 027/205] Update multiple_kernels.rst Replacing tabs with spaces --- configuration/multiple_kernels.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configuration/multiple_kernels.rst b/configuration/multiple_kernels.rst index 1b8504e0748..9464fcf39f7 100644 --- a/configuration/multiple_kernels.rst +++ b/configuration/multiple_kernels.rst @@ -62,16 +62,16 @@ directory structure like the one described in :ref:`Symfony Best Practice Date: Fri, 5 May 2023 16:49:43 +0200 Subject: [PATCH 028/205] [FrameworkBundle] Update the http_method_override default value explanation --- reference/configuration/framework.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 5a71b31b122..aff01af4c9c 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -176,7 +176,7 @@ bootstrap the Symfony framework on a cache hit. http_method_override ~~~~~~~~~~~~~~~~~~~~ -**type**: ``boolean`` **default**: ``true`` +**type**: ``boolean`` **default**: (see explanation below) This determines whether the ``_method`` request parameter is used as the intended HTTP method on POST requests. If enabled, the @@ -184,6 +184,13 @@ intended HTTP method on POST requests. If enabled, the method gets called automatically. It becomes the service container parameter named ``kernel.http_method_override``. +The **default value** is: + +* ``true``, if you have an existing application that you've upgraded from an older + Symfony version without resyncing the :doc:`Symfony Flex ` recipes; +* ``false``, if you've created a new Symfony application or updated the Symfony + Flex recipes. This is also the default value starting from Symfony 7.0. + .. seealso:: :ref:`Changing the Action and HTTP Method ` of From 9de751cbc3becf44285985a84d102af68de1504f Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Sun, 7 May 2023 22:29:00 +0200 Subject: [PATCH 029/205] Not add quote in default values --- reference/configuration/framework.rst | 18 +++++++++--------- reference/configuration/security.rst | 6 +++--- reference/configuration/twig.rst | 10 +++++----- reference/configuration/web_profiler.rst | 2 +- reference/forms/types/collection.rst | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 53f3aa64960..290fefb13c8 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -740,7 +740,7 @@ is disabled. This can be either a template name or the content itself. path .... -**type**: ``string`` **default**: ``'/_fragment'`` +**type**: ``string`` **default**: ``/_fragment`` The path prefix for fragments. The fragment listener will only be executed when the request starts with this path. @@ -1357,7 +1357,7 @@ requests (and not on the subrequests). dsn ... -**type**: ``string`` **default**: ``'file:%kernel.cache_dir%/profiler'`` +**type**: ``string`` **default**: ``file:%kernel.cache_dir%/profiler`` The DSN where to store the profiling information. @@ -1553,7 +1553,7 @@ session storage_factory_id .................. -**type**: ``string`` **default**: ``'session.storage.factory.native'`` +**type**: ``string`` **default**: ``session.storage.factory.native`` The service ID used for creating the ``SessionStorageInterface`` that stores the session. This service is available in the Symfony application via the @@ -1574,7 +1574,7 @@ To see a list of all available storages, run: handler_id .......... -**type**: ``string`` **default**: ``'session.handler.native_file'`` +**type**: ``string`` **default**: ``session.handler.native_file`` The service id used for session storage. The default value ``'session.handler.native_file'`` will let Symfony manage the sessions itself using files to store the session metadata. @@ -1666,7 +1666,7 @@ to the cookie specification. cookie_samesite ............... -**type**: ``string`` or ``null`` **default**: ``'lax'`` +**type**: ``string`` or ``null`` **default**: ``lax`` It controls the way cookies are sent when the HTTP request did not originate from the same domain that is associated with the cookies. Setting this option is @@ -1701,7 +1701,7 @@ The possible values for this option are: cookie_secure ............. -**type**: ``boolean`` or ``'auto'`` **default**: ``'auto'`` +**type**: ``boolean`` or ``'auto'`` **default**: ``auto`` This determines whether cookies should only be sent over secure connections. In addition to ``true`` and ``false``, there's a special ``'auto'`` value that @@ -2702,7 +2702,7 @@ annotations cache ..... -**type**: ``string`` **default**: ``'php_array'`` +**type**: ``string`` **default**: ``php_array`` This option can be one of the following values: @@ -2722,7 +2722,7 @@ a service id file_cache_dir .............. -**type**: ``string`` **default**: ``'%kernel.cache_dir%/annotations'`` +**type**: ``string`` **default**: ``%kernel.cache_dir%/annotations`` The directory to store cache files for annotations, in case ``annotations.cache`` is set to ``'file'``. @@ -3493,7 +3493,7 @@ marking_store Each marking store can define any of these options: -* ``property`` (**type**: ``string`` **default**: ``'marking'``) +* ``property`` (**type**: ``string`` **default**: ``marking``) * ``service`` (**type**: ``string``) * ``type`` (**type**: ``string`` **allow value**: ``'method'``) diff --git a/reference/configuration/security.rst b/reference/configuration/security.rst index b811f33e2ac..22884fdbbe1 100644 --- a/reference/configuration/security.rst +++ b/reference/configuration/security.rst @@ -494,7 +494,7 @@ success_handler :class:`Symfony\\Component\\Security\\Http\\Event\\LogoutEvent` instead. -**type**: ``string`` **default**: ``'security.logout.success_handler'`` +**type**: ``string`` **default**: ``security.logout.success_handler`` The service ID used for handling a successful logout. The service must implement :class:`Symfony\\Component\\Security\\Http\\Logout\\LogoutSuccessHandlerInterface`. @@ -506,7 +506,7 @@ If it is set, the logout ``target`` option will be ignored. csrf_parameter .............. -**type**: ``string`` **default**: ``'_csrf_token'`` +**type**: ``string`` **default**: ``_csrf_token`` The name of the parameter that stores the CSRF token value. @@ -521,7 +521,7 @@ default service whose ID is ``security.csrf.token_manager``. csrf_token_id ............. -**type**: ``string`` **default**: ``'logout'`` +**type**: ``string`` **default**: ``logout`` An arbitrary string used to identify the token (and check its validity afterwards). diff --git a/reference/configuration/twig.rst b/reference/configuration/twig.rst index fc1d4886082..1153846f35d 100644 --- a/reference/configuration/twig.rst +++ b/reference/configuration/twig.rst @@ -36,7 +36,7 @@ compiled again automatically. autoescape ~~~~~~~~~~ -**type**: ``boolean`` or ``string`` **default**: ``'name'`` +**type**: ``boolean`` or ``string`` **default**: ``name`` If set to ``false``, automatic escaping is disabled (you can still escape each content individually in the templates). @@ -83,7 +83,7 @@ called to determine the default escaping applied to the template. base_template_class ~~~~~~~~~~~~~~~~~~~ -**type**: ``string`` **default**: ``'Twig\Template'`` +**type**: ``string`` **default**: ``Twig\Template`` Twig templates are compiled into PHP classes before using them to render contents. This option defines the base class from which all the template classes @@ -93,7 +93,7 @@ application harder to maintain. cache ~~~~~ -**type**: ``string`` | ``false`` **default**: ``'%kernel.cache_dir%/twig'`` +**type**: ``string`` | ``false`` **default**: ``%kernel.cache_dir%/twig`` Before using the Twig templates to render some contents, they are compiled into regular PHP code. Compilation is a costly process, so the result is cached in @@ -107,7 +107,7 @@ compiled again. charset ~~~~~~~ -**type**: ``string`` **default**: ``'%kernel.charset%'`` +**type**: ``string`` **default**: ``%kernel.charset%`` The charset used by the template files. By default it's the same as the value of the :ref:`kernel.charset container parameter `, @@ -160,7 +160,7 @@ If this option is ``false``, the ``dump()`` function doesn't output any contents default_path ~~~~~~~~~~~~ -**type**: ``string`` **default**: ``'%kernel.project_dir%/templates'`` +**type**: ``string`` **default**: ``%kernel.project_dir%/templates`` The path to the directory where Symfony will look for the application Twig templates by default. If you store the templates in more than one directory, use diff --git a/reference/configuration/web_profiler.rst b/reference/configuration/web_profiler.rst index fc95fd96833..f0b11f47064 100644 --- a/reference/configuration/web_profiler.rst +++ b/reference/configuration/web_profiler.rst @@ -30,7 +30,7 @@ Configuration excluded_ajax_paths ~~~~~~~~~~~~~~~~~~~ -**type**: ``string`` **default**: ``'^/((index|app(_[\w]+)?)\.php/)?_wdt'`` +**type**: ``string`` **default**: ``^/((index|app(_[\w]+)?)\.php/)?_wdt`` When the toolbar logs AJAX requests, it matches their URLs against this regular expression. If the URL matches, the request is not displayed in the toolbar. This diff --git a/reference/forms/types/collection.rst b/reference/forms/types/collection.rst index f44f25d7545..c4aa8be8a7f 100644 --- a/reference/forms/types/collection.rst +++ b/reference/forms/types/collection.rst @@ -198,7 +198,7 @@ type:: entry_type ~~~~~~~~~~ -**type**: ``string`` **default**: ``'Symfony\Component\Form\Extension\Core\Type\TextType'`` +**type**: ``string`` **default**: ``Symfony\Component\Form\Extension\Core\Type\TextType`` This is the field type for each item in this collection (e.g. ``TextType``, ``ChoiceType``, etc). For example, if you have an array of email addresses, From 486eacc15c75817fdba3644f5b316245be95206e Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Sun, 7 May 2023 22:41:02 +0200 Subject: [PATCH 030/205] Add missing backticks to defaults --- reference/configuration/framework.rst | 2 +- reference/constraints/Collection.rst | 4 ++-- reference/constraints/Count.rst | 2 +- reference/constraints/Regex.rst | 2 +- reference/forms/types/options/help.rst.inc | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 53f3aa64960..c35eb5a575e 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -1117,7 +1117,7 @@ Use ``0`` to not limit the duration. max_duration ............ -**type**: ``float`` **default**: 0 +**type**: ``float`` **default**: ``0`` The maximum execution time, in seconds, that the request and the response are allowed to take. A value lower than or equal to 0 means it is unlimited. diff --git a/reference/constraints/Collection.rst b/reference/constraints/Collection.rst index 62595aef75e..44d0319bb84 100644 --- a/reference/constraints/Collection.rst +++ b/reference/constraints/Collection.rst @@ -379,7 +379,7 @@ Options ``allowExtraFields`` ~~~~~~~~~~~~~~~~~~~~ -**type**: ``boolean`` **default**: false +**type**: ``boolean`` **default**: ``false`` If this option is set to ``false`` and the underlying collection contains one or more elements that are not included in the `fields`_ option, a validation @@ -388,7 +388,7 @@ error will be returned. If set to ``true``, extra fields are OK. ``allowMissingFields`` ~~~~~~~~~~~~~~~~~~~~~~ -**type**: ``boolean`` **default**: false +**type**: ``boolean`` **default**: ``false`` If this option is set to ``false`` and one or more fields from the `fields`_ option are not present in the underlying collection, a validation error diff --git a/reference/constraints/Count.rst b/reference/constraints/Count.rst index d4e7e796acc..b4d6982b0fb 100644 --- a/reference/constraints/Count.rst +++ b/reference/constraints/Count.rst @@ -115,7 +115,7 @@ Options ``divisibleBy`` ~~~~~~~~~~~~~~~ -**type**: ``integer`` **default**: null +**type**: ``integer`` **default**: ``null`` .. versionadded:: 5.1 diff --git a/reference/constraints/Regex.rst b/reference/constraints/Regex.rst index d4ecf423fd0..6c7f34a5422 100644 --- a/reference/constraints/Regex.rst +++ b/reference/constraints/Regex.rst @@ -193,7 +193,7 @@ Options ``htmlPattern`` ~~~~~~~~~~~~~~~ -**type**: ``string|boolean`` **default**: null +**type**: ``string|boolean`` **default**: ``null`` This option specifies the pattern to use in the HTML5 ``pattern`` attribute. You usually don't need to specify this option because by default, the constraint diff --git a/reference/forms/types/options/help.rst.inc b/reference/forms/types/options/help.rst.inc index 86f84111c88..c69e99819b3 100644 --- a/reference/forms/types/options/help.rst.inc +++ b/reference/forms/types/options/help.rst.inc @@ -1,7 +1,7 @@ help ~~~~ -**type**: ``string`` or ``TranslatableMessage`` **default**: null +**type**: ``string`` or ``TranslatableMessage`` **default**: ``null`` Allows you to define a help message for the form field, which by default is rendered below the field:: From e45f6e9dc0ff57db7b17ce312b141857433ccff2 Mon Sep 17 00:00:00 2001 From: MatTheCat Date: Mon, 8 May 2023 14:01:13 +0200 Subject: [PATCH 031/205] Improve the warning about signing messages in a listener --- mailer.rst | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mailer.rst b/mailer.rst index 712efa8a8c5..3a5e9223411 100644 --- a/mailer.rst +++ b/mailer.rst @@ -1044,6 +1044,15 @@ Before signing/encrypting messages, make sure to have: When using OpenSSL to generate certificates, make sure to add the ``-addtrust emailProtection`` command option. +.. caution:: + + These features require messages to be rendered, + which is not always immediate. + For example, :ref:`templated emails ` content is generated + by a :class:`Symfony\\Component\\Mailer\\EventListener\\MessageListener`. + If you need to sign and/or encrypt such a message, you need to do so in + a :ref:`MessageEvent ` listener with a negative priority. + Signing Messages ~~~~~~~~~~~~~~~~ @@ -1432,13 +1441,6 @@ is sent:: } } -.. tip:: - - When using a ``MessageEvent`` listener to - :doc:`sign the email contents `, run it as - late as possible (e.g. setting a negative priority for it) so the email - contents are not set or modified after signing them. - Development & Debugging ----------------------- From 07f6609a1b8bec0839a56d464e18b2abb06c753f Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Sun, 7 May 2023 22:57:08 +0200 Subject: [PATCH 032/205] [Fix pipeline] multiple_kernels.rst must respect doctor-rst --- .doctor-rst.yaml | 14 ++++++++++++++ configuration/multiple_kernels.rst | 18 +++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.doctor-rst.yaml b/.doctor-rst.yaml index 0fc471cfee8..318d55b688a 100644 --- a/.doctor-rst.yaml +++ b/.doctor-rst.yaml @@ -101,3 +101,17 @@ whitelist: - '// bin/console' - '.. _`a feature to test applications using Mercure`: https://github.com/symfony/panther#creating-isolated-browsers-to-test-apps-using-mercure-or-websocket' - '.. End to End Tests (E2E)' + - 'First, create a new ``apps`` directory at the root of your project, which will' # configuration/multiple_kernels.rst + - '├─ apps/' # configuration/multiple_kernels.rst + - '``apps/`` directory. Therefore, you should carefully consider what is' # configuration/multiple_kernels.rst + - 'Since the new ``apps/api/src/`` directory will host the PHP code related to the' # configuration/multiple_kernels.rst + - '"Api\\": "apps/api/src/"' # configuration/multiple_kernels.rst + - "return $this->getProjectDir().'/apps/'.$this->id.'/config';" # configuration/multiple_kernels.rst + - '``apps/`` as it is used in the Kernel to load the specific application' # configuration/multiple_kernels.rst + - '``apps/admin/templates/`` which you will need to manually configure under the' # configuration/multiple_kernels.rst + - '# apps/admin/config/packages/twig.yaml' # configuration/multiple_kernels.rst + - "'%kernel.project_dir%/apps/admin/templates': Admin" # configuration/multiple_kernels.rst + - '// apps/api/tests/ApiTestCase.php' # configuration/multiple_kernels.rst + - 'Now, create a ``tests/`` directory inside the ``apps/api/`` application. Then,' # configuration/multiple_kernels.rst + - '"Api\\Tests\\": "apps/api/tests/"' # configuration/multiple_kernels.rst + - 'apps/api/tests' # configuration/multiple_kernels.rst diff --git a/configuration/multiple_kernels.rst b/configuration/multiple_kernels.rst index 9464fcf39f7..cc50c27a1d4 100644 --- a/configuration/multiple_kernels.rst +++ b/configuration/multiple_kernels.rst @@ -164,12 +164,12 @@ resources:: return ($_SERVER['APP_LOG_DIR'] ?? $this->getProjectDir().'/var/log').'/'.$this->id; } - protected function configureContainer(ContainerConfigurator $container): void + protected function configureContainer(ContainerConfigurator $containerConfigurator): void { // load common config files, such as the framework.yaml, as well as // specific configs required exclusively for the app itself - $this->doConfigureContainer($container, $this->getSharedConfigDir()); - $this->doConfigureContainer($container, $this->getAppConfigDir()); + $this->doConfigureContainer($containerConfigurator, $this->getSharedConfigDir()); + $this->doConfigureContainer($containerConfigurator, $this->getAppConfigDir()); } protected function configureRoutes(RoutingConfigurator $routes): void @@ -180,16 +180,16 @@ resources:: $this->doConfigureRoutes($routes, $this->getAppConfigDir()); } - private function doConfigureContainer(ContainerConfigurator $container, string $configDir): void + private function doConfigureContainer(ContainerConfigurator $containerConfigurator, string $configDir): void { - $container->import($configDir.'/{packages}/*.{php,yaml}'); - $container->import($configDir.'/{packages}/'.$this->environment.'/*.{php,yaml}'); + $containerConfigurator->import($configDir.'/{packages}/*.{php,yaml}'); + $containerConfigurator->import($configDir.'/{packages}/'.$this->environment.'/*.{php,yaml}'); if (is_file($configDir.'/services.yaml')) { - $container->import($configDir.'/services.yaml'); - $container->import($configDir.'/{services}_'.$this->environment.'.yaml'); + $containerConfigurator->import($configDir.'/services.yaml'); + $containerConfigurator->import($configDir.'/{services}_'.$this->environment.'.yaml'); } else { - $container->import($configDir.'/{services}.php'); + $containerConfigurator->import($configDir.'/{services}.php'); } } From d22a4bd4db92da667dfe8359f05e5459c27990b4 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 9 May 2023 11:31:48 +0200 Subject: [PATCH 033/205] Tweaks --- mailer.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mailer.rst b/mailer.rst index 3a5e9223411..ee69bd3b123 100644 --- a/mailer.rst +++ b/mailer.rst @@ -1046,12 +1046,12 @@ Before signing/encrypting messages, make sure to have: .. caution:: - These features require messages to be rendered, - which is not always immediate. - For example, :ref:`templated emails ` content is generated + Signing and encrypting messages require their contents to be fully rendered. + For example, the content of :ref:`templated emails ` is rendered by a :class:`Symfony\\Component\\Mailer\\EventListener\\MessageListener`. - If you need to sign and/or encrypt such a message, you need to do so in - a :ref:`MessageEvent ` listener with a negative priority. + So, if you want to sign and/or encrypt such a message, you need to do it in + a :ref:`MessageEvent ` listener run after it (you need to set + a negative priority to your listener). Signing Messages ~~~~~~~~~~~~~~~~ From 7b0bac7ff72206c5e1b3d56231716fb1417dca48 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 5 May 2023 17:11:43 +0200 Subject: [PATCH 034/205] Update all links to PHPUnit docs --- best_practices.rst | 2 +- components/phpunit_bridge.rst | 10 +++++----- create_framework/unit_testing.rst | 4 ++-- form/unit_testing.rst | 2 +- testing.rst | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/best_practices.rst b/best_practices.rst index 159868118b3..02896abc627 100644 --- a/best_practices.rst +++ b/best_practices.rst @@ -463,4 +463,4 @@ you must set up a redirection. .. _`feature toggles`: https://en.wikipedia.org/wiki/Feature_toggle .. _`smoke testing`: https://en.wikipedia.org/wiki/Smoke_testing_(software) .. _`Webpack`: https://webpack.js.org/ -.. _`PHPUnit data providers`: https://phpunit.readthedocs.io/en/9.5/writing-tests-for-phpunit.html#data-providers +.. _`PHPUnit data providers`: https://docs.phpunit.de/en/9.5/writing-tests-for-phpunit.html#data-providers diff --git a/components/phpunit_bridge.rst b/components/phpunit_bridge.rst index 2d8803c4089..558fd808db6 100644 --- a/components/phpunit_bridge.rst +++ b/components/phpunit_bridge.rst @@ -1062,13 +1062,13 @@ not find the SUT: .. _`PHPUnit`: https://phpunit.de -.. _`PHPUnit event listener`: https://phpunit.de/manual/current/en/extending-phpunit.html#extending-phpunit.PHPUnit_Framework_TestListener +.. _`PHPUnit event listener`: https://docs.phpunit.de/en/10.0/extending-phpunit.html#phpunit-s-event-system .. _`ErrorHandler component`: https://github.com/symfony/error-handler -.. _`PHPUnit's assertStringMatchesFormat()`: https://phpunit.de/manual/current/en/appendixes.assertions.html#appendixes.assertions.assertStringMatchesFormat +.. _`PHPUnit's assertStringMatchesFormat()`: https://docs.phpunit.de/en/9.5/assertions.html#assertstringmatchesformat .. _`PHP error handler`: https://www.php.net/manual/en/book.errorfunc.php -.. _`environment variable`: https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.php-ini-constants-variables +.. _`environment variable`: https://docs.phpunit.de/en/9.5/configuration.html#the-env-element .. _`@-silencing operator`: https://www.php.net/manual/en/language.operators.errorcontrol.php .. _`Travis CI`: https://travis-ci.org/ -.. _`test listener`: https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.test-listeners -.. _`@covers`: https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.covers +.. _`test listener`: https://docs.phpunit.de/en/9.5/configuration.html#the-extensions-element +.. _`@covers`: https://docs.phpunit.de/en/9.5/annotations.html#covers .. _`PHP namespace resolutions rules`: https://www.php.net/manual/en/language.namespaces.rules.php diff --git a/create_framework/unit_testing.rst b/create_framework/unit_testing.rst index c2d04115812..cd3b30cac6c 100644 --- a/create_framework/unit_testing.rst +++ b/create_framework/unit_testing.rst @@ -220,6 +220,6 @@ Symfony code. Now that we are confident (again) about the code we have written, we can safely think about the next batch of features we want to add to our framework. -.. _`PHPUnit`: https://phpunit.readthedocs.io/en/9.5/ -.. _`test doubles`: https://phpunit.readthedocs.io/en/9.5/test-doubles.html +.. _`PHPUnit`: https://docs.phpunit.de/en/9.5/ +.. _`test doubles`: https://docs.phpunit.de/en/9.5/test-doubles.html .. _`XDebug`: https://xdebug.org/ diff --git a/form/unit_testing.rst b/form/unit_testing.rst index d67b5f3bae7..3c4a7b780a3 100644 --- a/form/unit_testing.rst +++ b/form/unit_testing.rst @@ -241,4 +241,4 @@ guessers using the :method:`Symfony\\Component\\Form\\Test\\FormIntegrationTestC and :method:`Symfony\\Component\\Form\\Test\\FormIntegrationTestCase::getTypeGuessers` methods. -.. _`PHPUnit data providers`: https://phpunit.readthedocs.io/en/9.5/writing-tests-for-phpunit.html#data-providers +.. _`PHPUnit data providers`: https://docs.phpunit.de/en/9.5/writing-tests-for-phpunit.html#data-providers diff --git a/testing.rst b/testing.rst index 3ca9f5e6e8a..ed0ab1a8e2c 100644 --- a/testing.rst +++ b/testing.rst @@ -1115,13 +1115,13 @@ Learn more /components/css_selector .. _`PHPUnit`: https://phpunit.de/ -.. _`documentation`: https://phpunit.readthedocs.io/ -.. _`Writing Tests for PHPUnit`: https://phpunit.readthedocs.io/en/9.5/writing-tests-for-phpunit.html -.. _`PHPUnit documentation`: https://phpunit.readthedocs.io/en/9.5/configuration.html +.. _`documentation`: https://docs.phpunit.de/ +.. _`Writing Tests for PHPUnit`: https://docs.phpunit.de/en/9.5/writing-tests-for-phpunit.html +.. _`PHPUnit documentation`: https://docs.phpunit.de/en/9.5/configuration.html .. _`unit test`: https://en.wikipedia.org/wiki/Unit_testing .. _`DAMADoctrineTestBundle`: https://github.com/dmaicher/doctrine-test-bundle .. _`Doctrine data fixtures`: https://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html .. _`DoctrineFixturesBundle documentation`: https://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html .. _`SymfonyMakerBundle`: https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html -.. _`PHPUnit Assertion`: https://phpunit.readthedocs.io/en/9.5/assertions.html +.. _`PHPUnit Assertion`: https://docs.phpunit.de/en/9.5/assertions.html .. _`section 4.1.18 of RFC 3875`: https://tools.ietf.org/html/rfc3875#section-4.1.18 From b7d5c256c88f34ba00abe8cccd169bad295c62d9 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 7 May 2023 20:11:10 +0200 Subject: [PATCH 035/205] [Frontend] Update package.json example path See symfony/ux@561a4a3609bd234b5ef1dacc9c42f5f89f071372 --- frontend/ux.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/ux.rst b/frontend/ux.rst index a43bcd8d028..98360893905 100644 --- a/frontend/ux.rst +++ b/frontend/ux.rst @@ -59,7 +59,7 @@ PHP package. For example: { "devDependencies": { "...": "", - "@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/Resources/assets" + "@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/assets" } } From 26d021c632d989621e541fdfe12b408e8c927aa7 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 10 May 2023 08:41:12 +0200 Subject: [PATCH 036/205] Use "$container" consistently --- .doctor-rst.yaml | 4 +- bundles/best_practices.rst | 4 +- bundles/configuration.rst | 12 ++-- bundles/extension.rst | 8 +-- bundles/prepend_extension.rst | 20 +++--- cache.rst | 8 +-- components/dependency_injection.rst | 52 +++++++------- .../_imports-parameters-note.rst.inc | 4 +- .../dependency_injection/compilation.rst | 72 +++++++++---------- components/event_dispatcher.rst | 20 +++--- components/serializer.rst | 4 +- components/uid.rst | 8 +-- components/var_dumper.rst | 4 +- configuration.rst | 50 ++++++------- configuration/env_var_processors.rst | 20 +++--- configuration/micro_kernel_trait.rst | 14 ++-- configuration/multiple_kernels.rst | 18 ++--- configuration/using_parameters_in_dic.rst | 4 +- console/lazy_commands.rst | 10 +-- controller/argument_value_resolver.rst | 4 +- controller/upload_file.rst | 4 +- create_framework/dependency_injection.rst | 24 +++---- doctrine/events.rst | 12 ++-- event_dispatcher.rst | 8 +-- frontend/custom_version_strategy.rst | 4 +- http_cache/cache_invalidation.rst | 4 +- mailer.rst | 4 +- messenger/multiple_buses.rst | 4 +- profiler.rst | 4 +- quick_tour/the_architecture.rst | 4 +- reference/configuration/framework.rst | 4 +- reference/dic_tags.rst | 8 +-- routing/custom_route_loader.rst | 4 +- security.rst | 8 +-- security/access_control.rst | 4 +- service_container.rst | 22 +++--- service_container/alias_private.rst | 20 +++--- service_container/autowiring.rst | 10 +-- service_container/calls.rst | 2 +- service_container/compiler_passes.rst | 16 ++--- service_container/configurators.rst | 8 +-- service_container/expression_language.rst | 6 +- service_container/factories.rst | 20 +++--- service_container/import.rst | 8 +-- service_container/injection_types.rst | 12 ++-- service_container/lazy_services.rst | 8 +-- service_container/optional_dependencies.rst | 8 +-- service_container/parent_services.rst | 8 +-- service_container/service_closures.rst | 6 +- service_container/service_decoration.rst | 32 ++++----- .../service_subscribers_locators.rst | 30 ++++---- service_container/shared.rst | 4 +- service_container/synthetic_services.rst | 4 +- service_container/tags.rst | 66 ++++++++--------- session.rst | 16 ++--- testing.rst | 4 +- 56 files changed, 375 insertions(+), 375 deletions(-) diff --git a/.doctor-rst.yaml b/.doctor-rst.yaml index 318d55b688a..6e22b45bb97 100644 --- a/.doctor-rst.yaml +++ b/.doctor-rst.yaml @@ -2,8 +2,8 @@ rules: american_english: ~ argument_variable_must_match_type: arguments: - - { type: 'ContainerBuilder', name: 'containerBuilder' } - - { type: 'ContainerConfigurator', name: 'containerConfigurator' } + - { type: 'ContainerBuilder', name: 'container' } + - { type: 'ContainerConfigurator', name: 'container' } avoid_repetetive_words: ~ blank_line_after_anchor: ~ blank_line_after_directive: ~ diff --git a/bundles/best_practices.rst b/bundles/best_practices.rst index d5c73209f26..e622cfd243f 100644 --- a/bundles/best_practices.rst +++ b/bundles/best_practices.rst @@ -442,8 +442,8 @@ The end user can provide values in any configuration file: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->parameters() + return static function (ContainerConfigurator $container) { + $container->parameters() ->set('acme_blog.author.email', 'fabien@example.com') ; }; diff --git a/bundles/configuration.rst b/bundles/configuration.rst index e25d6e01036..a30b6310ec1 100644 --- a/bundles/configuration.rst +++ b/bundles/configuration.rst @@ -217,7 +217,7 @@ force validation (e.g. if an additional option was passed, an exception will be thrown):: // src/Acme/SocialBundle/DependencyInjection/AcmeSocialExtension.php - public function load(array $configs, ContainerBuilder $containerBuilder) + public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); @@ -259,15 +259,15 @@ In your extension, you can load this and dynamically set its arguments:: use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; - public function load(array $configs, ContainerBuilder $containerBuilder) + public function load(array $configs, ContainerBuilder $container) { - $loader = new XmlFileLoader($containerBuilder, new FileLocator(dirname(__DIR__).'/Resources/config')); + $loader = new XmlFileLoader($container, new FileLocator(dirname(__DIR__).'/Resources/config')); $loader->load('services.xml'); $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $definition = $containerBuilder->getDefinition('acme.social.twitter_client'); + $definition = $container->getDefinition('acme.social.twitter_client'); $definition->replaceArgument(0, $config['twitter']['client_id']); $definition->replaceArgument(1, $config['twitter']['client_secret']); } @@ -288,7 +288,7 @@ In your extension, you can load this and dynamically set its arguments:: class AcmeHelloExtension extends ConfigurableExtension { // note that this method is called loadInternal and not load - protected function loadInternal(array $mergedConfig, ContainerBuilder $containerBuilder) + protected function loadInternal(array $mergedConfig, ContainerBuilder $container) { // ... } @@ -304,7 +304,7 @@ In your extension, you can load this and dynamically set its arguments:: (e.g. by overriding configurations and using :phpfunction:`isset` to check for the existence of a value). Be aware that it'll be very hard to support XML:: - public function load(array $configs, ContainerBuilder $containerBuilder) + public function load(array $configs, ContainerBuilder $container) { $config = []; // let resources override the previous set value diff --git a/bundles/extension.rst b/bundles/extension.rst index 2a8a5965451..74659cd98b6 100644 --- a/bundles/extension.rst +++ b/bundles/extension.rst @@ -34,7 +34,7 @@ This is how the extension of an AcmeHelloBundle should look like:: class AcmeHelloExtension extends Extension { - public function load(array $configs, ContainerBuilder $containerBuilder) + public function load(array $configs, ContainerBuilder $container) { // ... you'll load the files here later } @@ -89,10 +89,10 @@ For instance, assume you have a file called ``services.xml`` in the use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; // ... - public function load(array $configs, ContainerBuilder $containerBuilder) + public function load(array $configs, ContainerBuilder $container) { $loader = new XmlFileLoader( - $containerBuilder, + $container, new FileLocator(__DIR__.'/../Resources/config') ); $loader->load('services.xml'); @@ -115,7 +115,7 @@ they are compiled when generating the application cache to improve the overall performance. Define the list of annotated classes to compile in the ``addAnnotatedClassesToCompile()`` method:: - public function load(array $configs, ContainerBuilder $containerBuilder) + public function load(array $configs, ContainerBuilder $container) { // ... diff --git a/bundles/prepend_extension.rst b/bundles/prepend_extension.rst index 6ad1ad758d3..35c277ec0e6 100644 --- a/bundles/prepend_extension.rst +++ b/bundles/prepend_extension.rst @@ -31,7 +31,7 @@ To give an Extension the power to do this, it needs to implement { // ... - public function prepend(ContainerBuilder $containerBuilder) + public function prepend(ContainerBuilder $container) { // ... } @@ -52,15 +52,15 @@ a configuration setting in multiple bundles as well as disable a flag in multipl in case a specific other bundle is not registered:: // src/Acme/HelloBundle/DependencyInjection/AcmeHelloExtension.php - public function prepend(ContainerBuilder $containerBuilder) + public function prepend(ContainerBuilder $container) { // get all bundles - $bundles = $containerBuilder->getParameter('kernel.bundles'); + $bundles = $container->getParameter('kernel.bundles'); // determine if AcmeGoodbyeBundle is registered if (!isset($bundles['AcmeGoodbyeBundle'])) { // disable AcmeGoodbyeBundle in bundles $config = ['use_acme_goodbye' => false]; - foreach ($containerBuilder->getExtensions() as $name => $extension) { + foreach ($container->getExtensions() as $name => $extension) { switch ($name) { case 'acme_something': case 'acme_other': @@ -70,21 +70,21 @@ in case a specific other bundle is not registered:: // note that if the user manually configured // use_acme_goodbye to true in config/services.yaml // then the setting would in the end be true and not false - $containerBuilder->prependExtensionConfig($name, $config); + $container->prependExtensionConfig($name, $config); break; } } } // get the configuration of AcmeHelloExtension (it's a list of configuration) - $configs = $containerBuilder->getExtensionConfig($this->getAlias()); + $configs = $container->getExtensionConfig($this->getAlias()); // iterate in reverse to preserve the original order after prepending the config foreach (array_reverse($configs) as $config) { // check if entity_manager_name is set in the "acme_hello" configuration if (isset($config['entity_manager_name'])) { // prepend the acme_something settings with the entity_manager_name - $containerBuilder->prependExtensionConfig('acme_something', [ + $container->prependExtensionConfig('acme_something', [ 'entity_manager_name' => $config['entity_manager_name'], ]); } @@ -141,13 +141,13 @@ registered and the ``entity_manager_name`` setting for ``acme_hello`` is set to // config/packages/acme_something.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->extension('acme_something', [ + return static function (ContainerConfigurator $container) { + $container->extension('acme_something', [ // ... 'use_acme_goodbye' => false, 'entity_manager_name' => 'non_default', ]); - $containerConfigurator->extension('acme_other', [ + $container->extension('acme_other', [ // ... 'use_acme_goodbye' => false, ]); diff --git a/cache.rst b/cache.rst index 48d3a250bd1..118ef13a326 100644 --- a/cache.rst +++ b/cache.rst @@ -384,8 +384,8 @@ with either :class:`Symfony\\Contracts\\Cache\\CacheInterface` or // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { - $containerConfigurator->services() + return function(ContainerConfigurator $container) { + $container->services() // ... ->set('app.cache.adapter.redis') @@ -465,14 +465,14 @@ and use that when configuring the pool. use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $containerBuilder, FrameworkConfig $framework) { + return static function (ContainerBuilder $container, FrameworkConfig $framework) { $framework->cache() ->pool('cache.my_redis') ->adapters(['cache.adapter.redis']) ->provider('app.my_custom_redis_provider'); - $containerBuilder->register('app.my_custom_redis_provider', \Redis::class) + $container->register('app.my_custom_redis_provider', \Redis::class) ->setFactory([RedisAdapter::class, 'createConnection']) ->addArgument('redis://localhost') ->addArgument([ diff --git a/components/dependency_injection.rst b/components/dependency_injection.rst index dcc98bf2450..a6d8521f03a 100644 --- a/components/dependency_injection.rst +++ b/components/dependency_injection.rst @@ -45,8 +45,8 @@ You can register this in the container as a service:: use Symfony\Component\DependencyInjection\ContainerBuilder; - $containerBuilder = new ContainerBuilder(); - $containerBuilder->register('mailer', 'Mailer'); + $container = new ContainerBuilder(); + $container->register('mailer', 'Mailer'); An improvement to the class to make it more flexible would be to allow the container to set the ``transport`` used. If you change the class @@ -68,8 +68,8 @@ Then you can set the choice of transport in the container:: use Symfony\Component\DependencyInjection\ContainerBuilder; - $containerBuilder = new ContainerBuilder(); - $containerBuilder + $container = new ContainerBuilder(); + $container ->register('mailer', 'Mailer') ->addArgument('sendmail'); @@ -83,9 +83,9 @@ the ``Mailer`` service's constructor argument:: use Symfony\Component\DependencyInjection\ContainerBuilder; - $containerBuilder = new ContainerBuilder(); - $containerBuilder->setParameter('mailer.transport', 'sendmail'); - $containerBuilder + $container = new ContainerBuilder(); + $container->setParameter('mailer.transport', 'sendmail'); + $container ->register('mailer', 'Mailer') ->addArgument('%mailer.transport%'); @@ -112,14 +112,14 @@ not exist yet. Use the ``Reference`` class to tell the container to inject the use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; - $containerBuilder = new ContainerBuilder(); + $container = new ContainerBuilder(); - $containerBuilder->setParameter('mailer.transport', 'sendmail'); - $containerBuilder + $container->setParameter('mailer.transport', 'sendmail'); + $container ->register('mailer', 'Mailer') ->addArgument('%mailer.transport%'); - $containerBuilder + $container ->register('newsletter_manager', 'NewsletterManager') ->addArgument(new Reference('mailer')); @@ -144,14 +144,14 @@ If you do want to though then the container can call the setter method:: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; - $containerBuilder = new ContainerBuilder(); + $container = new ContainerBuilder(); - $containerBuilder->setParameter('mailer.transport', 'sendmail'); - $containerBuilder + $container->setParameter('mailer.transport', 'sendmail'); + $container ->register('mailer', 'Mailer') ->addArgument('%mailer.transport%'); - $containerBuilder + $container ->register('newsletter_manager', 'NewsletterManager') ->addMethodCall('setMailer', [new Reference('mailer')]); @@ -160,11 +160,11 @@ like this:: use Symfony\Component\DependencyInjection\ContainerBuilder; - $containerBuilder = new ContainerBuilder(); + $container = new ContainerBuilder(); // ... - $newsletterManager = $containerBuilder->get('newsletter_manager'); + $newsletterManager = $container->get('newsletter_manager'); Avoiding your Code Becoming Dependent on the Container ------------------------------------------------------ @@ -198,8 +198,8 @@ Loading an XML config file:: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; - $containerBuilder = new ContainerBuilder(); - $loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__)); + $container = new ContainerBuilder(); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__)); $loader->load('services.xml'); Loading a YAML config file:: @@ -208,8 +208,8 @@ Loading a YAML config file:: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; - $containerBuilder = new ContainerBuilder(); - $loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__)); + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__)); $loader->load('services.yaml'); .. note:: @@ -233,8 +233,8 @@ into a separate config file and load it in a similar way:: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; - $containerBuilder = new ContainerBuilder(); - $loader = new PhpFileLoader($containerBuilder, new FileLocator(__DIR__)); + $container = new ContainerBuilder(); + $loader = new PhpFileLoader($container, new FileLocator(__DIR__)); $loader->load('services.php'); You can now set up the ``newsletter_manager`` and ``mailer`` services using @@ -287,13 +287,13 @@ config files: namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->parameters() + return static function (ContainerConfigurator $container) { + $container->parameters() // ... ->set('mailer.transport', 'sendmail') ; - $services = $containerConfigurator->services(); + $services = $container->services(); $services->set('mailer', 'Mailer') ->args(['%mailer.transport%']) ; diff --git a/components/dependency_injection/_imports-parameters-note.rst.inc b/components/dependency_injection/_imports-parameters-note.rst.inc index 45a75652fda..d17d6d60b26 100644 --- a/components/dependency_injection/_imports-parameters-note.rst.inc +++ b/components/dependency_injection/_imports-parameters-note.rst.inc @@ -31,6 +31,6 @@ // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->import('%kernel.project_dir%/somefile.yaml'); + return static function (ContainerConfigurator $container) { + $container->import('%kernel.project_dir%/somefile.yaml'); }; diff --git a/components/dependency_injection/compilation.rst b/components/dependency_injection/compilation.rst index 3880d6b5508..edaa8be8f47 100644 --- a/components/dependency_injection/compilation.rst +++ b/components/dependency_injection/compilation.rst @@ -61,10 +61,10 @@ A very simple extension may just load configuration files into the container:: class AcmeDemoExtension implements ExtensionInterface { - public function load(array $configs, ContainerBuilder $containerBuilder) + public function load(array $configs, ContainerBuilder $container) { $loader = new XmlFileLoader( - $containerBuilder, + $container, new FileLocator(__DIR__.'/../Resources/config') ); $loader->load('services.xml'); @@ -114,14 +114,14 @@ are loaded:: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; - $containerBuilder = new ContainerBuilder(); - $containerBuilder->registerExtension(new AcmeDemoExtension); + $container = new ContainerBuilder(); + $container->registerExtension(new AcmeDemoExtension); - $loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__)); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__)); $loader->load('config.yaml'); // ... - $containerBuilder->compile(); + $container->compile(); .. note:: @@ -132,7 +132,7 @@ are loaded:: The values from those sections of the config files are passed into the first argument of the ``load()`` method of the extension:: - public function load(array $configs, ContainerBuilder $containerBuilder) + public function load(array $configs, ContainerBuilder $container) { $foo = $configs[0]['foo']; //fooValue $bar = $configs[0]['bar']; //barValue @@ -158,7 +158,7 @@ you could access the config value this way:: use Symfony\Component\Config\Definition\Processor; // ... - public function load(array $configs, ContainerBuilder $containerBuilder) + public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $processor = new Processor(); @@ -219,13 +219,13 @@ The processed config value can now be added as container parameters as if it were listed in a ``parameters`` section of the config file but with the additional benefit of merging multiple files and validation of the configuration:: - public function load(array $configs, ContainerBuilder $containerBuilder) + public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $processor = new Processor(); $config = $processor->processConfiguration($configuration, $configs); - $containerBuilder->setParameter('acme_demo.FOO', $config['foo']); + $container->setParameter('acme_demo.FOO', $config['foo']); // ... } @@ -234,14 +234,14 @@ More complex configuration requirements can be catered for in the Extension classes. For example, you may choose to load a main service configuration file but also load a secondary one only if a certain parameter is set:: - public function load(array $configs, ContainerBuilder $containerBuilder) + public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $processor = new Processor(); $config = $processor->processConfiguration($configuration, $configs); $loader = new XmlFileLoader( - $containerBuilder, + $container, new FileLocator(__DIR__.'/../Resources/config') ); $loader->load('services.xml'); @@ -263,11 +263,11 @@ file but also load a secondary one only if a certain parameter is set:: use Symfony\Component\DependencyInjection\ContainerBuilder; - $containerBuilder = new ContainerBuilder(); + $container = new ContainerBuilder(); $extension = new AcmeDemoExtension(); - $containerBuilder->registerExtension($extension); - $containerBuilder->loadFromExtension($extension->getAlias()); - $containerBuilder->compile(); + $container->registerExtension($extension); + $container->loadFromExtension($extension->getAlias()); + $container->compile(); .. note:: @@ -292,11 +292,11 @@ method is called by implementing { // ... - public function prepend(ContainerBuilder $containerBuilder) + public function prepend(ContainerBuilder $container) { // ... - $containerBuilder->prependExtensionConfig($name, $config); + $container->prependExtensionConfig($name, $config); // ... } @@ -323,7 +323,7 @@ compilation:: class AcmeDemoExtension implements ExtensionInterface, CompilerPassInterface { - public function process(ContainerBuilder $containerBuilder) + public function process(ContainerBuilder $container) { // ... do something during the compilation } @@ -377,7 +377,7 @@ class implementing the ``CompilerPassInterface``:: class CustomPass implements CompilerPassInterface { - public function process(ContainerBuilder $containerBuilder) + public function process(ContainerBuilder $container) { // ... do something during the compilation } @@ -387,8 +387,8 @@ You then need to register your custom pass with the container:: use Symfony\Component\DependencyInjection\ContainerBuilder; - $containerBuilder = new ContainerBuilder(); - $containerBuilder->addCompilerPass(new CustomPass()); + $container = new ContainerBuilder(); + $container->addCompilerPass(new CustomPass()); .. note:: @@ -418,7 +418,7 @@ For example, to run your custom pass after the default removal passes have been run, use:: // ... - $containerBuilder->addCompilerPass( + $container->addCompilerPass( new CustomPass(), PassConfig::TYPE_AFTER_REMOVING ); @@ -460,11 +460,11 @@ serves at dumping the compiled container:: require_once $file; $container = new ProjectServiceContainer(); } else { - $containerBuilder = new ContainerBuilder(); + $container = new ContainerBuilder(); // ... - $containerBuilder->compile(); + $container->compile(); - $dumper = new PhpDumper($containerBuilder); + $dumper = new PhpDumper($container); file_put_contents($file, $dumper->dump()); } @@ -487,11 +487,11 @@ dump it:: require_once $file; $container = new MyCachedContainer(); } else { - $containerBuilder = new ContainerBuilder(); + $container = new ContainerBuilder(); // ... - $containerBuilder->compile(); + $container->compile(); - $dumper = new PhpDumper($containerBuilder); + $dumper = new PhpDumper($container); file_put_contents( $file, $dumper->dump(['class' => 'MyCachedContainer']) @@ -519,12 +519,12 @@ application:: require_once $file; $container = new MyCachedContainer(); } else { - $containerBuilder = new ContainerBuilder(); + $container = new ContainerBuilder(); // ... - $containerBuilder->compile(); + $container->compile(); if (!$isDebug) { - $dumper = new PhpDumper($containerBuilder); + $dumper = new PhpDumper($container); file_put_contents( $file, $dumper->dump(['class' => 'MyCachedContainer']) @@ -554,14 +554,14 @@ for these resources and use them as metadata for the cache:: $containerConfigCache = new ConfigCache($file, $isDebug); if (!$containerConfigCache->isFresh()) { - $containerBuilder = new ContainerBuilder(); + $container = new ContainerBuilder(); // ... - $containerBuilder->compile(); + $container->compile(); - $dumper = new PhpDumper($containerBuilder); + $dumper = new PhpDumper($container); $containerConfigCache->write( $dumper->dump(['class' => 'MyCachedContainer']), - $containerBuilder->getResources() + $container->getResources() ); } diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index 5459d27bdb3..1e281c084b0 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -186,22 +186,22 @@ determine which instance is passed. use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; use Symfony\Component\EventDispatcher\EventDispatcher; - $containerBuilder = new ContainerBuilder(new ParameterBag()); + $container = new ContainerBuilder(new ParameterBag()); // register the compiler pass that handles the 'kernel.event_listener' // and 'kernel.event_subscriber' service tags - $containerBuilder->addCompilerPass(new RegisterListenersPass()); + $container->addCompilerPass(new RegisterListenersPass()); - $containerBuilder->register('event_dispatcher', EventDispatcher::class); + $container->register('event_dispatcher', EventDispatcher::class); // registers an event listener - $containerBuilder->register('listener_service_id', \AcmeListener::class) + $container->register('listener_service_id', \AcmeListener::class) ->addTag('kernel.event_listener', [ 'event' => 'acme.foo.action', 'method' => 'onFooAction', ]); // registers an event subscriber - $containerBuilder->register('subscriber_service_id', \AcmeSubscriber::class) + $container->register('subscriber_service_id', \AcmeSubscriber::class) ->addTag('kernel.event_subscriber'); ``RegisterListenersPass`` resolves aliased class names which for instance @@ -218,16 +218,16 @@ determine which instance is passed. use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; use Symfony\Component\EventDispatcher\EventDispatcher; - $containerBuilder = new ContainerBuilder(new ParameterBag()); - $containerBuilder->addCompilerPass(new AddEventAliasesPass([ + $container = new ContainerBuilder(new ParameterBag()); + $container->addCompilerPass(new AddEventAliasesPass([ \AcmeFooActionEvent::class => 'acme.foo.action', ])); - $containerBuilder->addCompilerPass(new RegisterListenersPass(), PassConfig::TYPE_BEFORE_REMOVING); + $container->addCompilerPass(new RegisterListenersPass(), PassConfig::TYPE_BEFORE_REMOVING); - $containerBuilder->register('event_dispatcher', EventDispatcher::class); + $container->register('event_dispatcher', EventDispatcher::class); // registers an event listener - $containerBuilder->register('listener_service_id', \AcmeListener::class) + $container->register('listener_service_id', \AcmeListener::class) ->addTag('kernel.event_listener', [ // will be translated to 'acme.foo.action' by RegisterListenersPass. 'event' => \AcmeFooActionEvent::class, diff --git a/components/serializer.rst b/components/serializer.rst index cf09f0b7992..29c008ce2c4 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -998,8 +998,8 @@ faster alternative to the use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->services() + return static function (ContainerConfigurator $container) { + $container->services() // ... ->set('get_set_method_normalizer', GetSetMethodNormalizer::class) ->tag('serializer.normalizer') diff --git a/components/uid.rst b/components/uid.rst index ccd567f6ccf..1731c392dba 100644 --- a/components/uid.rst +++ b/components/uid.rst @@ -126,13 +126,13 @@ configure the behavior of the factory using configuration files:: // config/packages/uid.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $containerConfigurator): void { - $services = $containerConfigurator->services() + return static function (ContainerConfigurator $container): void { + $services = $container->services() ->defaults() ->autowire() ->autoconfigure(); - $containerConfigurator->extension('framework', [ + $container->extension('framework', [ 'uid' => [ 'default_uuid_version' => 6, 'name_based_uuid_version' => 5, @@ -568,7 +568,7 @@ configuration in your application before using these commands: use Symfony\Component\Uid\Command\InspectUlidCommand; use Symfony\Component\Uid\Command\InspectUuidCommand; - return static function (ContainerConfigurator $containerConfigurator): void { + return static function (ContainerConfigurator $container): void { // ... $services diff --git a/components/var_dumper.rst b/components/var_dumper.rst index 6b0d3bc6ea1..e8a4d18d0c7 100644 --- a/components/var_dumper.rst +++ b/components/var_dumper.rst @@ -144,8 +144,8 @@ the :ref:`dump_destination option ` of the // config/packages/debug.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->extension('debug', [ + return static function (ContainerConfigurator $container) { + $container->extension('debug', [ 'dump_destination' => 'tcp://%env(VAR_DUMPER_SERVER)%', ]); }; diff --git a/configuration.rst b/configuration.rst index c56b895da8b..79d014f9170 100644 --- a/configuration.rst +++ b/configuration.rst @@ -73,18 +73,18 @@ shown in these three formats. { // ... - private function configureContainer(ContainerConfigurator $containerConfigurator): void + private function configureContainer(ContainerConfigurator $container): void { $configDir = $this->getConfigDir(); - $containerConfigurator->import($configDir.'/{packages}/*.{yaml,php}'); - $containerConfigurator->import($configDir.'/{packages}/'.$this->environment.'/*.{yaml,php}'); + $container->import($configDir.'/{packages}/*.{yaml,php}'); + $container->import($configDir.'/{packages}/'.$this->environment.'/*.{yaml,php}'); if (is_file($configDir.'/services.yaml')) { - $containerConfigurator->import($configDir.'/services.yaml'); - $containerConfigurator->import($configDir.'/{services}_'.$this->environment.'.yaml'); + $container->import($configDir.'/services.yaml'); + $container->import($configDir.'/{services}_'.$this->environment.'.yaml'); } else { - $containerConfigurator->import($configDir.'/{services}.php'); + $container->import($configDir.'/{services}.php'); } } } @@ -158,17 +158,17 @@ configuration files, even if they use a different format: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->import('legacy_config.php'); + return static function (ContainerConfigurator $container) { + $container->import('legacy_config.php'); // glob expressions are also supported to load multiple files - $containerConfigurator->import('/etc/myapp/*.yaml'); + $container->import('/etc/myapp/*.yaml'); // the third optional argument of import() is 'ignore_errors' // 'ignore_errors' set to 'not_found' silently discards errors if the loaded file doesn't exist - $containerConfigurator->import('my_config_file.yaml', null, 'not_found'); + $container->import('my_config_file.yaml', null, 'not_found'); // 'ignore_errors' set to true silently discards all errors (including invalid code and not found) - $containerConfigurator->import('my_config_file.yaml', null, true); + $container->import('my_config_file.yaml', null, true); }; // ... @@ -257,8 +257,8 @@ reusable configuration value. By convention, parameters are defined under the use App\Entity\BlogPost; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->parameters() + return static function (ContainerConfigurator $container) { + $container->parameters() // the parameter name is an arbitrary string (the 'app.' prefix is recommended // to better differentiate your parameters from Symfony parameters). ->set('app.admin_email', 'something@example.com') @@ -329,8 +329,8 @@ configuration file using a special syntax: wrap the parameter name in two ``%`` // config/packages/some_package.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->extension('some_package', [ + return static function (ContainerConfigurator $container) { + $container->extension('some_package', [ // any string surrounded by two % is replaced by that parameter value 'email_address' => '%app.admin_email%', @@ -366,8 +366,8 @@ configuration file using a special syntax: wrap the parameter name in two ``%`` // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->parameters() + return static function (ContainerConfigurator $container) { + $container->parameters() ->set('url_pattern', 'http://symfony.com/?foo=%%s&bar=%%d'); }; @@ -502,7 +502,7 @@ files directly in the ``config/packages/`` directory. use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symfony\Config\WebpackEncoreConfig; - return static function (WebpackEncoreConfig $webpackEncore, ContainerConfigurator $containerConfigurator) { + return static function (WebpackEncoreConfig $webpackEncore, ContainerConfigurator $container) { $webpackEncore ->outputPath('%kernel.project_dir%/public/build') ->strictMode(true) @@ -510,12 +510,12 @@ files directly in the ``config/packages/`` directory. ; // cache is enabled only in the "prod" environment - if ('prod' === $containerConfigurator->env()) { + if ('prod' === $container->env()) { $webpackEncore->cache(true); } // disable strict mode only in the "test" environment - if ('test' === $containerConfigurator->env()) { + if ('test' === $container->env()) { $webpackEncore->strictMode(false); } }; @@ -633,7 +633,7 @@ This example shows how you could configure the application secret using an env v // config/packages/framework.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $containerConfigurator) { + return static function (ContainerConfigurator $container) { $container->extension('framework', [ // by convention the env var names are always uppercase 'secret' => '%env(APP_SECRET)%', @@ -989,8 +989,8 @@ doesn't work for parameters: use App\Service\MessageGenerator; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->parameters() + return static function (ContainerConfigurator $container) { + $container->parameters() ->set('app.contents_dir', '...'); $container->services() @@ -1046,8 +1046,8 @@ whenever a service/controller defines a ``$projectDir`` argument, use this: use App\Controller\LuckyController; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->services() + return static function (ContainerConfigurator $container) { + $container->services() ->defaults() // pass this value to any $projectDir argument for any service // that's created in this file (including controller arguments) diff --git a/configuration/env_var_processors.rst b/configuration/env_var_processors.rst index 358f3989a69..cc6782baabb 100644 --- a/configuration/env_var_processors.rst +++ b/configuration/env_var_processors.rst @@ -104,8 +104,8 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $containerBuilder, FrameworkConfig $framework) { - $containerBuilder->setParameter('env(SECRET)', 'some_secret'); + return static function (ContainerBuilder $container, FrameworkConfig $framework) { + $container->setParameter('env(SECRET)', 'some_secret'); $framework->secret(env('SECRET')->string()); }; @@ -150,8 +150,8 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $containerBuilder, FrameworkConfig $framework) { - $containerBuilder->setParameter('env(HTTP_METHOD_OVERRIDE)', 'true'); + return static function (ContainerBuilder $container, FrameworkConfig $framework) { + $container->setParameter('env(HTTP_METHOD_OVERRIDE)', 'true'); $framework->httpMethodOverride(env('HTTP_METHOD_OVERRIDE')->bool()); }; @@ -242,8 +242,8 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\SecurityConfig; - return static function (ContainerBuilder $containerBuilder, SecurityConfig $security) { - $containerBuilder->setParameter('env(HEALTH_CHECK_METHOD)', 'Symfony\Component\HttpFoundation\Request::METHOD_HEAD'); + return static function (ContainerBuilder $container, SecurityConfig $security) { + $container->setParameter('env(HEALTH_CHECK_METHOD)', 'Symfony\Component\HttpFoundation\Request::METHOD_HEAD'); $security->accessControl() ->path('^/health-check$') ->methods([env('HEALTH_CHECK_METHOD')->const()]); @@ -293,8 +293,8 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $containerBuilder, FrameworkConfig $framework) { - $containerBuilder->setParameter('env(TRUSTED_HOSTS)', '["10.0.0.1", "10.0.0.2"]'); + return static function (ContainerBuilder $container, FrameworkConfig $framework) { + $container->setParameter('env(TRUSTED_HOSTS)', '["10.0.0.1", "10.0.0.2"]'); $framework->trustedHosts(env('TRUSTED_HOSTS')->json()); }; @@ -379,8 +379,8 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $containerBuilder, FrameworkConfig $framework) { - $containerBuilder->setParameter('env(TRUSTED_HOSTS)', '10.0.0.1,10.0.0.2'); + return static function (ContainerBuilder $container, FrameworkConfig $framework) { + $container->setParameter('env(TRUSTED_HOSTS)', '10.0.0.1,10.0.0.2'); $framework->trustedHosts(env('TRUSTED_HOSTS')->csv()); }; diff --git a/configuration/micro_kernel_trait.rst b/configuration/micro_kernel_trait.rst index ce4b0ac46c2..185d301a657 100644 --- a/configuration/micro_kernel_trait.rst +++ b/configuration/micro_kernel_trait.rst @@ -43,10 +43,10 @@ Next, create an ``index.php`` file that defines the kernel class and runs it:: ]; } - protected function configureContainer(ContainerConfigurator $containerConfigurator): void + protected function configureContainer(ContainerConfigurator $container): void { // PHP equivalent of config/packages/framework.yaml - $containerConfigurator->extension('framework', [ + $container->extension('framework', [ 'secret' => 'S0ME_SECRET' ]); } @@ -88,7 +88,7 @@ that define your bundles, your services and your routes: **registerBundles()** This is the same ``registerBundles()`` that you see in a normal kernel. -**configureContainer(ContainerConfigurator $containerConfigurator)** +**configureContainer(ContainerConfigurator $container)** This method builds and configures the container. In practice, you will use ``extension()`` to configure different bundles (this is the equivalent of what you see in a normal ``config/packages/*`` file). You can also register @@ -191,12 +191,12 @@ hold the kernel. Now it looks like this:: return $bundles; } - protected function configureContainer(ContainerConfigurator $containerConfigurator): void + protected function configureContainer(ContainerConfigurator $container): void { - $containerConfigurator->import(__DIR__.'/../config/framework.yaml'); + $container->import(__DIR__.'/../config/framework.yaml'); // register all classes in /src/ as service - $containerConfigurator->services() + $container->services() ->load('App\\', __DIR__.'/*') ->autowire() ->autoconfigure() @@ -204,7 +204,7 @@ hold the kernel. Now it looks like this:: // configure WebProfilerBundle only if the bundle is enabled if (isset($this->bundles['WebProfilerBundle'])) { - $containerConfigurator->extension('web_profiler', [ + $container->extension('web_profiler', [ 'toolbar' => true, 'intercept_redirects' => false, ]); diff --git a/configuration/multiple_kernels.rst b/configuration/multiple_kernels.rst index cc50c27a1d4..9464fcf39f7 100644 --- a/configuration/multiple_kernels.rst +++ b/configuration/multiple_kernels.rst @@ -164,12 +164,12 @@ resources:: return ($_SERVER['APP_LOG_DIR'] ?? $this->getProjectDir().'/var/log').'/'.$this->id; } - protected function configureContainer(ContainerConfigurator $containerConfigurator): void + protected function configureContainer(ContainerConfigurator $container): void { // load common config files, such as the framework.yaml, as well as // specific configs required exclusively for the app itself - $this->doConfigureContainer($containerConfigurator, $this->getSharedConfigDir()); - $this->doConfigureContainer($containerConfigurator, $this->getAppConfigDir()); + $this->doConfigureContainer($container, $this->getSharedConfigDir()); + $this->doConfigureContainer($container, $this->getAppConfigDir()); } protected function configureRoutes(RoutingConfigurator $routes): void @@ -180,16 +180,16 @@ resources:: $this->doConfigureRoutes($routes, $this->getAppConfigDir()); } - private function doConfigureContainer(ContainerConfigurator $containerConfigurator, string $configDir): void + private function doConfigureContainer(ContainerConfigurator $container, string $configDir): void { - $containerConfigurator->import($configDir.'/{packages}/*.{php,yaml}'); - $containerConfigurator->import($configDir.'/{packages}/'.$this->environment.'/*.{php,yaml}'); + $container->import($configDir.'/{packages}/*.{php,yaml}'); + $container->import($configDir.'/{packages}/'.$this->environment.'/*.{php,yaml}'); if (is_file($configDir.'/services.yaml')) { - $containerConfigurator->import($configDir.'/services.yaml'); - $containerConfigurator->import($configDir.'/{services}_'.$this->environment.'.yaml'); + $container->import($configDir.'/services.yaml'); + $container->import($configDir.'/{services}_'.$this->environment.'.yaml'); } else { - $containerConfigurator->import($configDir.'/{services}.php'); + $container->import($configDir.'/{services}.php'); } } diff --git a/configuration/using_parameters_in_dic.rst b/configuration/using_parameters_in_dic.rst index 9eb629b4b20..05008114e01 100644 --- a/configuration/using_parameters_in_dic.rst +++ b/configuration/using_parameters_in_dic.rst @@ -135,9 +135,9 @@ And set it in the constructor of ``Configuration`` via the ``Extension`` class:: { // ... - public function getConfiguration(array $config, ContainerBuilder $containerBuilder) + public function getConfiguration(array $config, ContainerBuilder $container) { - return new Configuration($containerBuilder->getParameter('kernel.debug')); + return new Configuration($container->getParameter('kernel.debug')); } } diff --git a/console/lazy_commands.rst b/console/lazy_commands.rst index 553490c845e..6d1f245eb75 100644 --- a/console/lazy_commands.rst +++ b/console/lazy_commands.rst @@ -68,13 +68,13 @@ with command names as keys and service identifiers as values:: use Symfony\Component\Console\CommandLoader\ContainerCommandLoader; use Symfony\Component\DependencyInjection\ContainerBuilder; - $containerBuilder = new ContainerBuilder(); - $containerBuilder->register(FooCommand::class, FooCommand::class); - $containerBuilder->compile(); + $container = new ContainerBuilder(); + $container->register(FooCommand::class, FooCommand::class); + $container->compile(); - $commandLoader = new ContainerCommandLoader($containerBuilder, [ + $commandLoader = new ContainerCommandLoader($container, [ 'app:foo' => FooCommand::class, ]); Like this, executing the ``app:foo`` command will load the ``FooCommand`` service -by calling ``$containerBuilder->get(FooCommand::class)``. +by calling ``$container->get(FooCommand::class)``. diff --git a/controller/argument_value_resolver.rst b/controller/argument_value_resolver.rst index fcbe012ef33..eb100c258f0 100644 --- a/controller/argument_value_resolver.rst +++ b/controller/argument_value_resolver.rst @@ -230,8 +230,8 @@ and adding a priority. use App\ArgumentResolver\UserValueResolver; - return static function (ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return static function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(UserValueResolver::class) ->tag('controller.argument_value_resolver', ['priority' => 50]) diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 0e5beb84eb3..886c772d98a 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -319,8 +319,8 @@ Then, define a service for this class: use App\Service\FileUploader; - return static function (ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return static function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(FileUploader::class) ->arg('$targetDirectory', '%brochures_directory%') diff --git a/create_framework/dependency_injection.rst b/create_framework/dependency_injection.rst index cd20a947251..de3c4e11e4e 100644 --- a/create_framework/dependency_injection.rst +++ b/create_framework/dependency_injection.rst @@ -109,30 +109,30 @@ Create a new file to host the dependency injection container configuration:: use Symfony\Component\HttpKernel; use Symfony\Component\Routing; - $containerBuilder = new DependencyInjection\ContainerBuilder(); - $containerBuilder->register('context', Routing\RequestContext::class); - $containerBuilder->register('matcher', Routing\Matcher\UrlMatcher::class) + $container = new DependencyInjection\ContainerBuilder(); + $container->register('context', Routing\RequestContext::class); + $container->register('matcher', Routing\Matcher\UrlMatcher::class) ->setArguments([$routes, new Reference('context')]) ; - $containerBuilder->register('request_stack', HttpFoundation\RequestStack::class); - $containerBuilder->register('controller_resolver', HttpKernel\Controller\ControllerResolver::class); - $containerBuilder->register('argument_resolver', HttpKernel\Controller\ArgumentResolver::class); + $container->register('request_stack', HttpFoundation\RequestStack::class); + $container->register('controller_resolver', HttpKernel\Controller\ControllerResolver::class); + $container->register('argument_resolver', HttpKernel\Controller\ArgumentResolver::class); - $containerBuilder->register('listener.router', HttpKernel\EventListener\RouterListener::class) + $container->register('listener.router', HttpKernel\EventListener\RouterListener::class) ->setArguments([new Reference('matcher'), new Reference('request_stack')]) ; - $containerBuilder->register('listener.response', HttpKernel\EventListener\ResponseListener::class) + $container->register('listener.response', HttpKernel\EventListener\ResponseListener::class) ->setArguments(['UTF-8']) ; - $containerBuilder->register('listener.exception', HttpKernel\EventListener\ErrorListener::class) + $container->register('listener.exception', HttpKernel\EventListener\ErrorListener::class) ->setArguments(['Calendar\Controller\ErrorController::exception']) ; - $containerBuilder->register('dispatcher', EventDispatcher\EventDispatcher::class) + $container->register('dispatcher', EventDispatcher\EventDispatcher::class) ->addMethodCall('addSubscriber', [new Reference('listener.router')]) ->addMethodCall('addSubscriber', [new Reference('listener.response')]) ->addMethodCall('addSubscriber', [new Reference('listener.exception')]) ; - $containerBuilder->register('framework', Framework::class) + $container->register('framework', Framework::class) ->setArguments([ new Reference('dispatcher'), new Reference('controller_resolver'), @@ -141,7 +141,7 @@ Create a new file to host the dependency injection container configuration:: ]) ; - return $containerBuilder; + return $container; The goal of this file is to configure your objects and their dependencies. Nothing is instantiated during this configuration step. This is purely a diff --git a/doctrine/events.rst b/doctrine/events.rst index 729e266db3d..80506081fbe 100644 --- a/doctrine/events.rst +++ b/doctrine/events.rst @@ -224,8 +224,8 @@ with the ``doctrine.event_listener`` tag: use App\EventListener\SearchIndexer; - return static function (ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return static function (ContainerConfigurator $container) { + $services = $container->services(); // listeners are applied by default to all Doctrine connections $services->set(SearchIndexer::class) @@ -357,8 +357,8 @@ with the ``doctrine.orm.entity_listener`` tag: use App\Entity\User; use App\EventListener\UserChangedNotifier; - return static function (ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return static function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(UserChangedNotifier::class) ->tag('doctrine.orm.entity_listener', [ @@ -498,8 +498,8 @@ Doctrine connection to use) you must do that in the manual service configuration use App\EventListener\DatabaseActivitySubscriber; - return static function (ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return static function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(DatabaseActivitySubscriber::class) ->tag('doctrine.event_subscriber'[ diff --git a/event_dispatcher.rst b/event_dispatcher.rst index c04e309eb46..a1e26412a85 100644 --- a/event_dispatcher.rst +++ b/event_dispatcher.rst @@ -91,8 +91,8 @@ notify Symfony that it is an event listener by using a special "tag": use App\EventListener\ExceptionListener; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(ExceptionListener::class) ->tag('kernel.event_listener') @@ -383,9 +383,9 @@ compiler pass ``AddEventAliasesPass``:: class Kernel extends BaseKernel { - protected function build(ContainerBuilder $containerBuilder) + protected function build(ContainerBuilder $container) { - $containerBuilder->addCompilerPass(new AddEventAliasesPass([ + $container->addCompilerPass(new AddEventAliasesPass([ MyCustomEvent::class => 'my_custom_event', ])); } diff --git a/frontend/custom_version_strategy.rst b/frontend/custom_version_strategy.rst index cdd4c6664be..ae64738e2df 100644 --- a/frontend/custom_version_strategy.rst +++ b/frontend/custom_version_strategy.rst @@ -141,8 +141,8 @@ After creating the strategy PHP class, register it as a Symfony service. use App\Asset\VersionStrategy\GulpBusterVersionStrategy; use Symfony\Component\DependencyInjection\Definition; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(GulpBusterVersionStrategy::class) ->args( diff --git a/http_cache/cache_invalidation.rst b/http_cache/cache_invalidation.rst index 48d451d3154..76c13ab975b 100644 --- a/http_cache/cache_invalidation.rst +++ b/http_cache/cache_invalidation.rst @@ -123,8 +123,8 @@ Then, register the class as a service that :doc:`decorates services(); + return function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(CacheKernel::class) ->decorate('http_cache') diff --git a/mailer.rst b/mailer.rst index ee69bd3b123..cdb6a259ede 100644 --- a/mailer.rst +++ b/mailer.rst @@ -57,8 +57,8 @@ over SMTP by configuring the DSN in your ``.env`` file (the ``user``, use function Symfony\Component\DependencyInjection\Loader\Configurator\env; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; - return static function (ContainerConfigurator $containerConfigurator): void { - $containerConfigurator->extension('framework', [ + return static function (ContainerConfigurator $container): void { + $container->extension('framework', [ 'mailer' => [ 'dsn' => env('MAILER_DSN'), ], diff --git a/messenger/multiple_buses.rst b/messenger/multiple_buses.rst index 08f788ec109..e96840fcb0d 100644 --- a/messenger/multiple_buses.rst +++ b/messenger/multiple_buses.rst @@ -204,8 +204,8 @@ you can determine the message bus based on an implemented interface: use App\MessageHandler\CommandHandlerInterface; use App\MessageHandler\QueryHandlerInterface; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); // ... diff --git a/profiler.rst b/profiler.rst index 8ae4d9dab36..ed89cfe7a08 100644 --- a/profiler.rst +++ b/profiler.rst @@ -512,8 +512,8 @@ you'll need to configure the data collector explicitly: use App\DataCollector\RequestCollector; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(RequestCollector::class) ->tag('data_collector', [ diff --git a/quick_tour/the_architecture.rst b/quick_tour/the_architecture.rst index 3bd459d2e3e..f42b4205316 100644 --- a/quick_tour/the_architecture.rst +++ b/quick_tour/the_architecture.rst @@ -286,12 +286,12 @@ using the special ``when@`` keyword: use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework, ContainerConfigurator $containerConfigurator) { + return static function (FrameworkConfig $framework, ContainerConfigurator $container) { $framework->router() ->utf8(true) ; - if ('prod' === $containerConfigurator->env()) { + if ('prod' === $container->env()) { $framework->router() ->strictRequirements(null) ; diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index c35eb5a575e..fa2b1daabe0 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -3356,8 +3356,8 @@ the `SMTP session`_. This value overrides any other recipient set in the code. // config/packages/mailer.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $containerConfigurator): void { - $containerConfigurator->extension('framework', [ + return static function (ContainerConfigurator $container): void { + $container->extension('framework', [ 'mailer' => [ 'dsn' => 'smtp://localhost:25', 'envelope' => [ diff --git a/reference/dic_tags.rst b/reference/dic_tags.rst index e707808e7e2..64cac27255e 100644 --- a/reference/dic_tags.rst +++ b/reference/dic_tags.rst @@ -122,8 +122,8 @@ services: use App\Lock\PostgresqlLock; use App\Lock\SqliteLock; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set('app.mysql_lock', MysqlLock::class); $services->set('app.postgresql_lock', PostgresqlLock::class); @@ -184,8 +184,8 @@ the generic ``app.lock`` service can be defined as follows: use App\Lock\PostgresqlLock; use App\Lock\SqliteLock; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set('app.mysql_lock', MysqlLock::class); $services->set('app.postgresql_lock', PostgresqlLock::class); diff --git a/routing/custom_route_loader.rst b/routing/custom_route_loader.rst index 7c050010ed5..78fd55f99aa 100644 --- a/routing/custom_route_loader.rst +++ b/routing/custom_route_loader.rst @@ -328,8 +328,8 @@ Now define a service for the ``ExtraLoader``: use App\Routing\ExtraLoader; - return static function (ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return static function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(ExtraLoader::class) ->tag('routing.loader') diff --git a/security.rst b/security.rst index a492e38fac7..9fe3801d01b 100644 --- a/security.rst +++ b/security.rst @@ -1572,7 +1572,7 @@ and set the ``limiter`` option to its service ID: use Symfony\Config\FrameworkConfig; use Symfony\Config\SecurityConfig; - return static function (ContainerBuilder $containerBuilder, FrameworkConfig $framework, SecurityConfig $security) { + return static function (ContainerBuilder $container, FrameworkConfig $framework, SecurityConfig $security) { $framework->rateLimiter() ->limiter('username_ip_login') ->policy('token_bucket') @@ -1588,7 +1588,7 @@ and set the ``limiter`` option to its service ID: ->interval('15 minutes') ; - $containerBuilder->register('app.login_rate_limiter', DefaultLoginRateLimiter::class) + $container->register('app.login_rate_limiter', DefaultLoginRateLimiter::class) ->setArguments([ // 1st argument is the limiter for IP new Reference('limiter.ip_login'), @@ -2589,8 +2589,8 @@ for these events. use App\EventListener\LogoutSubscriber; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(LogoutSubscriber::class) ->tag('kernel.event_subscriber', [ diff --git a/security/access_control.rst b/security/access_control.rst index 81aae70c602..b8a5f557286 100644 --- a/security/access_control.rst +++ b/security/access_control.rst @@ -91,8 +91,8 @@ Take the following ``access_control`` entries as an example: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\SecurityConfig; - return static function (ContainerBuilder $containerBuilder, SecurityConfig $security) { - $containerBuilder->setParameter('env(TRUSTED_IPS)', '10.0.0.1, 10.0.0.2'); + return static function (ContainerBuilder $container, SecurityConfig $security) { + $container->setParameter('env(TRUSTED_IPS)', '10.0.0.1, 10.0.0.2'); // ... $security->accessControl() diff --git a/service_container.rst b/service_container.rst index 47a421f1345..afd5ea44bd7 100644 --- a/service_container.rst +++ b/service_container.rst @@ -205,9 +205,9 @@ each time you ask for it. // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { + return function(ContainerConfigurator $container) { // default configuration for services in *this* file - $services = $containerConfigurator->services() + $services = $container->services() ->defaults() ->autowire() // Automatically injects dependencies in your services. ->autoconfigure() // Automatically registers your services as commands, event subscribers, etc. @@ -500,7 +500,7 @@ pass here. No problem! In your configuration, you can explicitly set this argume use App\Service\SiteUpdateManager; - return function(ContainerConfigurator $containerConfigurator) { + return function(ContainerConfigurator $container) { // ... // same as before @@ -575,8 +575,8 @@ parameter and in PHP config use the ``service()`` function: use App\Service\MessageGenerator; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(MessageGenerator::class) // In versions earlier to Symfony 5.1 the service() function was called ref() @@ -682,7 +682,7 @@ But, you can control this and pass in a different logger: use App\Service\MessageGenerator; - return function(ContainerConfigurator $containerConfigurator) { + return function(ContainerConfigurator $container) { // ... same code as before // explicitly configure the service @@ -783,8 +783,8 @@ You can also use the ``bind`` keyword to bind specific arguments by name or type use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services() + return function(ContainerConfigurator $container) { + $services = $container->services() ->defaults() // pass this value to any $adminEmail argument for any service // that's defined in this file (including controller arguments) @@ -918,7 +918,7 @@ setting: use App\Service\PublicService; - return function(ContainerConfigurator $containerConfigurator) { + return function(ContainerConfigurator $container) { // ... same as code before // explicitly configure the service @@ -975,7 +975,7 @@ key. For example, the default Symfony configuration contains this: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { + return function(ContainerConfigurator $container) { // ... // makes classes in src/ available to be used as services @@ -1157,7 +1157,7 @@ admin email. In this case, each needs to have a unique service id: use App\Service\MessageGenerator; use App\Service\SiteUpdateManager; - return function(ContainerConfigurator $containerConfigurator) { + return function(ContainerConfigurator $container) { // ... // site_update_manager.superadmin is the service's id diff --git a/service_container/alias_private.rst b/service_container/alias_private.rst index 44a8492a53d..e4f7604a846 100644 --- a/service_container/alias_private.rst +++ b/service_container/alias_private.rst @@ -55,8 +55,8 @@ You can also control the ``public`` option on a service-by-service basis: use App\Service\Foo; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(Foo::class) ->public(); @@ -127,8 +127,8 @@ services. use App\Mail\PhpMailer; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(PhpMailer::class) ->private(); @@ -275,8 +275,8 @@ The following example shows how to inject an anonymous service into another serv use App\AnonymousBar; use App\Foo; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(Foo::class) // In versions earlier to Symfony 5.1 the inline_service() function was called inline() @@ -327,8 +327,8 @@ Using an anonymous service as a factory looks like this: use App\AnonymousBar; use App\Foo; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(Foo::class) ->factory([inline_service(AnonymousBar::class), 'constructFoo']); @@ -373,8 +373,8 @@ or you decided not to maintain it anymore), you can deprecate its definition: use App\Service\OldService; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(OldService::class) ->deprecate( diff --git a/service_container/autowiring.rst b/service_container/autowiring.rst index 60baa01b261..cd53bbeef35 100644 --- a/service_container/autowiring.rst +++ b/service_container/autowiring.rst @@ -104,8 +104,8 @@ both services: .. code-block:: php // config/services.php - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services() + return function(ContainerConfigurator $container) { + $services = $container->services() ->defaults() ->autowire() ->autoconfigure() @@ -243,7 +243,7 @@ adding a service alias: use App\Util\Rot13Transformer; - return function(ContainerConfigurator $containerConfigurator) { + return function(ContainerConfigurator $container) { // ... // the id is not a class, so it won't be used for autowiring @@ -350,7 +350,7 @@ To fix that, add an :ref:`alias `: use App\Util\Rot13Transformer; use App\Util\TransformerInterface; - return function(ContainerConfigurator $containerConfigurator) { + return function(ContainerConfigurator $container) { // ... $services->set(Rot13Transformer::class); @@ -520,7 +520,7 @@ the injection:: use App\Util\TransformerInterface; use App\Util\UppercaseTransformer; - return function(ContainerConfigurator $containerConfigurator) { + return function(ContainerConfigurator $container) { // ... $services->set(Rot13Transformer::class)->autowire(); diff --git a/service_container/calls.rst b/service_container/calls.rst index a76cedbca2c..a40ca68e29c 100644 --- a/service_container/calls.rst +++ b/service_container/calls.rst @@ -66,7 +66,7 @@ To configure the container to call the ``setLogger`` method, use the ``calls`` k use App\Service\MessageGenerator; - return function(ContainerConfigurator $containerConfigurator) { + return function(ContainerConfigurator $container) { // ... $services->set(MessageGenerator::class) diff --git a/service_container/compiler_passes.rst b/service_container/compiler_passes.rst index 34eee2e67df..fda044a1195 100644 --- a/service_container/compiler_passes.rst +++ b/service_container/compiler_passes.rst @@ -22,9 +22,9 @@ Compiler passes are registered in the ``build()`` method of the application kern // ... - protected function build(ContainerBuilder $containerBuilder): void + protected function build(ContainerBuilder $container): void { - $containerBuilder->addCompilerPass(new CustomPass()); + $container->addCompilerPass(new CustomPass()); } } @@ -50,14 +50,14 @@ and process the services inside the ``process()`` method:: // ... - public function process(ContainerBuilder $containerBuilder): void + public function process(ContainerBuilder $container): void { // in this method you can manipulate the service container: // for example, changing some container service: - $containerBuilder->getDefinition('app.some_private_service')->setPublic(true); + $container->getDefinition('app.some_private_service')->setPublic(true); // or processing tagged services: - foreach ($containerBuilder->findTaggedServiceIds('some_tag') as $id => $tags) { + foreach ($container->findTaggedServiceIds('some_tag') as $id => $tags) { // ... } } @@ -79,11 +79,11 @@ method in the extension):: class MyBundle extends Bundle { - public function build(ContainerBuilder $containerBuilder): void + public function build(ContainerBuilder $container): void { - parent::build($containerBuilder); + parent::build($container); - $containerBuilder->addCompilerPass(new CustomPass()); + $container->addCompilerPass(new CustomPass()); } } diff --git a/service_container/configurators.rst b/service_container/configurators.rst index 055eb541ae8..1d289580815 100644 --- a/service_container/configurators.rst +++ b/service_container/configurators.rst @@ -169,8 +169,8 @@ all the classes are already loaded as services. All you need to do is specify th use App\Mail\GreetingCardManager; use App\Mail\NewsletterManager; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); // Registers all 4 classes as services, including App\Mail\EmailConfigurator $services->load('App\\', '../src/*'); @@ -239,8 +239,8 @@ Services can be configured via invokable configurators (replacing the use App\Mail\GreetingCardManager; use App\Mail\NewsletterManager; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); // Registers all 4 classes as services, including App\Mail\EmailConfigurator $services->load('App\\', '../src/*'); diff --git a/service_container/expression_language.rst b/service_container/expression_language.rst index 908ad68da5a..f1de823e47b 100644 --- a/service_container/expression_language.rst +++ b/service_container/expression_language.rst @@ -55,7 +55,7 @@ to another service: ``App\Mailer``. One way to do this is with an expression: use App\Mail\MailerConfiguration; use App\Mailer; - return function(ContainerConfigurator $containerConfigurator) { + return function(ContainerConfigurator $container) { // ... $services->set(MailerConfiguration::class); @@ -110,8 +110,8 @@ via a ``container`` variable. Here's another example: use App\Mailer; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(Mailer::class) ->args([expr("container.hasParameter('some_param') ? parameter('some_param') : 'default_value'")]); diff --git a/service_container/factories.rst b/service_container/factories.rst index 7c5c87dc004..a188bb2a046 100644 --- a/service_container/factories.rst +++ b/service_container/factories.rst @@ -74,8 +74,8 @@ create its object: use App\Email\NewsletterManager; use App\Email\NewsletterManagerStaticFactory; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(NewsletterManager::class) // the first argument is the class and the second argument is the static method @@ -156,8 +156,8 @@ You can omit the class on the factory declaration: use App\Email\NewsletterManager; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); // Note that we are not using service() $services->set(NewsletterManager::class) @@ -218,8 +218,8 @@ Configuration of the service container then looks like this: use App\Email\NewsletterManager; use App\Email\NewsletterManagerFactory; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); // first, create a service for the factory $services->set(NewsletterManagerFactory::class); @@ -297,8 +297,8 @@ method name: use App\Email\NewsletterManager; use App\Email\NewsletterManagerFactory; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(NewsletterManager::class) ->factory(service(InvokableNewsletterManagerFactory::class)); @@ -357,8 +357,8 @@ previous examples takes the ``templating`` service as an argument: use App\Email\NewsletterManager; use App\Email\NewsletterManagerFactory; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(NewsletterManager::class) ->factory([service(NewsletterManagerFactory::class), 'createNewsletterManager']) diff --git a/service_container/import.rst b/service_container/import.rst index 2fed44e16a5..1e0fcfb2cee 100644 --- a/service_container/import.rst +++ b/service_container/import.rst @@ -116,12 +116,12 @@ a relative or absolute path to the imported file: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { - $containerConfigurator->import('services/mailer.php'); + return function(ContainerConfigurator $container) { + $container->import('services/mailer.php'); // If you want to import a whole directory: - $containerConfigurator->import('services/'); + $container->import('services/'); - $services = $containerConfigurator->services() + $services = $container->services() ->defaults() ->autowire() ->autoconfigure() diff --git a/service_container/injection_types.rst b/service_container/injection_types.rst index d88e5139824..595ac79b185 100644 --- a/service_container/injection_types.rst +++ b/service_container/injection_types.rst @@ -71,8 +71,8 @@ service container configuration: use App\Mail\NewsletterManager; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(NewsletterManager::class) // In versions earlier to Symfony 5.1 the service() function was called ref() @@ -274,8 +274,8 @@ that accepts the dependency:: use App\Mail\NewsletterManager; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(NewsletterManager::class) ->call('setMailer', [service('mailer')]); @@ -356,8 +356,8 @@ Another possibility is setting public fields of the class directly:: use App\Mail\NewsletterManager; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set('app.newsletter_manager', NewsletterManager::class) ->property('mailer', service('mailer')); diff --git a/service_container/lazy_services.rst b/service_container/lazy_services.rst index bdac2a0bc46..bf45e100ef8 100644 --- a/service_container/lazy_services.rst +++ b/service_container/lazy_services.rst @@ -76,8 +76,8 @@ You can mark the service as ``lazy`` by manipulating its definition: use App\Twig\AppExtension; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(AppExtension::class)->lazy(); }; @@ -170,8 +170,8 @@ specific interfaces. use App\Twig\AppExtension; use Twig\Extension\ExtensionInterface; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(AppExtension::class) ->lazy() diff --git a/service_container/optional_dependencies.rst b/service_container/optional_dependencies.rst index 8317cd363df..86aa0c2eb22 100644 --- a/service_container/optional_dependencies.rst +++ b/service_container/optional_dependencies.rst @@ -38,8 +38,8 @@ if the service does not exist: use App\Newsletter\NewsletterManager; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(NewsletterManager::class) // In versions earlier to Symfony 5.1 the service() function was called ref() @@ -95,8 +95,8 @@ call if the service exists and remove the method call if it does not: use App\Newsletter\NewsletterManager; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(NewsletterManager::class) ->call('setLogger', [service('logger')->ignoreOnInvalid()]) diff --git a/service_container/parent_services.rst b/service_container/parent_services.rst index 9cab17e2254..b3792dc5a6a 100644 --- a/service_container/parent_services.rst +++ b/service_container/parent_services.rst @@ -119,8 +119,8 @@ avoid duplicated service definitions: use App\Repository\DoctrinePostRepository; use App\Repository\DoctrineUserRepository; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(BaseDoctrineRepository::class) ->abstract() @@ -229,8 +229,8 @@ the child class: use App\Repository\DoctrineUserRepository; // ... - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(BaseDoctrineRepository::class) // ... diff --git a/service_container/service_closures.rst b/service_container/service_closures.rst index 03e142b3455..723aa26e8bf 100644 --- a/service_container/service_closures.rst +++ b/service_container/service_closures.rst @@ -77,8 +77,8 @@ argument of type ``service_closure``: use App\Service\MyService; - return function (ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(MyService::class) ->args([service_closure('mailer')]); @@ -104,7 +104,7 @@ a service closure by wrapping the service reference into an instance of use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; - public function process(ContainerBuilder $containerBuilder): void + public function process(ContainerBuilder $container): void { // ... diff --git a/service_container/service_decoration.rst b/service_container/service_decoration.rst index 1bf0bf86d1e..5d663fbc797 100644 --- a/service_container/service_decoration.rst +++ b/service_container/service_decoration.rst @@ -41,8 +41,8 @@ When overriding an existing definition, the original service is lost: use App\Mailer; use App\NewMailer; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(Mailer::class); @@ -98,8 +98,8 @@ but keeps a reference of the old one as ``.inner``: use App\DecoratingMailer; use App\Mailer; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(Mailer::class); @@ -161,8 +161,8 @@ automatically changed to ``'.inner'``): use App\DecoratingMailer; use App\Mailer; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(Mailer::class); @@ -233,8 +233,8 @@ automatically changed to ``'.inner'``): use App\DecoratingMailer; use App\Mailer; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(Mailer::class); @@ -295,8 +295,8 @@ the ``decoration_priority`` option. Its value is an integer that defaults to // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(\Foo::class); @@ -382,8 +382,8 @@ ordered services, each one decorating the next: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { - $containerConfigurator->services() + return function(ContainerConfigurator $container) { + $container->services() ->stack('decorated_foo_stack', [ inline_service(\Baz::class)->args([service('.inner')]), inline_service(\Bar::class)->args([service('.inner')]), @@ -465,8 +465,8 @@ advanced example of composition: use App\Decorated; use App\Decorator; - return function(ContainerConfigurator $containerConfigurator) { - $containerConfigurator->services() + return function(ContainerConfigurator $container) { + $container->services() ->set('some_decorator', Decorator::class) ->stack('embedded_stack', [ @@ -583,8 +583,8 @@ Three different behaviors are available: use Symfony\Component\DependencyInjection\ContainerInterface; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(Foo::class); diff --git a/service_container/service_subscribers_locators.rst b/service_container/service_subscribers_locators.rst index 86389a71144..1b152ac6d68 100644 --- a/service_container/service_subscribers_locators.rst +++ b/service_container/service_subscribers_locators.rst @@ -233,8 +233,8 @@ service type to a service. use App\CommandBus; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(CommandBus::class) ->tag('container.service_subscriber', ['key' => 'logger', 'id' => 'monolog.logger.event']); @@ -325,8 +325,8 @@ or directly via PHP attributes: use App\CommandBus; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(CommandBus::class) ->args([service_locator([ @@ -409,8 +409,8 @@ other services. To do so, create a new service definition using the use Symfony\Component\DependencyInjection\ServiceLocator; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set('app.command_handler_locator', ServiceLocator::class) // In versions earlier to Symfony 5.1 the service() function was called ref() @@ -471,8 +471,8 @@ Now you can inject the service locator in any other services: use App\CommandBus; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(CommandBus::class) ->args([service('app.command_handler_locator')]); @@ -490,7 +490,7 @@ will share identical locators among all the services referencing them:: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; - public function process(ContainerBuilder $containerBuilder): void + public function process(ContainerBuilder $container): void { // ... @@ -499,9 +499,9 @@ will share identical locators among all the services referencing them:: 'logger' => new Reference('logger'), ]; - $myService = $containerBuilder->findDefinition(MyService::class); + $myService = $container->findDefinition(MyService::class); - $myService->addArgument(ServiceLocatorTagPass::register($containerBuilder, $locateableServices)); + $myService->addArgument(ServiceLocatorTagPass::register($container, $locateableServices)); } Indexing the Collection of Services @@ -579,8 +579,8 @@ of the ``key`` tag attribute (as defined in the ``index_by`` locator option): // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(App\Handler\One::class) ->tag('app.handler', ['key' => 'handler_one']) @@ -686,8 +686,8 @@ attribute to the locator service defining the name of this custom method: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { - $containerConfigurator->services() + return function(ContainerConfigurator $container) { + $container->services() ->set(App\HandlerCollection::class) ->args([tagged_locator('app.handler', 'key', 'myOwnMethodName')]) ; diff --git a/service_container/shared.rst b/service_container/shared.rst index 003ad2914b7..435822fb25c 100644 --- a/service_container/shared.rst +++ b/service_container/shared.rst @@ -33,8 +33,8 @@ in your service definition: use App\SomeNonSharedService; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(SomeNonSharedService::class) ->share(false); diff --git a/service_container/synthetic_services.rst b/service_container/synthetic_services.rst index 4dfec92709f..fc26c6848d3 100644 --- a/service_container/synthetic_services.rst +++ b/service_container/synthetic_services.rst @@ -63,8 +63,8 @@ configuration: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); // synthetic services don't specify a class $services->set('app.synthetic_service') diff --git a/service_container/tags.rst b/service_container/tags.rst index 8777639cd60..bcb30e7da3e 100644 --- a/service_container/tags.rst +++ b/service_container/tags.rst @@ -37,8 +37,8 @@ example: use App\Twig\AppExtension; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(AppExtension::class) ->tag('twig.extension'); @@ -103,8 +103,8 @@ If you want to apply tags automatically for your own services, use the use App\Security\CustomInterface; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); // this config only applies to the services created by this file $services @@ -147,9 +147,9 @@ In a Symfony application, call this method in your kernel class:: { // ... - protected function build(ContainerBuilder $containerBuilder): void + protected function build(ContainerBuilder $container): void { - $containerBuilder->registerForAutoconfiguration(CustomInterface::class) + $container->registerForAutoconfiguration(CustomInterface::class) ->addTag('app.custom_tag') ; } @@ -163,9 +163,9 @@ In a Symfony bundle, call this method in the ``load()`` method of the { // ... - public function load(array $configs, ContainerBuilder $containerBuilder): void + public function load(array $configs, ContainerBuilder $container): void { - $containerBuilder->registerForAutoconfiguration(CustomInterface::class) + $container->registerForAutoconfiguration(CustomInterface::class) ->addTag('app.custom_tag') ; } @@ -202,11 +202,11 @@ method:: { // ... - protected function build(ContainerBuilder $containerBuilder): void + protected function build(ContainerBuilder $container): void { // ... - $containerBuilder->registerAttributeForAutoconfiguration(SensitiveElement::class, static function (ChildDefinition $definition, SensitiveElement $attribute, \ReflectionClass $reflector): void { + $container->registerAttributeForAutoconfiguration(SensitiveElement::class, static function (ChildDefinition $definition, SensitiveElement $attribute, \ReflectionClass $reflector): void { // Apply the 'app.sensitive_element' tag to all classes with SensitiveElement // attribute, and attach the token value to the tag $definition->addTag('app.sensitive_element', ['token' => $attribute->getToken()]); @@ -284,8 +284,8 @@ Then, define the chain as a service: use App\Mail\TransportChain; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(TransportChain::class); }; @@ -338,8 +338,8 @@ For example, you may add the following transports as services: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(\MailerSmtpTransport::class) // the param() method was introduced in Symfony 5.2. @@ -374,17 +374,17 @@ container for any services with the ``app.mail_transport`` tag:: class MailTransportPass implements CompilerPassInterface { - public function process(ContainerBuilder $containerBuilder): void + public function process(ContainerBuilder $container): void { // always first check if the primary service is defined - if (!$containerBuilder->has(TransportChain::class)) { + if (!$container->has(TransportChain::class)) { return; } - $definition = $containerBuilder->findDefinition(TransportChain::class); + $definition = $container->findDefinition(TransportChain::class); // find all service IDs with the app.mail_transport tag - $taggedServices = $containerBuilder->findTaggedServiceIds('app.mail_transport'); + $taggedServices = $container->findTaggedServiceIds('app.mail_transport'); foreach ($taggedServices as $id => $tags) { // add the transport service to the TransportChain service @@ -411,9 +411,9 @@ or from your kernel:: { // ... - protected function build(ContainerBuilder $containerBuilder): void + protected function build(ContainerBuilder $container): void { - $containerBuilder->addCompilerPass(new MailTransportPass()); + $container->addCompilerPass(new MailTransportPass()); } } @@ -501,8 +501,8 @@ To answer this, change the service declaration: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(\MailerSmtpTransport::class) // the param() method was introduced in Symfony 5.2. @@ -545,7 +545,7 @@ use this, update the compiler:: class TransportCompilerPass implements CompilerPassInterface { - public function process(ContainerBuilder $containerBuilder): void + public function process(ContainerBuilder $container): void { // ... @@ -655,8 +655,8 @@ directly via PHP attributes: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(App\Handler\One::class) ->tag('app.handler') @@ -720,8 +720,8 @@ the number, the earlier the tagged service will be located in the collection: use App\Handler\One; - return function(ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function(ContainerConfigurator $container) { + $services = $container->services(); $services->set(One::class) ->tag('app.handler', ['priority' => 20]) @@ -796,8 +796,8 @@ you can define it in the configuration of the collecting service: use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; - return function (ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function (ContainerConfigurator $container) { + $services = $container->services(); // ... @@ -884,8 +884,8 @@ indexed by the ``key`` attribute: use App\Handler\Two; use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; - return function (ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(One::class) ->tag('app.handler', ['key' => 'handler_one']); @@ -998,8 +998,8 @@ array element. For example, to retrieve the ``handler_two`` handler:: use App\HandlerCollection; use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; - return function (ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return function (ContainerConfigurator $container) { + $services = $container->services(); // ... diff --git a/session.rst b/session.rst index 1124eea36a8..621749eadb0 100644 --- a/session.rst +++ b/session.rst @@ -723,8 +723,8 @@ To use it, first register a new handler service with your database credentials: use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; - return static function (ContainerConfigurator $containerConfiguratorConfigurator) { - $services = $containerConfigurator->services(); + return static function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(PdoSessionHandler::class) ->args([ @@ -838,8 +838,8 @@ passed to the ``PdoSessionHandler`` service: use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; - return static function (ContainerConfigurator $containerConfiguratorConfigurator) { - $services = $containerConfigurator->services(); + return static function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(PdoSessionHandler::class) ->args([ @@ -1011,8 +1011,8 @@ the MongoDB connection as argument: use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler; - return static function (ContainerConfigurator $containerConfiguratorConfigurator) { - $services = $containerConfigurator->services(); + return static function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(MongoDbSessionHandler::class) ->args([ @@ -1130,8 +1130,8 @@ configure these values with the second argument passed to the use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler; - return static function (ContainerConfigurator $containerConfigurator) { - $services = $containerConfigurator->services(); + return static function (ContainerConfigurator $container) { + $services = $container->services(); $services->set(MongoDbSessionHandler::class) ->args([ diff --git a/testing.rst b/testing.rst index ed0ab1a8e2c..24326be908a 100644 --- a/testing.rst +++ b/testing.rst @@ -357,8 +357,8 @@ the ``test`` environment as follows: use App\Contracts\Repository\NewsRepositoryInterface; use App\Repository\NewsRepository; - return static function (ContainerConfigurator $containerConfigurator) { - $containerConfigurator->services() + return static function (ContainerConfigurator $container) { + $container->services() // redefine the alias as it should be while making it public ->alias(NewsRepositoryInterface::class, NewsRepository::class) ->public() From d59f96070b5c51f7116a4f2e53c4b61fe986e1de Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Wed, 10 May 2023 22:16:14 +0200 Subject: [PATCH 037/205] Remove versionadded 5.2 on 6.x branch --- form/form_customization.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/form/form_customization.rst b/form/form_customization.rst index 1df12a0bc9c..7b4844247f5 100644 --- a/form/form_customization.rst +++ b/form/form_customization.rst @@ -127,10 +127,6 @@ fields, so you no longer have to deal with form themes: {% endfor %} -.. versionadded:: 5.2 - - The ``field_*()`` helpers were introduced in Symfony 5.2. - Form Rendering Variables ------------------------ From 2426ce44af403fde87d4989d2824c0f8d8e11bdf Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Sat, 11 Mar 2023 14:25:14 +0100 Subject: [PATCH 038/205] Be consistent in code examples --- service_container/service_closures.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/service_container/service_closures.rst b/service_container/service_closures.rst index d490bcb3769..1a6b6542680 100644 --- a/service_container/service_closures.rst +++ b/service_container/service_closures.rst @@ -58,6 +58,9 @@ argument of type ``service_closure``: App\Service\MyService: arguments: [!service_closure '@mailer'] + # In case the dependency is optional + # arguments: [!service_closure '@?mailer'] + .. code-block:: xml @@ -69,6 +72,11 @@ argument of type ``service_closure``: + + From f7e1af2b238c60ce47e4f746359c0f7bcbbd7ad2 Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Fri, 12 May 2023 09:42:28 +0200 Subject: [PATCH 039/205] Add some typehint --- controller/service.rst | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/controller/service.rst b/controller/service.rst index 1510f7b8278..50ee34a1aac 100644 --- a/controller/service.rst +++ b/controller/service.rst @@ -31,6 +31,7 @@ apply the ``controller.service_arguments`` tag to your controller services:: // src/Controller/HelloController.php namespace App\Controller; + use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Annotation\Route; @@ -38,7 +39,7 @@ apply the ``controller.service_arguments`` tag to your controller services:: class HelloController { #[Route('/hello', name: 'hello', methods: ['GET'])] - public function index() + public function index(): Response { // ... } @@ -71,7 +72,7 @@ a service like: ``App\Controller\HelloController::index``: /** * @Route("/hello", name="hello", methods={"GET"}) */ - public function index() + public function index(): Response { // ... } @@ -82,12 +83,13 @@ a service like: ``App\Controller\HelloController::index``: // src/Controller/HelloController.php namespace App\Controller; + use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class HelloController { #[Route('/hello', name: 'hello', methods: ['GET'])] - public function index() + public function index(): Response { // ... } @@ -151,7 +153,7 @@ which is a common practice when following the `ADR pattern`_ */ class Hello { - public function __invoke($name = 'World') + public function __invoke(string $name = 'World'): Response { return new Response(sprintf('Hello %s!', $name)); } @@ -168,7 +170,7 @@ which is a common practice when following the `ADR pattern`_ #[Route('/hello/{name}', name: 'hello')] class Hello { - public function __invoke($name = 'World') + public function __invoke(string $name = 'World'): Response { return new Response(sprintf('Hello %s!', $name)); } @@ -228,14 +230,14 @@ service and use it directly:: class HelloController { - private $twig; + private Environment $twig; public function __construct(Environment $twig) { $this->twig = $twig; } - public function index($name) + public function index(string $name): Response { $content = $this->twig->render( 'hello/index.html.twig', From ae34e2c12fa9f85185292dcd9b4bd033517babcc Mon Sep 17 00:00:00 2001 From: Jon Green Date: Mon, 15 May 2023 15:04:49 +0100 Subject: [PATCH 040/205] Add missing `use` statement to databases & doctrine page --- doctrine.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doctrine.rst b/doctrine.rst index cca47d1b0f4..d84b20f6583 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -813,6 +813,7 @@ with any PHP model:: use App\Entity\Product; use App\Repository\ProductRepository; + use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; // ... From 90ff99b876be20fead963396a6e8c20394933de5 Mon Sep 17 00:00:00 2001 From: pavdovlatov <129055488+pavdovlatov@users.noreply.github.com> Date: Wed, 17 May 2023 14:20:58 +0300 Subject: [PATCH 041/205] Fixed typo in messenger.rst --- messenger.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messenger.rst b/messenger.rst index a1d76eb3e57..ba8e4a76936 100644 --- a/messenger.rst +++ b/messenger.rst @@ -2484,7 +2484,7 @@ of the process. For each, the event class is the event name: .. versionadded:: 6.2 - The ``WorkerRateLimitedEvent`` was introduced in Symfony 6.3. + The ``WorkerRateLimitedEvent`` was introduced in Symfony 6.2. Multiple Buses, Command & Event Buses ------------------------------------- From 02d5477d1f4ee3557069a20a1c638c5e59acabb7 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 19 May 2023 10:17:23 +0200 Subject: [PATCH 042/205] Use DOCtor-RST 1.46.1 --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 79f2c12e4fb..744cc957c6c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -73,7 +73,7 @@ jobs: key: ${{ runner.os }}-doctor-rst-${{ steps.extract_base_branch.outputs.branch }} - name: "Run DOCtor-RST" - uses: docker://oskarstark/doctor-rst:1.45.0 + uses: docker://oskarstark/doctor-rst:1.46.1 with: args: --short --error-format=github --cache-file=/github/workspace/.cache/doctor-rst.cache From e32ee28127f277f4ccb208046541004f08328b3c Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 19 May 2023 10:22:52 +0200 Subject: [PATCH 043/205] Enable new DOCtor rule `no_duplicate_use_statements` --- .doctor-rst.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.doctor-rst.yaml b/.doctor-rst.yaml index 318d55b688a..a1623233d96 100644 --- a/.doctor-rst.yaml +++ b/.doctor-rst.yaml @@ -34,6 +34,7 @@ rules: no_brackets_in_method_directive: ~ no_composer_req: ~ no_directive_after_shorthand: ~ + no_duplicate_use_statements: ~ no_explicit_use_of_code_block_php: ~ no_inheritdoc: ~ no_merge_conflict: ~ From e419c65fb40eebceef743bfc14e6c6b8ba6ab254 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 19 May 2023 21:56:44 +0200 Subject: [PATCH 044/205] Use `ubuntu-latest` --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 744cc957c6c..492d38ff045 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -79,7 +79,7 @@ jobs: symfony-code-block-checker: name: Code Blocks - runs-on: Ubuntu-20.04 + runs-on: ubuntu-latest continue-on-error: true steps: - name: Checkout code From e73b674985714d18b328c6bd1a6f6d1ed3732424 Mon Sep 17 00:00:00 2001 From: uncaught Date: Mon, 22 May 2023 08:36:34 +0200 Subject: [PATCH 045/205] Fix non-working examples of `json` and `csv` env var processors (closes https://github.com/symfony/symfony/issues/50341). --- configuration/env_var_processors.rst | 32 ++++++++++++---------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/configuration/env_var_processors.rst b/configuration/env_var_processors.rst index cc6782baabb..0a76793cc2c 100644 --- a/configuration/env_var_processors.rst +++ b/configuration/env_var_processors.rst @@ -262,9 +262,8 @@ Symfony provides the following env var processors: # config/packages/framework.yaml parameters: - env(TRUSTED_HOSTS): '["10.0.0.1", "10.0.0.2"]' - framework: - trusted_hosts: '%env(json:TRUSTED_HOSTS)%' + env(ALLOWED_LANGUAGES): '["en","de","es"]' + app_allowed_languages: '%env(json:ALLOWED_LANGUAGES)%' .. code-block:: xml @@ -279,10 +278,9 @@ Symfony provides the following env var processors: https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - ["10.0.0.1", "10.0.0.2"] + ["en","de","es"] + %env(json:ALLOWED_LANGUAGES)% - - .. code-block:: php @@ -293,9 +291,9 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $container, FrameworkConfig $framework) { - $container->setParameter('env(TRUSTED_HOSTS)', '["10.0.0.1", "10.0.0.2"]'); - $framework->trustedHosts(env('TRUSTED_HOSTS')->json()); + return static function (ContainerBuilder $container) { + $container->setParameter('env(ALLOWED_LANGUAGES)', '["en","de","es"]'); + $container->setParameter('app_allowed_languages', '%env(json:ALLOWED_LANGUAGES)%'); }; ``env(resolve:FOO)`` @@ -348,9 +346,8 @@ Symfony provides the following env var processors: # config/packages/framework.yaml parameters: - env(TRUSTED_HOSTS): "10.0.0.1,10.0.0.2" - framework: - trusted_hosts: '%env(csv:TRUSTED_HOSTS)%' + env(ALLOWED_LANGUAGES): "en,de,es" + app_allowed_languages: '%env(csv:ALLOWED_LANGUAGES)%' .. code-block:: xml @@ -365,10 +362,9 @@ Symfony provides the following env var processors: https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - 10.0.0.1,10.0.0.2 + en,de,es + %env(csv:ALLOWED_LANGUAGES)% - - .. code-block:: php @@ -379,9 +375,9 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $container, FrameworkConfig $framework) { - $container->setParameter('env(TRUSTED_HOSTS)', '10.0.0.1,10.0.0.2'); - $framework->trustedHosts(env('TRUSTED_HOSTS')->csv()); + return static function (ContainerBuilder $container) { + $container->setParameter('env(ALLOWED_LANGUAGES)', 'en,de,es'); + $container->setParameter('app_allowed_languages', '%env(csv:ALLOWED_LANGUAGES)%'); }; ``env(file:FOO)`` From 84b52284bc5f3509f7daf3534a2f9e2337db5104 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 19 May 2023 10:05:14 +0200 Subject: [PATCH 046/205] Use DOCtor-RST 1.47.1 --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 744cc957c6c..0f17933d8ae 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -73,7 +73,7 @@ jobs: key: ${{ runner.os }}-doctor-rst-${{ steps.extract_base_branch.outputs.branch }} - name: "Run DOCtor-RST" - uses: docker://oskarstark/doctor-rst:1.46.1 + uses: docker://oskarstark/doctor-rst:1.47.1 with: args: --short --error-format=github --cache-file=/github/workspace/.cache/doctor-rst.cache From 64cb70171f51b82d747bd396ce1cb5ad498d2a15 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Fri, 12 May 2023 12:46:42 -0300 Subject: [PATCH 047/205] [Serializer] Fix data type according to the field name on serializer.rst --- serializer.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serializer.rst b/serializer.rst index b7b62efa843..7bf972e908e 100644 --- a/serializer.rst +++ b/serializer.rst @@ -312,7 +312,7 @@ to your class:: private $name; /** - * @ORM\Column(type="integer") + * @ORM\Column(type="text") * @Groups({"show_product"}) */ private $description; From 6f74096cdc0105dba561bac1637159791b747d36 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Wed, 17 May 2023 20:22:49 +0200 Subject: [PATCH 048/205] [FormCollection] mention Symfony UX live collection --- form/form_collections.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/form/form_collections.rst b/form/form_collections.rst index 540f8d50377..601d49f689d 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -213,6 +213,11 @@ Previously you added two tags to your task in the controller. Now let the users add as many tag forms as they need directly in the browser. This requires a bit of JavaScript code. +.. tip:: + + You can leverage Symfony UX via https://ux.symfony.com/live-component/demos/form-collection-type + if you do not want to handle the JavaScript code yourself. + But first, you need to let the form collection know that instead of exactly two, it will receive an *unknown* number of tags. Otherwise, you'll see a *"This form should not contain extra fields"* error. This is done with the From 7f6a8e2cfdb72b607d0f2c48af0a8c98868f275b Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 22 May 2023 10:59:14 +0200 Subject: [PATCH 049/205] Tweaks --- form/form_collections.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/form/form_collections.rst b/form/form_collections.rst index 601d49f689d..a2726ed1ed6 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -215,8 +215,9 @@ of JavaScript code. .. tip:: - You can leverage Symfony UX via https://ux.symfony.com/live-component/demos/form-collection-type - if you do not want to handle the JavaScript code yourself. + Instead of writing the needed JavaScript code yourself, you can use Symfony + UX to implement this feature with only PHP and Twig code. See the + `Symfony UX Demo of Form Collections`_. But first, you need to let the form collection know that instead of exactly two, it will receive an *unknown* number of tags. Otherwise, you'll see a @@ -662,3 +663,4 @@ the relationship between the removed ``Tag`` and ``Task`` object. .. _`@a2lix/symfony-collection`: https://github.com/a2lix/symfony-collection .. _`symfony-collection`: https://github.com/ninsuo/symfony-collection .. _`ArrayCollection`: https://www.doctrine-project.org/projects/doctrine-collections/en/1.6/index.html +.. _`Symfony UX Demo of Form Collections`: https://ux.symfony.com/live-component/demos/form-collection-type From be256a1acc52427ddc9918134e46936748365cc9 Mon Sep 17 00:00:00 2001 From: Jorick <48644518+JorickPepin@users.noreply.github.com> Date: Wed, 24 May 2023 09:52:21 +0200 Subject: [PATCH 050/205] [Doctrine] Replace entityManager by objectManager --- doctrine.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doctrine.rst b/doctrine.rst index d84b20f6583..164ed72ed09 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -784,13 +784,13 @@ control behavior: If true, then when ``findOneBy()`` is used, any values that are ``null`` will not be used for the query. -``entityManager`` +``objectManager`` By default, the ``EntityValueResolver`` uses the *default* - entity manager, but you can configure this:: + object manager, but you can configure this:: #[Route('/product/{id}')] public function show( - #[MapEntity(entityManager: ['foo'])] + #[MapEntity(objectManager: 'foo')] Product $product ): Response { } From fee66c0fb88044a3b433720190f4926ea3f42572 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Wed, 24 May 2023 10:01:51 +0200 Subject: [PATCH 051/205] Fix code block --- lock.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lock.rst b/lock.rst index 3e93173aedc..8d5dc62617f 100644 --- a/lock.rst +++ b/lock.rst @@ -281,7 +281,7 @@ case version of its name suffixed by ``LockFactory``. For instance, the ``invoice`` lock can be injected by naming the argument ``$invoiceLockFactory`` and type-hinting it with -:class:`Symfony\\Component\\Lock\\LockFactory`: +:class:`Symfony\\Component\\Lock\\LockFactory`:: // src/Controller/PdfController.php namespace App\Controller; From 0cc61f75d762244e14c4267fa4e3d8b111c207dd Mon Sep 17 00:00:00 2001 From: Terence Eden Date: Sun, 21 May 2023 21:03:46 +0100 Subject: [PATCH 052/205] Update error_pages.rst I couldn't find any explicit documentation about `{{ exception.message }}` This adds it in and provides a link to to class so that readers can find the other methods available. --- controller/error_pages.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/controller/error_pages.rst b/controller/error_pages.rst index 7ccb05cdf65..5cad96b742c 100644 --- a/controller/error_pages.rst +++ b/controller/error_pages.rst @@ -114,10 +114,14 @@ store the HTTP status code and message respectively. and its required ``getStatusCode()`` method. Otherwise, the ``status_code`` will default to ``500``. -Additionally you have access to the Exception with ``exception``, which for example -allows you to output the stack trace using ``{{ exception.traceAsString }}`` or -access any other method on the object. You should be careful with this though, -as this is very likely to expose sensitive data. +Additionally you have access to the Exception with ``exception``. +This allows you to access any method of :class:`Symfony\\Component\\HttpKernel\\Exception\\HttpException`. +For example, if an exception message has been set, using +``throw $this->createNotFoundException('The product does not exist');``, +this can be accessed with ``{{ exception.message }}``. +You can output the stack trace using ``{{ exception.traceAsString }}`` +You should be careful with this though, as it is very likely to expose +sensitive data. .. tip:: From 93a056bb231c8f033f2b0c8117c3b518b3909f9d Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 24 May 2023 15:31:49 +0200 Subject: [PATCH 053/205] Tweaks --- controller/error_pages.rst | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/controller/error_pages.rst b/controller/error_pages.rst index 5cad96b742c..56f8e60a408 100644 --- a/controller/error_pages.rst +++ b/controller/error_pages.rst @@ -114,14 +114,12 @@ store the HTTP status code and message respectively. and its required ``getStatusCode()`` method. Otherwise, the ``status_code`` will default to ``500``. -Additionally you have access to the Exception with ``exception``. -This allows you to access any method of :class:`Symfony\\Component\\HttpKernel\\Exception\\HttpException`. -For example, if an exception message has been set, using -``throw $this->createNotFoundException('The product does not exist');``, -this can be accessed with ``{{ exception.message }}``. -You can output the stack trace using ``{{ exception.traceAsString }}`` -You should be careful with this though, as it is very likely to expose -sensitive data. +Additionally you have access to the :class:`Symfony\\Component\\HttpKernel\\Exception\\HttpException` +object via the ``exception`` Twig variable. For example, if the exception sets a +message (e.g. using ``throw $this->createNotFoundException('The product does not exist')``), +use ``{{ exception.message }}`` to print that message. You can also output the +stack trace using ``{{ exception.traceAsString }}``, but don't do that for end +users because the trace contains sensitive data. .. tip:: From 815b159ce016a5dff7d1c3e51f86256cf04f573d Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 26 May 2023 13:46:57 -0400 Subject: [PATCH 054/205] Updating UX docs to install the new StimulusBundle --- frontend/encore/simple-example.rst | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/frontend/encore/simple-example.rst b/frontend/encore/simple-example.rst index d41da8daf84..2e5043c5f83 100644 --- a/frontend/encore/simple-example.rst +++ b/frontend/encore/simple-example.rst @@ -5,10 +5,7 @@ After :doc:`installing Encore `, your app already has a few files, organized into an ``assets/`` directory: * ``assets/app.js`` -* ``assets/bootstrap.js`` -* ``assets/controllers.json`` * ``assets/styles/app.css`` -* ``assets/controllers/hello_controller.js`` With Encore, think of your ``app.js`` file like a standalone JavaScript application: it will *require* all of the dependencies it needs (e.g. jQuery or React), @@ -27,9 +24,6 @@ statements and create one final ``app.js`` (and ``app.css``) that contains *ever your app needs. Encore can do a lot more: minify files, pre-process Sass/LESS, support React, Vue.js, etc. -The other files - ``bootstrap.js``, ``controllers.json`` and ``hello_controller.js`` -relate to a topic you'll learn about soon: `Stimulus & Symfony UX`_. - Configuring Encore/Webpack -------------------------- @@ -222,10 +216,18 @@ easy to attach behavior to HTML. It's powerful, and you will love it! Symfony even provides packages to add more features to Stimulus. These are called the Symfony UX Packages. -If you followed the setup instructions, you should already have Stimulus installed -and ready to go! In fact, that's the purpose of the ``assets/bootstrap.js`` file: -to initialize Stimulus and automatically load any "controllers" from the -``assets/controllers/`` directory. +To use Stimulus, first install StimulusBundle: + +.. code-block:: terminal + + $ composer require symfony/stimulus-bundle + +The Flex recipe should add several files/directories: + +* ``assets/bootstrap.js`` - initializes Stimulus; +* ``assets/controllers/`` - a directory where you'll put your Stimulus controllers; +* ``assets/controllers.json`` - file that helps load Stimulus controllers form UX + packages that you'll install. Let's look at a simple Stimulus example. In a Twig template, suppose you have: From 07c7ba942aa0f10b23baf88b9fa5c4a9e892682f Mon Sep 17 00:00:00 2001 From: jmsche Date: Fri, 26 May 2023 21:11:58 +0200 Subject: [PATCH 055/205] Update docs about creating a UX bundle after stimulus bundle release --- frontend/create_ux_bundle.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/create_ux_bundle.rst b/frontend/create_ux_bundle.rst index 8bc04725bcd..095b9c6d84b 100644 --- a/frontend/create_ux_bundle.rst +++ b/frontend/create_ux_bundle.rst @@ -108,7 +108,7 @@ To use your controller in a template (e.g. one defined in your bundle) you can u ... -Don't forget to add ``symfony/webpack-encore-bundle:^1.12`` as a composer dependency to use +Don't forget to add ``symfony/stimulus-bundle:^2.9`` as a composer dependency to use Twig ``stimulus_*`` functions. .. tip:: From 20a7e795009d942db4031ad2d8a42f972a913091 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 30 May 2023 12:01:25 +0200 Subject: [PATCH 056/205] [Security] Use POST method for logout route --- security.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/security.rst b/security.rst index 9fe3801d01b..ad62fed4ba8 100644 --- a/security.rst +++ b/security.rst @@ -1686,7 +1686,7 @@ Next, you need to create a route for this URL (but not a controller): class SecurityController extends AbstractController { /** - * @Route("/logout", name="app_logout", methods={"GET"}) + * @Route("/logout", name="app_logout", methods={"POST"}) */ public function logout(): void { @@ -1705,7 +1705,7 @@ Next, you need to create a route for this URL (but not a controller): class SecurityController extends AbstractController { - #[Route('/logout', name: 'app_logout', methods: ['GET'])] + #[Route('/logout', name: 'app_logout', methods: ['POST'])] public function logout() { // controller can be blank: it will never be called! @@ -1718,7 +1718,7 @@ Next, you need to create a route for this URL (but not a controller): # config/routes.yaml app_logout: path: /logout - methods: GET + methods: POST .. code-block:: xml @@ -1729,7 +1729,7 @@ Next, you need to create a route for this URL (but not a controller): xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd"> - + .. code-block:: php @@ -1739,7 +1739,7 @@ Next, you need to create a route for this URL (but not a controller): return function (RoutingConfigurator $routes) { $routes->add('app_logout', '/logout') - ->methods(['GET']) + ->methods(['POST']) ; }; From c714cadea9e46c601b24cd95d25251b37dacaef8 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 30 May 2023 13:43:48 +0200 Subject: [PATCH 057/205] Minor tweaks --- setup/flex_private_recipes.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/setup/flex_private_recipes.rst b/setup/flex_private_recipes.rst index 14300e70258..abecdfd5039 100644 --- a/setup/flex_private_recipes.rst +++ b/setup/flex_private_recipes.rst @@ -32,9 +32,9 @@ the **repository name**, select the **Private** radio button, and click the Gitlab ~~~~~~ -Log in to your Gitlab.com account, click the **New project** button, select **Create blank project**, fill in -the **Project name**, select the **Private** radio button, and click the -**Create project** button. +Log in to your Gitlab.com account, click the **New project** button, select +**Create blank project**, fill in the **Project name**, select the **Private** +radio button, and click the **Create project** button. Create Your Private Recipes --------------------------- @@ -184,7 +184,8 @@ The ``index.json`` file has the following format: } Create an entry in ``"recipes"`` for each of your bundle recipes. Replace -``your-gitlab-account-name``, ``your-gitlab-repository`` and ``your-gitlab-project-id`` with your own details. +``your-gitlab-account-name``, ``your-gitlab-repository`` and ``your-gitlab-project-id`` +with your own details. Store Your Recipes in the Private Repository -------------------------------------------- From 7e8b5fe83c68cc79a295d6876d4135457b7af9cc Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 30 May 2023 15:20:24 +0200 Subject: [PATCH 058/205] [Uuid] Add few property types --- components/uid.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/uid.rst b/components/uid.rst index 74458ac1717..24f4c59255b 100644 --- a/components/uid.rst +++ b/components/uid.rst @@ -236,12 +236,13 @@ type, which converts to/from UUID objects automatically:: use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Types\UuidType; + use Symfony\Component\Uid\Uuid; #[ORM\Entity(repositoryClass: ProductRepository::class)] class Product { #[ORM\Column(type: UuidType::NAME)] - private $someProperty; + private Uuid $someProperty; // ... } @@ -265,7 +266,7 @@ entity primary keys:: #[ORM\Column(type: UuidType::NAME, unique: true)] #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')] - private $id; + private ?Uuid $id; public function getId(): ?Uuid { @@ -422,12 +423,13 @@ type, which converts to/from ULID objects automatically:: use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Types\UlidType; + use Symfony\Component\Uid\Ulid; #[ORM\Entity(repositoryClass: ProductRepository::class)] class Product { #[ORM\Column(type: UlidType::NAME)] - private $someProperty; + private Ulid $someProperty; // ... } @@ -451,7 +453,7 @@ entity primary keys:: #[ORM\Column(type: UlidType::NAME, unique: true)] #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: 'doctrine.ulid_generator')] - private $id; + private ?Ulid $id; public function getId(): ?Ulid { From 472f5794d3c14ea53b6ea15be14b8aba510cf410 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 30 May 2023 16:03:27 +0200 Subject: [PATCH 059/205] Add property types and return types in a few places --- bundles/best_practices.rst | 2 +- bundles/configuration.rst | 2 +- bundles/prepend_extension.rst | 2 +- cache.rst | 14 ++--- components/dependency_injection.rst | 2 +- .../_imports-parameters-note.rst.inc | 2 +- components/expression_language.rst | 2 +- components/property_access.rst | 24 ++++----- components/serializer.rst | 16 +++--- components/var_dumper.rst | 2 +- configuration.rst | 14 ++--- configuration/env_var_processors.rst | 12 ++--- configuration/micro_kernel_trait.rst | 2 +- configuration/override_dir_structure.rst | 4 +- configuration/secrets.rst | 2 +- controller/error_pages.rst | 2 +- controller/upload_file.rst | 2 +- controller/value_resolver.rst | 2 +- deployment/proxies.rst | 2 +- doctrine.rst | 2 +- doctrine/events.rst | 6 +-- event_dispatcher.rst | 51 +++++++++--------- form/embedded.rst | 4 +- frontend/custom_version_strategy.rst | 2 +- html_sanitizer.rst | 22 ++++---- http_cache/cache_invalidation.rst | 2 +- http_cache/esi.rst | 4 +- http_cache/ssi.rst | 2 +- http_client.rst | 23 ++++---- lock.rst | 4 +- mailer.rst | 12 ++--- messenger.rst | 30 +++++------ messenger/custom-transport.rst | 2 +- messenger/multiple_buses.rst | 2 +- notifier.rst | 12 ++--- rate_limiter.rst | 6 +-- reference/configuration/framework.rst | 42 +++++++-------- reference/constraints/Compound.rst | 4 +- reference/constraints/UniqueEntity.rst | 11 ++-- reference/formats/expression_language.rst | 6 +-- routing.rst | 2 +- routing/custom_route_loader.rst | 2 +- security.rst | 52 +++++++++--------- security/access_control.rst | 2 +- security/csrf.rst | 2 +- serializer.rst | 13 ++--- service_container.rst | 24 ++++----- service_container/injection_types.rst | 2 +- service_container/service_closures.rst | 2 +- service_container/tags.rst | 6 +-- session.rst | 54 +++++++++---------- templates.rst | 4 +- testing.rst | 2 +- testing/profiling.rst | 2 +- translation.rst | 8 +-- validation.rst | 36 ++++++------- validation/translations.rst | 8 +-- workflow.rst | 34 ++++++------ workflow/dumping-workflows.rst | 2 +- workflow/workflow-and-state-machine.rst | 2 +- 60 files changed, 310 insertions(+), 308 deletions(-) diff --git a/bundles/best_practices.rst b/bundles/best_practices.rst index 10ae34e9d33..72a394362fa 100644 --- a/bundles/best_practices.rst +++ b/bundles/best_practices.rst @@ -436,7 +436,7 @@ The end user can provide values in any configuration file: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->parameters() ->set('acme_blog.author.email', 'fabien@example.com') ; diff --git a/bundles/configuration.rst b/bundles/configuration.rst index 4ef81743bf5..6933f7eb794 100644 --- a/bundles/configuration.rst +++ b/bundles/configuration.rst @@ -42,7 +42,7 @@ as integration of other related components: // config/packages/framework.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->form()->enabled(true); }; diff --git a/bundles/prepend_extension.rst b/bundles/prepend_extension.rst index a0c686c4527..8d28080470f 100644 --- a/bundles/prepend_extension.rst +++ b/bundles/prepend_extension.rst @@ -139,7 +139,7 @@ registered and the ``entity_manager_name`` setting for ``acme_hello`` is set to // config/packages/acme_something.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->extension('acme_something', [ // ... 'use_acme_goodbye' => false, diff --git a/cache.rst b/cache.rst index 84d60315fe3..f9d7175cf41 100644 --- a/cache.rst +++ b/cache.rst @@ -85,7 +85,7 @@ adapter (template) they use by using the ``app`` and ``system`` key like: // config/packages/cache.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->cache() ->app('cache.adapter.filesystem') ->system('cache.adapter.system') @@ -163,7 +163,7 @@ will create pools with service IDs that follow the pattern ``cache.[type]``. // config/packages/cache.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->cache() // Only used with cache.adapter.filesystem ->directory('%kernel.cache_dir%/pools') @@ -264,7 +264,7 @@ You can also create more customized pools: // config/packages/cache.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $cache = $framework->cache(); $cache->defaultMemcachedProvider('memcached://localhost'); @@ -444,7 +444,7 @@ and use that when configuring the pool. use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $container, FrameworkConfig $framework) { + return static function (ContainerBuilder $container, FrameworkConfig $framework): void { $framework->cache() ->pool('cache.my_redis') ->adapters(['cache.adapter.redis']) @@ -524,7 +524,7 @@ Symfony stores the item automatically in all the missing pools. // config/packages/cache.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->cache() ->pool('my_cache_pool') ->defaultLifetime(31536000) // One year @@ -616,7 +616,7 @@ to enable this feature. This could be added by using the following configuration // config/packages/cache.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->cache() ->pool('my_cache_pool') ->tags(true) @@ -670,7 +670,7 @@ achieved by specifying the adapter. // config/packages/cache.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->cache() ->pool('my_cache_pool') ->tags('tag_pool') diff --git a/components/dependency_injection.rst b/components/dependency_injection.rst index f805b39db35..6d8672feeef 100644 --- a/components/dependency_injection.rst +++ b/components/dependency_injection.rst @@ -313,7 +313,7 @@ config files: namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->parameters() // ... ->set('mailer.transport', 'sendmail') diff --git a/components/dependency_injection/_imports-parameters-note.rst.inc b/components/dependency_injection/_imports-parameters-note.rst.inc index d17d6d60b26..1389ca78fe3 100644 --- a/components/dependency_injection/_imports-parameters-note.rst.inc +++ b/components/dependency_injection/_imports-parameters-note.rst.inc @@ -31,6 +31,6 @@ // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->import('%kernel.project_dir%/somefile.yaml'); }; diff --git a/components/expression_language.rst b/components/expression_language.rst index 33fdcae8de2..3f79c57707d 100644 --- a/components/expression_language.rst +++ b/components/expression_language.rst @@ -107,7 +107,7 @@ PHP type (including objects):: class Apple { - public $variety; + public string $variety; } $apple = new Apple(); diff --git a/components/property_access.rst b/components/property_access.rst index 7bf4a3d3a9e..3364b667a5c 100644 --- a/components/property_access.rst +++ b/components/property_access.rst @@ -177,7 +177,7 @@ method:: // ... class Person { - public $name; + public string $name; } $person = new Person(); @@ -321,26 +321,26 @@ can use setters, the magic ``__set()`` method or properties to set values:: // ... class Person { - public $firstName; - private $lastName; - private $children = []; + public string $firstName; + private string $lastName; + private array $children = []; - public function setLastName($name) + public function setLastName($name): void { $this->lastName = $name; } - public function getLastName() + public function getLastName(): string { return $this->lastName; } - public function getChildren() + public function getChildren(): array { return $this->children; } - public function __set($property, $value) + public function __set($property, $value): void { $this->$property = $value; } @@ -507,15 +507,15 @@ You can also mix objects and arrays:: // ... class Person { - public $firstName; - private $children = []; + public string $firstName; + private array $children = []; - public function setChildren($children) + public function setChildren($children): void { $this->children = $children; } - public function getChildren() + public function getChildren(): array { return $this->children; } diff --git a/components/serializer.rst b/components/serializer.rst index 0b97690650f..e08bd5c1f07 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -398,15 +398,15 @@ It is also possible to serialize only a set of specific attributes:: class User { - public $familyName; - public $givenName; - public $company; + public string $familyName; + public string $givenName; + public string $company; } class Company { - public $name; - public $address; + public string $name; + public string $address; } $company = new Company(); @@ -529,8 +529,8 @@ Given you have the following object:: class Company { - public $name; - public $address; + public string $name; + public string $address; } And in the serialized form, all attributes must be prefixed by ``org_`` like @@ -925,7 +925,7 @@ faster alternative to the use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->services() // ... ->set('get_set_method_normalizer', GetSetMethodNormalizer::class) diff --git a/components/var_dumper.rst b/components/var_dumper.rst index 3a55d6c21bd..ccde974b9e5 100644 --- a/components/var_dumper.rst +++ b/components/var_dumper.rst @@ -144,7 +144,7 @@ the :ref:`dump_destination option ` of the // config/packages/debug.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->extension('debug', [ 'dump_destination' => 'tcp://%env(VAR_DUMPER_SERVER)%', ]); diff --git a/configuration.rst b/configuration.rst index 733dbbac32a..b7ccac2ece7 100644 --- a/configuration.rst +++ b/configuration.rst @@ -136,7 +136,7 @@ configuration files, even if they use a different format: // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->import('legacy_config.php'); // glob expressions are also supported to load multiple files @@ -242,7 +242,7 @@ reusable configuration value. By convention, parameters are defined under the use App\Entity\BlogPost; use App\Enum\PostState; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->parameters() // the parameter name is an arbitrary string (the 'app.' prefix is recommended // to better differentiate your parameters from Symfony parameters). @@ -321,7 +321,7 @@ configuration file using a special syntax: wrap the parameter name in two ``%`` // config/packages/some_package.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->extension('some_package', [ // any string surrounded by two % is replaced by that parameter value 'email_address' => '%app.admin_email%', @@ -358,7 +358,7 @@ configuration file using a special syntax: wrap the parameter name in two ``%`` // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->parameters() ->set('url_pattern', 'http://symfony.com/?foo=%%s&bar=%%d'); }; @@ -620,7 +620,7 @@ This example shows how you could configure the application secret using an env v // config/packages/framework.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->extension('framework', [ // by convention the env var names are always uppercase 'secret' => '%env(APP_SECRET)%', @@ -973,7 +973,7 @@ doesn't work for parameters: use App\Service\MessageGenerator; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->parameters() ->set('app.contents_dir', '...'); @@ -1030,7 +1030,7 @@ whenever a service/controller defines a ``$projectDir`` argument, use this: use App\Controller\LuckyController; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $container->services() ->defaults() // pass this value to any $projectDir argument for any service diff --git a/configuration/env_var_processors.rst b/configuration/env_var_processors.rst index 15a91f249de..937c0e341f6 100644 --- a/configuration/env_var_processors.rst +++ b/configuration/env_var_processors.rst @@ -45,7 +45,7 @@ processor to turn the value of the ``HTTP_PORT`` env var into an integer: use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->router() ->httpPort('%env(int:HTTP_PORT)%') // or @@ -98,7 +98,7 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $container, FrameworkConfig $framework) { + return static function (ContainerBuilder $container, FrameworkConfig $framework): void { $container->setParameter('env(SECRET)', 'some_secret'); $framework->secret(env('SECRET')->string()); }; @@ -144,7 +144,7 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $container, FrameworkConfig $framework) { + return static function (ContainerBuilder $container, FrameworkConfig $framework): void { $container->setParameter('env(HTTP_METHOD_OVERRIDE)', 'true'); $framework->httpMethodOverride(env('HTTP_METHOD_OVERRIDE')->bool()); }; @@ -231,7 +231,7 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\SecurityConfig; - return static function (ContainerBuilder $container, SecurityConfig $security) { + return static function (ContainerBuilder $container, SecurityConfig $security): void { $container->setParameter('env(HEALTH_CHECK_METHOD)', 'Symfony\Component\HttpFoundation\Request::METHOD_HEAD'); $security->accessControl() ->path('^/health-check$') @@ -280,7 +280,7 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $container) { + return static function (ContainerBuilder $container): void { $container->setParameter('env(ALLOWED_LANGUAGES)', '["en","de","es"]'); $container->setParameter('app_allowed_languages', '%env(json:ALLOWED_LANGUAGES)%'); }; @@ -364,7 +364,7 @@ Symfony provides the following env var processors: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Config\FrameworkConfig; - return static function (ContainerBuilder $container) { + return static function (ContainerBuilder $container): void { $container->setParameter('env(ALLOWED_LANGUAGES)', 'en,de,es'); $container->setParameter('app_allowed_languages', '%env(csv:ALLOWED_LANGUAGES)%'); }; diff --git a/configuration/micro_kernel_trait.rst b/configuration/micro_kernel_trait.rst index 2a4b8a2b495..ac0d50e1671 100644 --- a/configuration/micro_kernel_trait.rst +++ b/configuration/micro_kernel_trait.rst @@ -369,7 +369,7 @@ because the configuration started to get bigger: // config/framework.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework ->secret('SOME_SECRET') ->profiler() diff --git a/configuration/override_dir_structure.rst b/configuration/override_dir_structure.rst index 7528c250729..4fb5524a2aa 100644 --- a/configuration/override_dir_structure.rst +++ b/configuration/override_dir_structure.rst @@ -67,7 +67,7 @@ Console script:: Web front-controller:: // public/index.php - + // ... $_SERVER['APP_RUNTIME_OPTIONS']['dotenv_path'] = 'another/custom/path/to/.env'; @@ -236,7 +236,7 @@ configuration option to define your own translations directory (use :ref:`framew // config/packages/translation.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->translator() ->defaultPath('%kernel.project_dir%/i18n') ; diff --git a/configuration/secrets.rst b/configuration/secrets.rst index d2923e13a42..bd52ea0895a 100644 --- a/configuration/secrets.rst +++ b/configuration/secrets.rst @@ -309,7 +309,7 @@ The secrets system is enabled by default and some of its behavior can be configu // config/packages/framework.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->secrets() // ->vaultDirectory('%kernel.project_dir%/config/secrets/%kernel.environment%') // ->localDotenvFile('%kernel.project_dir%/.env.%kernel.environment%.local') diff --git a/controller/error_pages.rst b/controller/error_pages.rst index 0e2463cbfd1..d28c51cce99 100644 --- a/controller/error_pages.rst +++ b/controller/error_pages.rst @@ -277,7 +277,7 @@ configuration option to point to it: // config/packages/framework.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { // ... $framework->errorController('App\Controller\ErrorController::show'); }; diff --git a/controller/upload_file.rst b/controller/upload_file.rst index f2a39c12262..9bcc17cd7cd 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -312,7 +312,7 @@ Then, define a service for this class: use App\Service\FileUploader; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $services = $container->services(); $services->set(FileUploader::class) diff --git a/controller/value_resolver.rst b/controller/value_resolver.rst index b2d93b13148..d9a84aa06ee 100644 --- a/controller/value_resolver.rst +++ b/controller/value_resolver.rst @@ -320,7 +320,7 @@ and adding a priority: use App\ValueResolver\BookingIdValueResolver; - return static function (ContainerConfigurator $containerConfigurator) { + return static function (ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); $services->set(BookingIdValueResolver::class) diff --git a/deployment/proxies.rst b/deployment/proxies.rst index 18377068cd6..2b716faa327 100644 --- a/deployment/proxies.rst +++ b/deployment/proxies.rst @@ -71,7 +71,7 @@ and what headers your reverse proxy uses to send information: // config/packages/framework.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework // the IP address (or range) of your proxy ->trustedProxies('192.0.0.1,10.0.0.0/8') diff --git a/doctrine.rst b/doctrine.rst index 164ed72ed09..ff8eaa2479a 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -282,7 +282,7 @@ methods: // ... + #[ORM\Column(type: Types::TEXT)] - + private $description; + + private string $description; // getDescription() & setDescription() were also added } diff --git a/doctrine/events.rst b/doctrine/events.rst index 9319fdbfca0..53a3dc5b32e 100644 --- a/doctrine/events.rst +++ b/doctrine/events.rst @@ -234,7 +234,7 @@ listener in the Symfony application by creating a new service for it and use App\EventListener\SearchIndexer; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $services = $container->services(); // listeners are applied by default to all Doctrine connections @@ -385,7 +385,7 @@ with the ``doctrine.orm.entity_listener`` tag as follows: use App\Entity\User; use App\EventListener\UserChangedNotifier; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $services = $container->services(); $services->set(UserChangedNotifier::class) @@ -531,7 +531,7 @@ Doctrine connection to use) you must do that in the manual service configuration use App\EventListener\DatabaseActivitySubscriber; - return static function (ContainerConfigurator $container) { + return static function (ContainerConfigurator $container): void { $services = $container->services(); $services->set(DatabaseActivitySubscriber::class) diff --git a/event_dispatcher.rst b/event_dispatcher.rst index d09a05a7473..275ec7863fe 100644 --- a/event_dispatcher.rst +++ b/event_dispatcher.rst @@ -263,17 +263,17 @@ listen to the same ``kernel.exception`` event:: ]; } - public function processException(ExceptionEvent $event) + public function processException(ExceptionEvent $event): void { // ... } - public function logException(ExceptionEvent $event) + public function logException(ExceptionEvent $event): void { // ... } - public function notifyException(ExceptionEvent $event) + public function notifyException(ExceptionEvent $event): void { // ... } @@ -306,7 +306,7 @@ a "main" request or a "sub request":: class RequestListener { - public function onKernelRequest(RequestEvent $event) + public function onKernelRequest(RequestEvent $event): void { if (!$event->isMainRequest()) { // don't do anything if it's not the main request @@ -357,7 +357,7 @@ name (FQCN) of the corresponding event class:: ]; } - public function onKernelRequest(RequestEvent $event) + public function onKernelRequest(RequestEvent $event): void { // ... } @@ -381,7 +381,7 @@ compiler pass ``AddEventAliasesPass``:: class Kernel extends BaseKernel { - protected function build(ContainerBuilder $container) + protected function build(ContainerBuilder $container): void { $container->addCompilerPass(new AddEventAliasesPass([ MyCustomEvent::class => 'my_custom_event', @@ -519,11 +519,12 @@ A controller that implements this interface looks like this:: use App\Controller\TokenAuthenticatedController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; + use Symfony\Component\HttpFoundation\Response; class FooController extends AbstractController implements TokenAuthenticatedController { // An action that needs authentication - public function bar() + public function bar(): Response { // ... } @@ -548,11 +549,11 @@ event subscribers, you can learn more about them at :doc:`/event_dispatcher`:: class TokenSubscriber implements EventSubscriberInterface { public function __construct( - private $tokens + private array $tokens ) { } - public function onKernelController(ControllerEvent $event) + public function onKernelController(ControllerEvent $event): void { $controller = $event->getController(); @@ -570,7 +571,7 @@ event subscribers, you can learn more about them at :doc:`/event_dispatcher`:: } } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ KernelEvents::CONTROLLER => 'onKernelController', @@ -609,7 +610,7 @@ For example, take the ``TokenSubscriber`` from the previous example and first record the authentication token inside the request attributes. This will serve as a basic flag that this request underwent token authentication:: - public function onKernelController(ControllerEvent $event) + public function onKernelController(ControllerEvent $event): void { // ... @@ -631,7 +632,7 @@ header on the response if it's found:: // add the new use statement at the top of your file use Symfony\Component\HttpKernel\Event\ResponseEvent; - public function onKernelResponse(ResponseEvent $event) + public function onKernelResponse(ResponseEvent $event): void { // check to see if onKernelController marked this as a token "auth'ed" request if (!$token = $event->getRequest()->attributes->get('auth_token')) { @@ -645,7 +646,7 @@ header on the response if it's found:: $response->headers->set('X-CONTENT-HASH', $hash); } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ KernelEvents::CONTROLLER => 'onKernelController', @@ -673,7 +674,7 @@ end of the method:: { // ... - public function send($subject, $message) + public function send(string $subject, string $message): mixed { // dispatch an event before the method $event = new BeforeSendMailEvent($subject, $message); @@ -711,27 +712,27 @@ this:: class BeforeSendMailEvent extends Event { public function __construct( - private $subject, - private $message, + private string $subject, + private string $message, ) { } - public function getSubject() + public function getSubject(): string { return $this->subject; } - public function setSubject($subject) + public function setSubject(string $subject): string { $this->subject = $subject; } - public function getMessage() + public function getMessage(): string { return $this->message; } - public function setMessage($message) + public function setMessage(string $message) { $this->message = $message; } @@ -747,16 +748,16 @@ And the ``AfterSendMailEvent`` even like this:: class AfterSendMailEvent extends Event { public function __construct( - private $returnValue, + private mixed $returnValue, ) { } - public function getReturnValue() + public function getReturnValue(): mixed { return $this->returnValue; } - public function setReturnValue($returnValue) + public function setReturnValue(mixed $returnValue) { $this->returnValue = $returnValue; } @@ -776,7 +777,7 @@ could listen to the ``mailer.post_send`` event and change the method's return va class MailPostSendSubscriber implements EventSubscriberInterface { - public function onMailerPostSend(AfterSendMailEvent $event) + public function onMailerPostSend(AfterSendMailEvent $event): void { $returnValue = $event->getReturnValue(); // modify the original $returnValue value @@ -784,7 +785,7 @@ could listen to the ``mailer.post_send`` event and change the method's return va $event->setReturnValue($returnValue); } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ 'mailer.post_send' => 'onMailerPostSend', diff --git a/form/embedded.rst b/form/embedded.rst index d4463532e9b..4263bb42b5d 100644 --- a/form/embedded.rst +++ b/form/embedded.rst @@ -22,7 +22,7 @@ creating the ``Category`` class:: class Category { #[Assert\NotBlank] - public $name; + public string $name; } Next, add a new ``category`` property to the ``Task`` class:: @@ -35,7 +35,7 @@ Next, add a new ``category`` property to the ``Task`` class:: #[Assert\Type(type: Category::class)] #[Assert\Valid] - protected $category; + protected ?Category $category = null; // ... diff --git a/frontend/custom_version_strategy.rst b/frontend/custom_version_strategy.rst index a873df8e801..9b86685889b 100644 --- a/frontend/custom_version_strategy.rst +++ b/frontend/custom_version_strategy.rst @@ -178,7 +178,7 @@ the :ref:`version_strategy ` option: use App\Asset\VersionStrategy\GulpBusterVersionStrategy; use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { // ... $framework->assets() ->versionStrategy(GulpBusterVersionStrategy::class) diff --git a/html_sanitizer.rst b/html_sanitizer.rst index 9aa26bbe37e..fccaedd29cd 100644 --- a/html_sanitizer.rst +++ b/html_sanitizer.rst @@ -197,7 +197,7 @@ You can do this by defining a new HTML sanitizer in the configuration: // config/packages/framework.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->htmlSanitizer() ->sanitizer('app.post_sanitizer') ->blockElement('h1') @@ -273,7 +273,7 @@ Safe elements // config/packages/framework.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->htmlSanitizer() ->sanitizer('app.post_sanitizer') // enable either of these @@ -360,7 +360,7 @@ attributes from the `W3C Standard Proposal`_ are allowed. // config/packages/framework.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->htmlSanitizer() ->sanitizer('app.post_sanitizer') // allow the
element and 2 attributes @@ -443,7 +443,7 @@ This can also be used to remove elements from the allow list. // config/packages/framework.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->htmlSanitizer() ->sanitizer('app.post_sanitizer') // remove
, but process the children @@ -521,7 +521,7 @@ on all elements allowed *before this setting*. // config/packages/framework.php use Symfony\Config\FrameworkConfig; - return static function (FrameworkConfig $framework) { + return static function (FrameworkConfig $framework): void { $framework->htmlSanitizer() ->sanitizer('app.post_sanitizer') // allow "src' on