Skip to content

Commit e6e6287

Browse files
Merge branch '6.3' into attributes-overview-6.3
2 parents df29290 + 80c618a commit e6e6287

24 files changed

+139
-25
lines changed

.doctor-rst.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ rules:
4747
space_between_label_and_link_in_doc: ~
4848
space_between_label_and_link_in_ref: ~
4949
string_replacement: ~
50+
title_underline_length_must_match_title_length: ~
5051
typo: ~
5152
unused_links: ~
5253
use_deprecated_directive_instead_of_versionadded: ~

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
key: ${{ runner.os }}-doctor-rst-${{ steps.extract_base_branch.outputs.branch }}
7474

7575
- name: "Run DOCtor-RST"
76-
uses: docker://oskarstark/doctor-rst:1.40.1
76+
uses: docker://oskarstark/doctor-rst:1.41.0
7777
with:
7878
args: --short --error-format=github --cache-file=/github/workspace/.cache/doctor-rst.cache
7979

best_practices.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ important parts of your application.
229229
.. _best-practice-controller-annotations:
230230

231231
Use Attributes or Annotations to Configure Routing, Caching, and Security
232-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
233233

234234
Using attributes or annotations for routing, caching, and security simplifies
235235
configuration. You don't need to browse several files created with different
@@ -437,7 +437,7 @@ specific tests for each page.
437437
.. _hardcode-urls-in-a-functional-test:
438438

439439
Hard-code URLs in a Functional Test
440-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
440+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
441441

442442
In Symfony applications, it's recommended to :ref:`generate URLs <routing-generating-urls>`
443443
using routes to automatically update all links when a URL changes. However, if a

bundles/best_practices.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,4 +560,3 @@ Learn more
560560
.. _`valid license identifier`: https://spdx.org/licenses/
561561
.. _`GitHub Actions`: https://docs.github.com/en/free-pro-team@latest/actions
562562
.. _`Travis CI`: https://docs.travis-ci.com/
563-
.. _`Symfony 4.4 bundle documentation`: https://symfony.com/doc/4.4/bundles.html#bundle-directory-structure

components/lock.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ method can be safely called repeatedly, even if the lock is already acquired.
7070
third argument of the ``createLock()`` method to ``false``.
7171

7272
Serializing Locks
73-
------------------
73+
-----------------
7474

7575
The :class:`Symfony\\Component\\Lock\\Key` contains the state of the
7676
:class:`Symfony\\Component\\Lock\\Lock` and can be serialized. This

components/runtime.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
single: Components; Runtime
44

55
The Runtime Component
6-
======================
6+
=====================
77

88
The Runtime Component decouples the bootstrapping logic from any global state
99
to make sure the application can run with runtimes like PHP-PM, ReactPHP,

components/serializer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ context to pass in these options using the key ``json_encode_options`` or
10001000
$this->serializer->serialize($data, 'json', ['json_encode_options' => \JSON_PRESERVE_ZERO_FRACTION]);
10011001

10021002
The ``CsvEncoder``
1003-
~~~~~~~~~~~~~~~~~~~
1003+
~~~~~~~~~~~~~~~~~~
10041004

10051005
The ``CsvEncoder`` encodes to and decodes from CSV.
10061006

controller.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ to render the content of a page.
1919
single: Controller; Basic example
2020

2121
A Basic Controller
22-
-------------------
22+
------------------
2323

2424
While a controller can be any PHP callable (function, method on an object,
2525
or a ``Closure``), a controller is usually a method inside a controller

doctrine.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ using the ``MapEntity`` attribute::
664664
.. tip::
665665

666666
When enabled globally, it's possible to disabled the behavior on a specific
667-
controller, by using the ``MapEntity`` set to ``disabled``.
667+
controller, by using the ``MapEntity`` set to ``disabled``::
668668

669669
public function show(
670670
#[CurrentUser]

frontend/encore/bootstrap.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Now, require bootstrap from any of your JavaScript files:
7474
});
7575
7676
Using Bootstrap with Turbo
77-
---------------------------
77+
--------------------------
7878

7979
If you are using bootstrap with Turbo Drive, to allow your JavaScript to load on each page change,
8080
wrap the initialization in a ``turbo:load`` event listener:

frontend/encore/virtual-machine.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ connections:
9393
otherwise other computers can have access to it.
9494

9595
Fix "Invalid Host header" Issue
96-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9797

9898
Webpack will respond ``Invalid Host header`` when trying to access files from
9999
the dev-server. To fix this, set the ``allowedHosts`` option:

html_sanitizer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ URLs of ``<a>`` elements:
828828
);
829829
830830
Force/Allow Media URLs
831-
~~~~~~~~~~~~~~~~~~~~~
831+
~~~~~~~~~~~~~~~~~~~~~~
832832

833833
Like :ref:`link URLs <html-sanitizer-link-url>`, you can also control the
834834
URLs of other media in the HTML. The following attributes are checked by

mercure.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ Checkout `the dedicated API Platform documentation`_ to learn more about
614614
its Mercure support.
615615

616616
Testing
617-
--------
617+
-------
618618

619619
During unit testing it's usually not needed to send updates to Mercure.
620620

reference/attributes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
Symfony Attributes Overview
55
===========================
66

7-
Attributes are the successor of annotation since PHP 8. Attributes are native
7+
Attributes are the successor of annotations since PHP 8. Attributes are native
88
to the language and Symfony takes full advantage of them across the framework
9-
ans its different components.
9+
and its different components.
1010

1111
Doctrine Bridge
1212
~~~~~~~~~~~~~~~

reference/configuration/framework.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ The value of this option is an associative array of ``domain => IP address``
12171217
(e.g ``['symfony.com' => '46.137.106.254', ...]``).
12181218

12191219
retry_strategy
1220-
...............
1220+
..............
12211221

12221222
**type**: ``string``
12231223

reference/configuration/security.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ If ``true``, users are always redirected to the default target path regardless
313313
of the previous URL that was stored in the session.
314314

315315
default_target_path
316-
....................
316+
...................
317317

318318
**type**: ``string`` **default**: ``/``
319319

reference/constraints/Expression.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ Parameter Description
263263
=============== ==============================================================
264264

265265
``negate``
266-
~~~~~~~~~~~
266+
~~~~~~~~~~
267267

268268
**type**: ``boolean`` **default**: ``true``
269269

reference/forms/types/choice.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Field Variables
313313
faster to use the :ref:`selectedchoice <form-twig-selectedchoice>` test.
314314

315315
Accessing Form Choice Data
316-
...........................
316+
..........................
317317

318318
The ``form.vars`` variable of each choice entry holds data such as whether the
319319
choice is selected or not. If you need to get the full list of choices data and

reference/forms/types/tel.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
single: Forms; Fields; TelType
33

44
TelType Field
5-
===============
5+
=============
66

77
The ``TelType`` field is a text field that is rendered using the HTML5
88
``<input type="tel">`` tag. Following the recommended HTML5 behavior, the value

reference/twig_reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ and :ref:`reference-assets-json-manifest-path` configuration options.
127127
Read more about :ref:`linking to web assets from templates <templates-link-to-assets>`.
128128

129129
asset_version
130-
~~~~~~~~~~~~~~
130+
~~~~~~~~~~~~~
131131

132132
.. code-block:: twig
133133

service_container/lazy_services.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Lazy Services
66

77
.. seealso::
88

9-
Another way to inject services lazily is via a :doc:`service subscriber </service_container/service_subscribers_locators>`.
9+
Other ways to inject services lazily are via a :doc:`service closure </service_container/service_closures>` or
10+
:doc:`service subscriber </service_container/service_subscribers_locators>`.
1011

1112
Why Lazy Services?
1213
------------------
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
.. index::
2+
single: DependencyInjection; Service Closures
3+
4+
Service Closures
5+
================
6+
7+
This feature wraps the injected service into a closure allowing it to be
8+
lazily loaded when and if needed.
9+
This is useful if the service being injected is a bit heavy to instantiate
10+
or is used only in certain cases.
11+
The service is instantiated the first time the closure is called, while
12+
all subsequent calls return the same instance, unless the service is
13+
:doc:`not shared </service_container/shared>`::
14+
15+
// src/Service/MyService.php
16+
namespace App\Service;
17+
18+
use Symfony\Component\Mailer\MailerInterface;
19+
20+
class MyService
21+
{
22+
/**
23+
* @var callable(): MailerInterface
24+
*/
25+
private \Closure $mailer;
26+
27+
public function __construct(\Closure $mailer)
28+
{
29+
$this->mailer = $mailer;
30+
}
31+
32+
public function doSomething(): void
33+
{
34+
// ...
35+
36+
$this->getMailer()->send($email);
37+
}
38+
39+
private function getMailer(): MailerInterface
40+
{
41+
return ($this->mailer)();
42+
}
43+
}
44+
45+
To define a service closure and inject it to another service, create an
46+
argument of type ``service_closure``:
47+
48+
.. configuration-block::
49+
50+
.. code-block:: yaml
51+
52+
# config/services.yaml
53+
services:
54+
App\Service\MyService:
55+
arguments: [!service_closure '@mailer']
56+
57+
.. code-block:: xml
58+
59+
<!-- config/services.xml -->
60+
<?xml version="1.0" encoding="UTF-8" ?>
61+
<container xmlns="http://symfony.com/schema/dic/services"
62+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
63+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
64+
65+
<services>
66+
<service id="App\Service\MyService">
67+
<argument type="service_closure" id="mailer"/>
68+
</service>
69+
</services>
70+
</container>
71+
72+
.. code-block:: php
73+
74+
// config/services.php
75+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
76+
77+
use App\Service\MyService;
78+
79+
return function (ContainerConfigurator $containerConfigurator) {
80+
$services = $containerConfigurator->services();
81+
82+
$services->set(MyService::class)
83+
->args([service_closure('mailer')]);
84+
85+
// In case the dependency is optional
86+
// $services->set(MyService::class)
87+
// ->args([service_closure('mailer')->ignoreOnInvalid()]);
88+
};
89+
90+
.. seealso::
91+
92+
Another way to inject services lazily is via a
93+
:doc:`service locator </service_container/service_subscribers_locators>`.
94+
95+
Using a Service Closure in a Compiler Pass
96+
------------------------------------------
97+
98+
In :doc:`compiler passes </service_container/compiler_passes>` you can create
99+
a service closure by wrapping the service reference into an instance of
100+
:class:`Symfony\\Component\\DependencyInjection\\Argument\\ServiceClosureArgument`::
101+
102+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
103+
use Symfony\Component\DependencyInjection\ContainerBuilder;
104+
use Symfony\Component\DependencyInjection\Reference;
105+
106+
public function process(ContainerBuilder $containerBuilder): void
107+
{
108+
// ...
109+
110+
$myService->addArgument(new ServiceClosureArgument(new Reference('mailer')));
111+
}

service_container/service_subscribers_locators.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ instantiation of the services to be lazy. However, that's not possible using
1212
the explicit dependency injection since services are not all meant to
1313
be ``lazy`` (see :doc:`/service_container/lazy_services`).
1414

15+
.. seealso::
16+
17+
Another way to inject services lazily is via a
18+
:doc:`service closure </service_container/service_closures>`.
19+
1520
This can typically be the case in your controllers, where you may inject several
1621
services in the constructor, but the action called only uses some of them.
1722
Another example are applications that implement the `Command pattern`_

session.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,6 @@ These are parameters that you can configure:
11241124
``expiry_field`` (default ``expires_at``):
11251125
The name of the field where to store the session lifetime.
11261126

1127-
.. index::
1128-
single: Sessions, saving locale
1129-
11301127
Migrating Between Session Handlers
11311128
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11321129

0 commit comments

Comments
 (0)