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

Skip to content

Commit 97faaef

Browse files
committed
Merge branch '3.2'
* 3.2: (23 commits) Update options_resolver.rst Fixed a minor typo Fixed a minor typo add labels for old headlines fix versionadded directives Removed "encryption" and "auth_mode" from the list of %env()% compatible options Fixed ... again ... the versionadded directives Added the missin 8000 g "versionadded" directives add mail transport as deprecated Minor tweaks update swiftmailer reference Replace calls to setDefinition() by register() [PhpUnitBridge] fix Stopwatch API usage use namespaced PHPUnit TestCase class use namespaced PHPUnit TestCase class Better explain empty_data values Readd mixed type for empty_data, it can be string, array or object Tried to write the important points more explicitly Updated the example add added a caution Addressed @stof's comment ...
2 parents cbedd79 + b9ef3c0 commit 97faaef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+226
-332
lines changed

_includes/service_container/_my_mailer.rst.inc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828

2929
// app/config/services.php
3030
use AppBundle\Mailer;
31-
use Symfony\Component\DependencyInjection\Definition;
3231

33-
$container->setDefinition('app.mailer', new Definition(
34-
Mailer::class,
35-
array('sendmail')
36-
));
32+
$container->register('app.mailer', Mailer::class)
33+
->addArgument('sendmail');

components/event_dispatcher.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ determine which instance is passed.
195195
a compiler pass called ``RegisterListenersPass()`` in the container builder::
196196

197197
use Symfony\Component\DependencyInjection\ContainerBuilder;
198-
use Symfony\Component\DependencyInjection\Definition;
199198
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
200199
use Symfony\Component\DependencyInjection\Reference;
201200
use Symfony\Component\EventDispatcher\EventDispatcher;
@@ -209,17 +208,15 @@ determine which instance is passed.
209208
$containerBuilder->register('event_dispatcher', EventDispatcher::class);
210209

211210
// register an event listener
212-
$listener = new Definition(\AcmeListener::class);
213-
$listener->addTag('kernel.event_listener', array(
214-
'event' => 'acme.foo.action',
215-
'method' => 'onFooAction',
216-
));
217-
$containerBuilder->setDefinition('listener_service_id', $listener);
211+
$containerBuilder->register('listener_service_id', \AcmeListener::class)
212+
->addTag('kernel.event_listener', array(
213+
'event' => 'acme.foo.action',
214+
'method' => 'onFooAction',
215+
));
218216

219217
// register an event subscriber
220-
$subscriber = new Definition(\AcmeSubscriber::class);
221-
$subscriber->addTag('kernel.event_subscriber');
222-
$containerBuilder->setDefinition('subscriber_service_id', $subscriber);
218+
$containerBuilder->register('subscriber_service_id', \AcmeSubscriber::class)
219+
->addTag('kernel.event_subscriber');
223220

224221
By default, the listeners pass assumes that the event dispatcher's service
225222
id is ``event_dispatcher``, that event listeners are tagged with the

components/options_resolver.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ the ``Mailer`` class makes a mistake?
9090
.. code-block:: php
9191
9292
$mailer = new Mailer(array(
93-
'usernme' => 'johndoe', // usernAme misspelled
93+
'usernme' => 'johndoe', // usernme misspelled (instead of username)
9494
));
9595
9696
No error will be shown. In the best case, the bug will appear during testing,

components/phpunit_bridge.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,18 @@ Use Case
190190

191191
If you have this kind of time-related tests::
192192

193+
use PHPUnit\Framework\TestCase;
193194
use Symfony\Component\Stopwatch\Stopwatch;
194195

195-
class MyTest extends \PHPUnit_Framework_TestCase
196+
class MyTest extends TestCase
196197
{
197198
public function testSomething()
198199
{
199200
$stopwatch = new Stopwatch();
200201

201-
$stopwatch->start();
202+
$stopwatch->start('event_name');
202203
sleep(10);
203-
$duration = $stopwatch->stop();
204+
$duration = $stopwatch->stop('event_name')->getDuration();
204205

205206
$this->assertEquals(10, $duration);
206207
}
@@ -245,12 +246,13 @@ following listener in your PHPUnit configuration:
245246
As a result, the following is guaranteed to work and is no longer a transient
246247
test::
247248

249+
use PHPUnit\Framework\TestCase;
248250
use Symfony\Component\Stopwatch\Stopwatch;
249251

250252
/**
251253
* @group time-sensitive
252254
*/
253-
class MyTest extends \PHPUnit_Framework_TestCase
255+
class MyTest extends TestCase
254256
{
255257
public function testSomething()
256258
{
@@ -297,9 +299,10 @@ Use Case
297299
Consider the following example that uses the ``checkMX`` option of the ``Email``
298300
constraint to test the validity of the email domain::
299301

302+
use PHPUnit\Framework\TestCase;
300303
use Symfony\Component\Validator\Constraints\Email;
301304

302-
class MyTest extends \PHPUnit_Framework_TestCase
305+
class MyTest extends TestCase
303306
{
304307
public function testEmail()
305308
{
@@ -315,12 +318,13 @@ In order to avoid making a real network connection, add the ``@dns-sensitive``
315318
annotation to the class and use the ``DnsMock::withMockedHosts()`` to configure
316319
the data you expect to get for the given hosts::
317320

321+
use PHPUnit\Framework\TestCase;
318322
use Symfony\Component\Validator\Constraints\Email;
319323

320324
/**
321325
* @group dns-sensitive
322326
*/
323-
class MyTest extends \PHPUnit_Framework_TestCase
327+
class MyTest extends TestCase
324328
{
325329
public function testEmails()
326330
{

controller/error_pages.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,12 @@ In that case, you might want to override one or both of the ``showAction()`` and
296296
// app/config/services.php
297297
use AppBundle\Controller\CustomExceptionController;
298298
use Symfony\Component\DependencyInjection\Reference;
299-
use Symfony\Component\DependencyInjection\Definition;
300299
301-
$definition = new Definition(CustomExceptionController::class, array(
302-
new Reference('twig'),
303-
'%kernel.debug%'
304-
));
305-
$container->setDefinition('app.exception_controller', $definition);
300+
$container->register('app.exception_controller', CustomExceptionController::class)
301+
->setArguments(array(
302+
new Reference('twig'),
303+
'%kernel.debug%',
304+
));
306305
307306
And then configure ``twig.exception_controller`` using the controller as
308307
services syntax (e.g. ``app.exception_controller:showAction``).

controller/service.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ argument:
234234
use AppBundle\Controller\HelloController;
235235
use Symfony\Component\DependencyInjection\Reference;
236236
237-
$container->register(HelloController::class)
237+
$container->register('app.hello_controller', HelloController::class)
238238
->addArgument(new Reference('templating'));
239239
240240
Rather than fetching the ``templating`` service from the container, you can

controller/upload_file.rst

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,10 @@ Then, define a service for this class:
283283
284284
// app/config/services.php
285285
use AppBundle\FileUploader;
286-
use Symfony\Component\DependencyInjection\Definition;
287286
288287
// ...
289-
$container->setDefinition('app.brochure_uploader', new Definition(
290-
FileUploader::class,
291-
array('%brochures_directory%')
292-
));
288+
$container->register('app.brochure_uploader', FileUploader::class)
289+
->addArgument('%brochures_directory%');
293290
294291
Now you're ready to use this service in the controller::
295292

@@ -411,21 +408,17 @@ Now, register this class as a Doctrine listener:
411408
412409
// app/config/services.php
413410
use AppBundle\EventListener\BrochureUploaderListener;
414-
use Symfony\Component\DependencyInjection\Definition;
415411
use Symfony\Component\DependencyInjection\Reference;
416412
417413
// ...
418-
$definition = new Definition(
419-
BrochureUploaderListener::class,
420-
array(new Reference('brochures_directory'))
421-
);
422-
$definition->addTag('doctrine.event_listener', array(
423-
'event' => 'prePersist',
424-
));
425-
$definition->addTag('doctrine.event_listener', array(
426-
'event' => 'preUpdate',
427-
));
428-
$container->setDefinition('app.doctrine_brochure_listener', $definition);
414+
$container->register('app.doctrine_brochure_listener', BrochureUploaderListener::class)
415+
->addArgument(new Reference('brochures_directory'))
416+
->addTag('doctrine.event_listener', array(
417+
'event' => 'prePersist',
418+
))
419+
->addTag('doctrine.event_listener', array(
420+
'event' => 'prePersist',
421+
));
429422
430423
This listener is now automatically executed when persisting a new Product
431424
entity. This way, you can remove everything related to uploading from the

doctrine/event_listeners_subscribers.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ managers that use this connection.
8484
use AppBundle\EventListener\SearchIndexer;
8585
use AppBundle\EventListener\SearchIndexer2;
8686
use AppBundle\EventListener\SearchIndexerSubscriber;
87-
use Symfony\Component\DependencyInjection\Definition;
8887
8988
$container->loadFromExtension('doctrine', array(
9089
'dbal' => array(

doctrine/mongodb_session_storage.rst

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ need to change/add some parameters in the main configuration file:
7777
.. code-block:: php
7878
7979
use Symfony\Component\DependencyInjection\Reference;
80-
use Symfony\Component\DependencyInjection\Definition;
8180
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler;
8281
8382
$container->loadFromExtension('framework', array(
@@ -89,20 +88,19 @@ need to change/add some parameters in the main configuration file:
8988
),
9089
));
9190
92-
$container->setDefinition('mongo_client', new Definition(
93-
\MongoClient::class,
94-
array(
91+
$container->register('mongo_client', \MongoClient::class)
92+
->setArguments(array(
9593
// if using a username and password
9694
array('mongodb://%mongodb_username%:%mongodb_password%@%mongodb_host%:27017'),
9795
// if not using a username and password
9896
array('mongodb://%mongodb_host%:27017'),
99-
)
100-
));
97+
));
10198
102-
$container->setDefinition('session.handler.mongo', new Definition(
103-
MongoDbSessionHandler::class,
104-
array(new Reference('mongo_client'), '%mongo.session.options%')
105-
));
99+
$container->register('session.handler.mongo', MongoDbSessionHandler::class)
100+
->setArguments(array(
101+
new Reference('mongo_client'),
102+
'%mongo.session.options%',
103+
));
106104
107105
The parameters used above should be defined somewhere in your application, often in your main
108106
parameters configuration:
@@ -149,7 +147,6 @@ parameters configuration:
149147
.. code-block:: php
150148
151149
use Symfony\Component\DependencyInjection\Reference;
152-
use Symfony\Component\DependencyInjection\Definition;
153150
154151
$container->setParameter('mongo.session.options', array(
155152
'database' => 'session_db', // your MongoDB database name

doctrine/pdo_session_storage.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ To use it, you just need to change some parameters in the main configuration fil
5252
5353
// app/config/config.php
5454
55+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
56+
5557
// ...
5658
$container->loadFromExtension('framework', array(
5759
// ...
@@ -61,11 +63,11 @@ To use it, you just need to change some parameters in the main configuration fil
6163
),
6264
));
6365
64-
$storageDefinition = new Definition(PdoSessionHandler::class, array(
65-
'mysql:dbname=mydatabase',
66-
array('db_username' => 'myuser', 'db_password' => 'mypassword')
67-
));
68-
$container->setDefinition('session.handler.pdo', $storageDefinition);
66+
$container->register('session.handler.pdo', PdoSessionHandler::class)
67+
->setArguments(array(
68+
'mysql:dbname=mydatabase',
69+
array('db_username' => 'myuser', 'db_password' => 'mypassword'),
70+
));
6971
7072
Configuring the Table and Column Names
7173
--------------------------------------
@@ -106,15 +108,14 @@ a second array argument to ``PdoSessionHandler``:
106108
107109
// app/config/config.php
108110
109-
use Symfony\Component\DependencyInjection\Definition;
110111
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
111112
// ...
112113
113-
$storageDefinition = new Definition(PdoSessionHandler::class, array(
114-
'mysql:dbname=mydatabase',
115-
array('db_table' => 'sessions', 'db_username' => 'myuser', 'db_password' => 'mypassword')
116-
));
117-
$container->setDefinition('session.handler.pdo', $storageDefinition);
114+
$container->register('session.handler.pdo', PdoSessionHandler::class)
115+
->setArguments(array(
116+
'mysql:dbname=mydatabase',
117+
array('db_table' => 'sessions', 'db_username' => 'myuser', 'db_password' => 'mypassword'),
118+
));
118119
119120
These are parameters that you must configure:
120121

event_dispatcher/before_after_filters.rst

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,13 @@ your listener to be called just before any controller is executed.
173173
174174
// app/config/services.php
175175
use AppBundle\EventListener\TokenListener;
176-
use Symfony\Component\DependencyInjection\Definition;
177176
178-
$listener = new Definition(TokenListener::class, array('%tokens%'));
179-
$listener->addTag('kernel.event_listener', array(
180-
'event' => 'kernel.controller',
181-
'method' => 'onKernelController'
182-
));
183-
$container->setDefinition('app.tokens.action_listener', $listener);
177+
$container->register('app.tokens.action_listener', TokenListener::class)
178+
->addArgument('%tokens%')
179+
->addTag('kernel.event_listener', array(
180+
'event' => 'kernel.controller',
181+
'method' => 'onKernelController',
182+
));
184183
185184
With this configuration, your ``TokenListener`` ``onKernelController()`` method
186185
will be executed on each request. If the controller that is about to be executed
@@ -271,18 +270,17 @@ event:
271270
272271
// app/config/services.php
273272
use AppBundle\EventListener\TokenListener;
274-
use Symfony\Component\DependencyInjection\Definition;
275273
276-
$listener = new Definition(TokenListener::class, array('%tokens%'));
277-
$listener->addTag('kernel.event_listener', array(
278-
'event' => 'kernel.controller',
279-
'method' => 'onKernelController'
280-
));
281-
$listener->addTag('kernel.event_listener', array(
282-
'event' => 'kernel.response',
283-
'method' => 'onKernelResponse'
284-
));
285-
$container->setDefinition('app.tokens.action_listener', $listener);
274+
$container->register('app.tokens.action_listener', TokenListener::class)
275+
->addArgument('%tokens%')
276+
->addTag('kernel.event_listener', array(
277+
'event' => 'kernel.controller',
278+
'method' => 'onKernelController',
279+
))
280+
->addTag('kernel.event_listener', array(
281+
'event' => 'kernel.response',
282+
'method' => 'onKernelResponse',
283+
));
286284
287285
That's it! The ``TokenListener`` is now notified before every controller is
288286
executed (``onKernelController()``) and after every controller returns a response

form/create_custom_field_type.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,9 @@ the ``genders`` parameter value as the first argument to its to-be-created
323323
324324
// src/AppBundle/Resources/config/services.php
325325
use AppBundle\Form\Type\GenderType;
326-
use Symfony\Component\DependencyInjection\Definition;
327326
328-
$container
329-
->setDefinition('app.form.type.gender', new Definition(
330-
GenderType::class,
331-
array('%genders%')
332-
))
327+
$container->register('app.form.type.gender', GenderType::class)
328+
->addArgument('%genders%')
333329
->addTag('form.type')
334330
;
335331

form/data_transformers.rst

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -458,19 +458,12 @@ it's recognized as a custom field type:
458458
459459
// app/config/services.php
460460
use AppBundle\Form\IssueSelectorType;
461-
use Symfony\Component\DependencyInjection\Definition;
462461
use Symfony\Component\DependencyInjection\Reference;
463462
// ...
464463
465-
$container
466-
->setDefinition('app.type.issue_selector', new Definition(
467-
IssueSelectorType::class,
468-
array(
469-
new Reference('doctrine.orm.entity_manager'),
470-
)
471-
))
472-
->addTag('form.type')
473-
;
464+
$container->register('app.type.issue_selector', IssueSelectorType::class)
465+
->addArgument(new Reference('doctrine.orm.entity_manager'))
466+
->addTag('form.type');
474467
475468
Now, whenever you need to use your special ``issue_selector`` field type,
476469
it's quite easy::

form/dynamic_form_modification.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,9 @@ you need to register it as a service and tag it with :ref:`form.type <dic-tags-f
362362
use AppBundle\Form\Type\FriendMessageFormType;
363363
use Symfony\Component\DependencyInjection\Reference;
364364
365-
$definition = new Definition(FriendMessageFormType::class, array(
366-
new Reference('security.token_storage')
367-
));
368-
$definition->addTag('form.type');
369-
370-
$container->setDefinition('app.form.friend_message', $definition);
365+
$container->register('app.form.friend_message', FriendMessageFormType::class)
366+
->addArgument(new Reference('security.token_storage'))
367+
->addTag('form.type');
371368
372369
.. versionadded:: 3.3
373370
Prior to Symfony 3.3, you needed to define form type services as ``public``.

0 commit comments

Comments
 (0)
0