Skip to content

Commit 0ddc9eb

Browse files
committed
Merge branch '4.2'
* 4.2: Documented the Contracts component Documented the LoggerAwareInterface autoconfiguration Fix format by removing underscore Added a note about UniqueEntity and collections Added a note about PHPUnit setLocale() method
2 parents 51ac601 + 5fabac8 commit 0ddc9eb

File tree

5 files changed

+109
-2
lines changed

5 files changed

+109
-2
lines changed

components/contracts.rst

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
.. index::
2+
single: Contracts
3+
single: Components; Contracts
4+
5+
The Contracts Component
6+
=======================
7+
8+
The Contracts component provides a set of abstractions extracted out of the
9+
Symfony components. They can be used to build on semantics that the Symfony
10+
components proved useful - and that already have battle-tested implementations.
11+
12+
Installation
13+
------------
14+
15+
.. code-block:: terminal
16+
17+
$ composer require symfony/contracts
18+
19+
.. include:: /components/require_autoload.rst.inc
20+
21+
Usage
22+
-----
23+
24+
The abstractions in this package are useful to achieve loose coupling and
25+
interoperability. By using the provided interfaces as type hints, you are able
26+
to reuse any implementations that match their contracts. It could be a Symfony
27+
component, or another package provided by the PHP community at large.
28+
29+
Depending on their semantics, some interfaces can be combined with
30+
:doc:`autowiring </service_container/autowiring>` to seamlessly inject a service
31+
in your classes.
32+
33+
Others might be useful as labeling interfaces, to hint about a specific behavior
34+
that can be enabled when using :ref:`autoconfiguration <services-autoconfigure>`
35+
or manual :doc:`service tagging </service_container/tags>` (or any other means
36+
provided by your framework.)
37+
38+
Design Principles
39+
-----------------
40+
41+
* Contracts are split by domain, each into their own sub-namespaces;
42+
* Contracts are small and consistent sets of PHP interfaces, traits, normative
43+
docblocks and reference test suites when applicable, ...;
44+
* Contracts must have a proven implementation to enter this repository;
45+
* Contracts must be backward compatible with existing Symfony components.
46+
47+
Packages that implement specific contracts should list them in the ``provide``
48+
section of their ``composer.json`` file, using the
49+
``symfony/*-contracts-implementation`` convention. For example:
50+
51+
.. code-block:: javascript
52+
53+
{
54+
"...": "...",
55+
"provide": {
56+
"symfony/cache-contracts-implementation": "1.0"
57+
}
58+
}
59+
60+
Frequently Asked Questions
61+
--------------------------
62+
63+
How Is this Different From PHP-FIG's PSRs?
64+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65+
66+
When applicable, the provided contracts are built on top of `PHP-FIG`_'s PSRs.
67+
However, PHP-FIG has different goals and different processes. Symfony Contracts
68+
focuses on providing abstractions that are useful on their own while still
69+
compatible with implementations provided by Symfony.
70+
71+
Why Isn't this Package Split into Several Packages?
72+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73+
74+
Putting all interfaces in one package eases discoverability and dependency
75+
management. Instead of dealing with a myriad of small packages and the
76+
corresponding matrix of versions, you only deal with one package and one
77+
version. Also when using IDE autocompletion or reading the source code, it makes
78+
it easier to figure out which contracts are provided.
79+
80+
There are two downsides to this approach:
81+
82+
* You may have unused files in your ``vendor/`` directory. This has no impact in
83+
practice because the file sizes are very small and there is no performance
84+
overhead at all since they are never loaded.
85+
* In the future, it will be impossible to use two different sub-namespaces in
86+
different major versions of the package. However, this package follows the
87+
:doc:`Symfony BC + deprecation </contributing/code/bc>` policies, with an
88+
additional restriction to never remove deprecated interfaces.
89+
90+
.. _`PHP-FIG`: https://www.php-fig.org/

components/phpunit_bridge.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ The PHPUnit Bridge
1010

1111
It comes with the following features:
1212

13-
* Forces the tests to use a consistent locale (``C``);
13+
* Forces the tests to use a consistent locale (``C``) (if you create
14+
locale-sensitive tests, use PHPUnit's ``setLocale()`` method);
1415

1516
* Auto-register ``class_exists`` to load Doctrine annotations (when used);
1617

logging.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,16 @@ option of your handler to ``rotating_file``:
338338
Using a Logger inside a Service
339339
-------------------------------
340340

341+
If your application uses :ref:`service autoconfiguration <services-autoconfigure>`,
342+
any service whose class implements ``Psr\Log\LoggerAwareInterface`` will
343+
receive a call to its method ``setLogger()`` with the default logger service
344+
passed as a service.
345+
346+
.. versionadded:: 4.2
347+
348+
The automatic call to ``setLogger()`` when implementing ``LoggerAwareInterface``
349+
was introduced in Symfony 4.2.
350+
341351
If you want to use in your own services a pre-configured logger which uses a
342352
specific channel (``app`` by default), use the ``monolog.logger`` tag with the
343353
``channel`` property as explained in the

messenger.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ for each bus looks like this:
437437
#. ``logging`` middleware. Responsible for logging the beginning and the end of the
438438
message within the bus;
439439

440-
#. _Your own collection of middleware_;
440+
#. Your own collection of middleware_;
441441

442442
#. ``send_message`` middleware. Will route the messages you configured to their
443443
corresponding sender and stop the middleware chain;

reference/constraints/UniqueEntity.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ between all of the constraints in your user table:
115115
this validation has passed and before this entity is actually persisted in
116116
the database.
117117

118+
.. caution::
119+
120+
This constraint cannot deal with duplicates found in a collection of items
121+
that haven't been persisted as entities yet. You'll need to create your own
122+
validator to handle that case.
123+
118124
Options
119125
-------
120126

0 commit comments

Comments
 (0)