8000 Merge branch '4.1' · symfony/symfony-docs@e56793b · GitHub
[go: up one dir, main page]

Skip to content

Commit e56793b

Browse files
committed
Merge branch '4.1'
* 4.1: Updated the command to run the Docker image [Doctrine Bridge] document priority for doctrine.event_listener tag Improved the docs of the instanceof config Add details on how the ClockMock::register works Add Dockerfile [Messenger] Register a handler for a specific bus Fix function name in expression [Routing] Fix path ressource Add missing semicolon in doc
2 parents 7f19b26 + 4765b7d commit e56793b

File tree

9 files changed

+189
-17
lines changed

9 files changed

+189
-17
lines changed

Dockerfile

Lines chang 8000 ed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:2-stretch as builder
2+
3+
WORKDIR /www
4+
5+
COPY ./_build/.requirements.txt _build/
6+
7+
RUN pip install pip==9.0.1 wheel==0.29.0 \
8+
&& pip install -r _build/.requirements.txt
9+
10+
COPY . /www
11+
12+
RUN make -C _build html
13+
14+
FROM nginx:latest
15+
16+
COPY --from=builder /www/_build/html /usr/share/nginx/html

README.markdown

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,17 @@ Platform.sh
1919
-----------
2020

2121
Pull requests are automatically built by [Platform.sh](https://platform.sh).
22+
23+
Docker
24+
------
25+
26+
You can build the doc locally with these commands:
27+
28+
```bash
29+
# build the image...
30+
$ docker build . -t symfony-docs
31+
32+
# ...and serve it locally on http//:127.0.0.1:8080
33+
# (if it's already in use, change the '8080' port by any other port)
34+
$ docker run --rm -p 8080:80 symfony-docs
35+
```

components/phpunit_bridge.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,48 @@ test::
352352

353353
And that's all!
354354

355+
.. caution::
356+
357+
Time-based function mocking follows the `PHP namespace resolutions rules`_
358+
so "fully qualified function calls" (e.g ``\time()``) cannot be mocked.
359+
360+
The ``@group time-sensitive`` annotation is equivalent to calling
361+
``ClockMock::register(MyTest::class)``. If you want to mock a function used in a
362+
different class, do it explicitly using ``ClockMock::register(MyClass::class)``::
363+
364+
// the class that uses the time() function to be mocked
365+
namespace App;
366+
367+
class MyClass
368+
{
369+
public function getTimeInHours()
370+
{
371+
return time() / 3600;
372+
}
373+
}
374+
375+
// the test that mocks the external time() function explicitly
376+
namespace App\Tests;
377+
378+
use App\MyClass;
379+
use PHPUnit\Framework\TestCase;
380+
381+
/**
382+
* @group time-sensitive
383+
*/
384+
class MyTest extends TestCase
385+
{
386+
public function testGetTimeInHours()
387+
{
388+
ClockMock::register(MyClass::class);
389+
390+
$my = new MyClass();
391+
$result = $my->getTimeInHours();
392+
393+
$this->assertEquals(time() / 3600, $result);
394+
}
395+
}
396+
355397
.. tip::
356398

357399
An added bonus of using the ``ClockMock`` class is that time passes
@@ -633,3 +675,4 @@ not find the SUT:
633675
.. _`Travis CI`: https://travis-ci.org/
634676
.. _`test listener`: https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.test-listeners
635677
.. _`@covers`: https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.covers
678+
.. _`PHP namespace resolutions rules`: https://php.net/manual/en/language.namespaces.rules.php

doctrine/event_listeners_subscribers.rst

Lines changed: 54 additions & 0 deletions
F438
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,57 @@ whenever possible.
204204

205205
.. _`The Event System`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html
206206
.. _`the Doctrine Documentation`: https://symfony.com/doc/current/bundles/DoctrineBundle/entity-listeners.html
207+
208+
Priorities for Event Listeners
209+
------------------------------
210+
211+
In case you have multiple listeners for the same event you can control the order
212+
in which they are invoked using the ``priority`` attribute on the tag.
213+
Listeners with a higher priority are invoked first.
214+
215+
.. configuration-block::
216+
217+
.. code-block:: yaml
218+
219+
# config/services.yaml
220+
services:
221+
App\EventListener\MyHighPriorityListener:
222+
tags:
223+
- { name: doctrine.event_listener, event: postPersist, priority: 10 }
224+
225+
App\EventListener\MyLowPriorityListener:
226+
tags:
227+
- { name: doctrine.event_listener, event: postPersist, priority: 1 }
228+
229+
.. code-block:: xml
230+
231+
<!-- config/services.xml -->
232+
<?xml version="1.0" ?>
233+
<container xmlns="http://symfony.com/schema/dic/services"
234+
xmlns:doctrine="http://symfony.com/schema/dic/doctrine">
235+
236+
<services>
237+
<service id="App\EventListener\MyHighPriorityListener" autowire="true">
238+
<tag name="doctrine.event_listener" event="postPersist" priority="10" />
239+
</service>
240+
<service id="App\EventListener\MyLowPriorityListener" autowire="true">
241+
<tag name="doctrine.event_listener" event="postPersist" priority="1" />
242+
</service>
243+
</services>
244+
</container>
245+
246+
.. code-block:: php
247+
248+
// config/services.php
249+
use AppBundle\EventListener\MyHighPriorityListener;
250+
use AppBundle\EventListener\MyLowPriorityListener;
251+
252+
$container
253+
->autowire(MyHighPriorityListener::class)
254+
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 10))
255+
;
256+
257+
$container
258+
->autowire(MyLowPriorityListener::class)
259+
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'priority' => 1))
260+
;

messenger.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ this:
449449
This will generate the ``messenger.bus.commands`` and ``messenger.bus.events`` services
450450
that you can inject in your services.
451451

452+
.. note::
453+
454+
To register a handler only for a specific bus, add a ``bus`` attribute to
455+
the handler's service tag (``messenger.message_handler``) and use the bus
456+
name as its value.
457+
452458
Type-hints and Auto-wiring
453459
~~~~~~~~~~~~~~~~~~~~~~~~~~
454460

routing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ with a locale. This can be done by defining a different prefix for each locale
234234
235235
# config/routes/annotations.yaml
236236
controllers:
237-
resource: '../src/Controller/'
237+
resource: '../../src/Controller/'
238238
type: annotation
239239
prefix:
240240
en: '' # don't prefix URLs for English, the default locale

security.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ You can easily deny access from inside a controller::
869869
:ref:`base controller provided by Symfony <the-base-controller-class-services>`.
870870
It's equivalent to the following code::
871871

872-
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
872+
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
873873
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
874874
// ...
875875

security/expressions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Additionally, you have access to a number of functions inside the expression:
6969

7070
.. sidebar:: ``is_remember_me`` is different than checking ``IS_AUTHENTICATED_REMEMBERED``
7171

72-
The ``is_remember_me()`` and ``is_authenticated_fully()`` functions are *similar*
72+
The ``is_remember_me()`` and ``is_fully_authenticated()`` functions are *similar*
7373
to using ``IS_AUTHENTICATED_REMEMBERED`` and ``IS_AUTHENTICATED_FULLY``
7474
with the ``isGranted()`` function - but they are **not** the same. The
7575
following controller snippet shows the difference::

service_container/tags.rst

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,63 @@ automatically applied for you. That's true for the ``twig.extension`` tag: the
6363
container sees that your class extends ``AbstractExtension`` (or more accurately,
6464
that it implements ``ExtensionInterface``) and adds the tag for you.
6565

66-
.. tip::
66+
If you want to apply tags automatically for your own services, use the
67+
``_instanceof`` option::
6768

68-
To apply a tag to all your autoconfigured services extending a class or implementing an
69-
interface, call the :method:`Symfony\\Component\\DependencyInjection\\ContainerBuilder::registerForAutoconfiguration`
70-
method in an :doc:`extension </bundles/extension>` or from your kernel::
69+
.. configuration-block::
7170

72-
// src/Kernel.php
73-
class Kernel extends Kernel
74-
{
75-
// ...
71+
.. code-block:: yaml
7672
77-
protected function build(ContainerBuilder $container)
78-
{
79-
$container->registerForAutoconfiguration(CustomInterface::class)
80-
->addTag('app.custom_tag')
81-
;
82-
}
73+
# config/services.yaml
74+
services:
75+
# this config only applies to the services created by this file
76+
_instanceof:
77+
# services whose classes are instances of CustomInterface will be tagged automatically
78+
App\Security\CustomInterface:
79+
tags: ['app.custom_tag']
80+
# ...
81+
82+
.. code-block:: xml
83+
84+
<!-- config/services.xml -->
85+
<?xml version="1.0" encoding="utf-8"?>
86+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
87+
<services>
88+
<!-- this config only applies to the services created by this file -->
89+
<instanceof id="App\Security\CustomInterface" autowire="true">
90+
<!-- services whose classes are instances of CustomInterface will be tagged automatically -->
91+
<tag name="app.custom_tag" />
92+
</instanceof>
93+
</services>
94+
</container>
95+
96+
.. code-block:: php
97+
98+
// config/services.php
99+
use App\Security\CustomInterface;
100+
// ...
101+
102+
// services whose classes are instances of CustomInterface will be tagged automatically
103+
$container->registerForAutoconfiguration(CustomInterface::class)
104+
->addTag('app.custom_tag')
105+
->setAutowired(true);
106+
107+
For more advanced needs, you can define the automatic tags using the
108+
:method:`Symfony\\Component\\DependencyInjection\\ContainerBuilder::registerForAutoconfiguration`
109+
method in an :doc:`extension </bundles/extension>` or from your kernel::
110+
111+
// src/Kernel.php
112+
class Kernel extends BaseKernel
113+
{
114+
// ...
115+
116+
protected function build(ContainerBuilder $container)
117+
{
118+
$container->registerForAutoconfiguration(CustomInterface::class)
119+
->addTag('app.custom_tag')
120+
;
83121
}
122+
}
84123

85124
Creating custom Tags
86125
--------------------

0 commit comments

Comments
 (0)
0