Skip to content

Commit cf6cbaf

Browse files
committed
Merge branch '2.0' into 2.1
Conflicts: cookbook/doctrine/event_listeners_subscribers.rst
2 parents 6658c97 + aa68789 commit cf6cbaf

File tree

15 files changed

+258
-43
lines changed

15 files changed

+258
-43
lines changed

book/testing.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,6 @@ or perform more complex requests::
354354
'image/jpeg',
355355
123
356356
);
357-
// or
358-
$photo = array(
359-
'tmp_name' => '/path/to/photo.jpg',
360-
'name' => 'photo.jpg',
361-
'type' => 'image/jpeg',
362-
'size' => 123,
363-
'error' => UPLOAD_ERR_OK
364-
);
365357
$client->request(
366358
'POST',
367359
'/submit',

components/console/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ You also need to create the file to run at the command line which creates
8585
an ``Application`` and adds commands to it::
8686

8787
#!/usr/bin/env php
88-
# app/console
8988
<?php
89+
// app/console
9090

9191
use Acme\DemoBundle\Command\GreetCommand;
9292
use Symfony\Component\Console\Application;

components/console/single_command_tool.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,32 @@ it is possible to remove this need by extending the application::
4343

4444
return $defaultCommands;
4545
}
46+
47+
/**
48+
* Overridden so that the application doesn't expect the command
49+
* name to be the first argument.
50+
*/
51+
public function getDefinition()
52+
{
53+
$inputDefinition = parent::getDefinition();
54+
// clear out the normal first argument, which is the command name
55+
$inputDefinition->setArguments();
56+
57+
return $inputDefinition;
58+
}
4659
}
4760

4861
When calling your console script, the command `MyCommand` will then always
4962
be used, without having to pass its name.
63+
64+
You can also simplify how you execute the application::
65+
66+
#!/usr/bin/env php
67+
<?php
68+
// command.php
69+
70+
use Acme\Tool\MyApplication;
71+
72+
$application = new MyApplication();
73+
$application->run();
74+

components/event_dispatcher/introduction.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ the ``getOrder`` method::
317317
.. index::
318318
single: Event Dispatcher; Event subscribers
319319

320+
.. _event_dispatcher-using-event-subscribers:
321+
320322
Using Event Subscribers
321323
~~~~~~~~~~~~~~~~~~~~~~~
322324

contributing/code/git.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Git
2+
===
3+
4+
This document explains some conventions and specificities in the way we manage
5+
the Symfony code with Git.
6+
7+
Pull Requests
8+
-------------
9+
10+
Whenever a pull request is merged, all the information contained in the pull
11+
request (including comments) is saved in the repository.
12+
13+
You can easily spot pull request merges as the commit message always follows
14+
this pattern:
15+
16+
.. block: text
17+
18+
merged branch USER_NAME/BRANCH_NAME (PR #1111)
19+
20+
The PR reference allows you to have a look at the original pull request on
21+
Github: https://github.com/symfony/symfony/pull/1111. But all the information
22+
you can get on Github is also available from the repository itself.
23+
24+
The merge commit message contains the original message from the author of the
25+
changes. Often, this can help understand what the changes were about and the
26+
reasoning behind the changes.
27+
28+
Moreover, the full discussion that might have occurred back then is also
29+
stored as a Git note (before March 22 2013, the discussion was part of the
30+
main merge commit message). To get access to these notes, add this line to
31+
your ``.git/config`` file:
32+
33+
.. block: text
34+
35+
fetch = +refs/notes/*:refs/notes/*
36+
37+
After a fetch, getting the Github discussion for a commit is then a matter of
38+
adding ``--show-notes=github-comments`` to the ``git show`` command:
39+
40+
.. block: text
41+
42+
git show HEAD --show-notes=github-comments

contributing/code/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Contributing Code
1010
tests
1111
standards
1212
conventions
13+
git
1314
license

contributing/documentation/overview.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,23 @@ GitHub covers the topic of `pull requests`_ in detail.
7979
The Symfony2 documentation is licensed under a Creative Commons
8080
Attribution-Share Alike 3.0 Unported :doc:`License <license>`.
8181

82+
You can also prefix the title of your pull request in a few cases:
83+
84+
* ``[WIP]`` (Work in Progress) is used when you are not yet finished with your
85+
pull request, but you would like it to be reviewed. The pull request won't
86+
be merged until you say it is ready.
87+
88+
* ``[WCM]`` (Waiting Code Merge) is used when you're documenting a new feature
89+
or change that hasn't been accepted yet into the core code. The pull request
90+
will not be merged until it is merged in the core code (or closed if the
91+
change is rejected).
92+
8293
.. _doc-contributing-pr-format:
8394

8495
Pull Request Format
8596
~~~~~~~~~~~~~~~~~~~
8697

87-
Unless you're fixing some minor typos, the pull request description must**
98+
Unless you're fixing some minor typos, the pull request description **must**
8899
include the following checklist to ensure that contributions may be reviewed
89100
without needless feedback loops and that your contributions can be included
90101
into the documentation as quickly as possible:

contributing/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* :doc:`Tests </contributing/code/tests>`
77
* :doc:`Coding Standards</contributing/code/standards>`
88
* :doc:`Code Conventions</contributing/code/conventions>`
9+
* :doc:`Git</contributing/code/git>`
910
* :doc:`License </contributing/code/license>`
1011

1112
* **Documentation**

cookbook/doctrine/event_listeners_subscribers.rst

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Doctrine defines two types of objects that can listen to Doctrine events:
1717
listeners and subscribers. Both are very similar, but listeners are a bit
1818
more straightforward. For more, see `The Event System`_ on Doctrine's website.
1919

20+
The Doctrine website also explains all existing events that can be listened to.
21+
2022
Configuring the Listener/Subscriber
2123
-----------------------------------
2224

@@ -119,8 +121,8 @@ Creating the Listener Class
119121
---------------------------
120122

121123
In the previous example, a service ``my.listener`` was configured as a Doctrine
122-
listener on the event ``postPersist``. That class behind that service must have
123-
a ``postPersist`` method, which will be called when the event is thrown::
124+
listener on the event ``postPersist``. The class behind that service must have
125+
a ``postPersist`` method, which will be called when the event is dispatched::
124126

125127
// src/Acme/SearchBundle/EventListener/SearchIndexer.php
126128
namespace Acme\SearchBundle\EventListener;
@@ -149,7 +151,63 @@ itself.
149151
One important thing to notice is that a listener will be listening for *all*
150152
entities in your application. So, if you're interested in only handling a
151153
specific type of entity (e.g. a ``Product`` entity but not a ``BlogPost``
152-
entity), you should check for the class name of the entity in your method
154+
entity), you should check for the entity's class type in your method
153155
(as shown above).
154156

157+
Creating the Subscriber Class
158+
-----------------------------
159+
160+
A doctrine event subscriber must implement the ``Doctrine\Common\EventSubscriber``
161+
interface and have an event method for each event it subscribes to::
162+
163+
// src/Acme/SearchBundle/EventListener/SearchIndexerSubscriber.php
164+
namespace Acme\SearchBundle\EventListener;
165+
166+
use Doctrine\Common\EventSubscriber;
167+
use Doctrine\ORM\Event\LifecycleEventArgs;
168+
// for doctrine 2.4: Doctrine\Common\Persistence\Event\LifecycleEventArgs;
169+
use Acme\StoreBundle\Entity\Product;
170+
171+
class SearchIndexerSubscriber implements EventSubscriber
172+
{
173+
public function getSubscribedEvents()
174+
{
175+
return array(
176+
'postPersist',
177+
'postUpdate',
178+
);
179+
}
180+
181+
public function postUpdate(LifecycleEventArgs $args)
182+
{
183+
$this->index($args);
184+
}
185+
186+
public function postPersist(LifecycleEventArgs $args)
187+
{
188+
$this->index($args);
189+
}
190+
191+
public function index(LifecycleEventArgs $args)
192+
{
193+
$entity = $args->getEntity();
194+
$entityManager = $args->getEntityManager();
195+
196+
// perhaps you only want to act on some "Product" entity
197+
if ($entity instanceof Product) {
198+
// ... do something with the Product
199+
}
200+
}
201+
}
202+
203+
.. tip::
204+
205+
Doctrine event subscribers can not return a flexible array of methods to
206+
call for the events like the :ref:`Symfony event subscriber <event_dispatcher-using-event-subscribers>`
207+
can. Doctrine event subscribers must return a simple array of the event
208+
names they subscribe to. Doctrine will then expect methods on the subscriber
209+
with the same name as each subscribed event, just as when using an event listener.
210+
211+
For a full reference, see chapter `The Event System`_ in the Doctrine documentation.
212+
155213
.. _`The Event System`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html

0 commit comments

Comments
 (0)