Skip to content

Commit 783de4f

Browse files
[Clock] Fix ClockAwareTrait usage
1 parent bbaf5b0 commit 783de4f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

components/clock.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ the default one during tests, you will have full control to set the "current tim
114114
to any arbitrary date/time.
115115

116116
In order to use this component in your services, make their classes use the
117-
:class:`Symfony\\Component\\Clock\\ClockAwareTrait` and add a ``ClockInterface``
118-
typed-property ``$clock`` to their constructors.
119-
120-
If your application uses :ref:`service autoconfiguration <services-autoconfigure>`,
121-
your services can now call the ``$this->now()`` method to get the current time::
117+
:class:`Symfony\\Component\\Clock\\ClockAwareTrait`. This trait defines the
118+
``ClockAwareTrait::setClock()`` method. Thanks to the ``#[Required]`` attribute
119+
declared on this method and if your application uses :ref:`service autoconfiguration <services-autoconfigure>`,
120+
``ClockAwareTrait::setClock()`` will automatically be called by the service container,
121+
injecting a clock implementation into the ``$clock`` property (also provided
122+
by the trait). Your services can now call the ``$this->now()`` method to get the
123+
current time::
122124

123125
namespace App\TimeUtils;
124126

0 commit comments

Comments
 (0)