Skip to content

Merge #7861 in master #7882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a22a973
use namespaced PHPUnit TestCase class
xabbuh Apr 28, 2017
3c9588e
use namespaced PHPUnit TestCase class
xabbuh Apr 28, 2017
fead634
[PhpUnitBridge] fix Stopwatch API usage
xabbuh Apr 28, 2017
879347c
Replace calls to setDefinition() by register()
GuilhemN Apr 30, 2017
b161bd8
update swiftmailer reference
mykiwi Feb 17, 2017
2bd1a22
Minor tweaks
javiereguiluz Feb 19, 2017
0e2853a
add mail transport as deprecated
mykiwi Feb 23, 2017
3333723
Added the missing "versionadded" directives
javiereguiluz Mar 13, 2017
3395258
Fixed ... again ... the versionadded directives
javiereguiluz Mar 13, 2017
8eaccef
Removed "encryption" and "auth_mode" from the list of %env()% compati…
javiereguiluz Mar 13, 2017
1c39991
fix versionadded directives
xabbuh Apr 30, 2017
7dbf4c5
add labels for old headlines
xabbuh May 1, 2017
2b187c8
minor #7867 add labels for old headlines (xabbuh)
xabbuh May 4, 2017
23bdb62
minor #7862 Backport #7510 for the Symfony 2.7 docs (mykiwi, javiereg…
xabbuh May 4, 2017
7ec94fe
minor #7856 [PhpUnitBridge] fix Stopwatch API usage (xabbuh)
xabbuh May 4, 2017
a360e3c
minor #7855 [PhpUnitBridge] use namespaced PHPUnit TestCase class (xa…
xabbuh May 4, 2017
a256fed
minor #7854 [PhpUnitBridge] use namespaced PHPUnit TestCase class (xa…
xabbuh May 4, 2017
5982698
minor #7861 Replace calls to setDefinition() by register() (GuilhemN)
xabbuh May 4, 2017
a481fdf
Merge commit '59826981d604c02eb5dfa53bf679cf6d86d278fc' into DEFINITION
GuilhemN May 6, 2017
36caee0
Merge branch 'DEFINITION' into MERGE3.2
GuilhemN May 6, 2017
08b531a
Merge branch 'MERGE3.2' into MERGEMASTER
GuilhemN May 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions _includes/service_container/_my_mailer.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

// app/config/services.php
use AppBundle\Mailer;
use Symfony\Component\DependencyInjection\Definition;

$container->setDefinition('app.mailer', new Definition(
Mailer::class,
array('sendmail')
));
$container->register('app.mailer', Mailer::class)
->addArgument('sendmail');
17 changes: 7 additions & 10 deletions components/event_dispatcher.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ determine which instance is passed.
a compiler pass called ``RegisterListenersPass()`` in the container builder::

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\EventDispatcher;
Expand All @@ -209,17 +208,15 @@ determine which instance is passed.
$containerBuilder->register('event_dispatcher', EventDispatcher::class);

// register an event listener
$listener = new Definition(\AcmeListener::class);
$listener->addTag('kernel.event_listener', array(
'event' => 'acme.foo.action',
'method' => 'onFooAction',
));
$containerBuilder->setDefinition('listener_service_id', $listener);
$containerBuilder->register('listener_service_id', \AcmeListener::class)
->addTag('kernel.event_listener', array(
'event' => 'acme.foo.action',
'method' => 'onFooAction',
));

// register an event subscriber
$subscriber = new Definition(\AcmeSubscriber::class);
$subscriber->addTag('kernel.event_subscriber');
$containerBuilder->setDefinition('subscriber_service_id', $subscriber);
$containerBuilder->register('subscriber_service_id', \AcmeSubscriber::class)
->addTag('kernel.event_subscriber');

By default, the listeners pass assumes that the event dispatcher's service
id is ``event_dispatcher``, that event listeners are tagged with the
Expand Down
16 changes: 10 additions & 6 deletions components/phpunit_bridge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,18 @@ Use Case

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

use PHPUnit\Framework\TestCase;
use Symfony\Component\Stopwatch\Stopwatch;

class MyTest extends \PHPUnit_Framework_TestCase
class MyTest extends TestCase
{
public function testSomething()
{
$stopwatch = new Stopwatch();

$stopwatch->start();
$stopwatch->start('event_name');
sleep(10);
$duration = $stopwatch->stop();
$duration = $stopwatch->stop('event_name')->getDuration();

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

use PHPUnit\Framework\TestCase;
use Symfony\Component\Stopwatch\Stopwatch;

/**
* @group time-sensitive
*/
class MyTest extends \PHPUnit_Framework_TestCase
class MyTest extends TestCase
{
public function testSomething()
{
Expand Down Expand Up @@ -297,9 +299,10 @@ Use Case
Consider the following example that uses the ``checkMX`` option of the ``Email``
constraint to test the validity of the email domain::

use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraints\Email;

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

use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraints\Email;

/**
* @group dns-sensitive
*/
class MyTest extends \PHPUnit_Framework_TestCase
class MyTest extends TestCase
{
public function testEmails()
{
Expand Down
11 changes: 5 additions & 6 deletions controller/error_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,12 @@ In that case, you might want to override one or both of the ``showAction()`` and
// app/config/services.php
use AppBundle\Controller\CustomExceptionController;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Definition;

$definition = new Definition(CustomExceptionController::class, array(
new Reference('twig'),
'%kernel.debug%'
));
$container->setDefinition('app.exception_controller', $definition);
$container->register('app.exception_controller', CustomExceptionController::class)
->setArguments(array(
new Reference('twig'),
'%kernel.debug%',
));

And then configure ``twig.exception_controller`` using the controller as
services syntax (e.g. ``app.exception_controller:showAction``).
Expand Down
27 changes: 10 additions & 17 deletions controller/upload_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,10 @@ Then, define a service for this class:

// app/config/services.php
use AppBundle\FileUploader;
use Symfony\Component\DependencyInjection\Definition;

// ...
$container->setDefinition('app.brochure_uploader', new Definition(
FileUploader::class,
array('%brochures_directory%')
));
$container->register('app.brochure_uploader', FileUploader::class)
->addArgument('%brochures_directory%');

Now you're ready to use this service in the controller::

Expand Down Expand Up @@ -411,21 +408,17 @@ Now, register this class as a Doctrine listener:

// app/config/services.php
use AppBundle\EventListener\BrochureUploaderListener;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

// ...
$definition = new Definition(
BrochureUploaderListener::class,
array(new Reference('brochures_directory'))
);
$definition->addTag('doctrine.event_listener', array(
'event' => 'prePersist',
));
$definition->addTag('doctrine.event_listener', array(
'event' => 'preUpdate',
));
$container->setDefinition('app.doctrine_brochure_listener', $definition);
$container->register('app.doctrine_brochure_listener', BrochureUploaderListener::class)
->addArgument(new Reference('brochures_directory'))
->addTag('doctrine.event_listener', array(
'event' => 'prePersist',
))
->addTag('doctrine.event_listener', array(
'event' => 'prePersist',
));

This listener is now automatically executed when persisting a new Product
entity. This way, you can remove everything related to uploading from the
Expand Down
1 change: 0 additions & 1 deletion doctrine/event_listeners_subscribers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ managers that use this connection.
use AppBundle\EventListener\SearchIndexer;
use AppBundle\EventListener\SearchIndexer2;
use AppBundle\EventListener\SearchIndexerSubscriber;
use Symfony\Component\DependencyInjection\Definition;

$container->loadFromExtension('doctrine', array(
'dbal' => array(
Expand Down
19 changes: 8 additions & 11 deletions doctrine/mongodb_session_storage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ need to change/add some parameters in the main configuration file:
.. code-block:: php

use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler;

$container->loadFromExtension('framework', array(
Expand All @@ -89,20 +88,19 @@ need to change/add some parameters in the main configuration file:
),
));

$container->setDefinition('mongo_client', new Definition(
\MongoClient::class,
array(
$container->register('mongo_client', \MongoClient::class)
->setArguments(array(
// if using a username and password
array('mongodb://%mongodb_username%:%mongodb_password%@%mongodb_host%:27017'),
// if not using a username and password
array('mongodb://%mongodb_host%:27017'),
)
));
));

$container->setDefinition('session.handler.mongo', new Definition(
MongoDbSessionHandler::class,
array(new Reference('mongo_client'), '%mongo.session.options%')
));
$container->register('session.handler.mongo', MongoDbSessionHandler::class)
->setArguments(array(
new Reference('mongo_client'),
'%mongo.session.options%',
));

The parameters used above should be defined somewhere in your application, often in your main
parameters configuration:
Expand Down Expand Up @@ -149,7 +147,6 @@ parameters configuration:
.. code-block:: php

use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Definition;

$container->setParameter('mongo.session.options', array(
'database' => 'session_db', // your MongoDB database name
Expand Down
23 changes: 12 additions & 11 deletions doctrine/pdo_session_storage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ To use it, you just need to change some parameters in the main configuration fil

// app/config/config.php

use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;

// ...
$container->loadFromExtension('framework', array(
// ...
Expand All @@ -61,11 +63,11 @@ To use it, you just need to change some parameters in the main configuration fil
),
));

$storageDefinition = new Definition(PdoSessionHandler::class, array(
'mysql:dbname=mydatabase',
array('db_username' => 'myuser', 'db_password' => 'mypassword')
));
$container->setDefinition('session.handler.pdo', $storageDefinition);
$container->register('session.handler.pdo', PdoSessionHandler::class)
->setArguments(array(
'mysql:dbname=mydatabase',
array('db_username' => 'myuser', 'db_password' => 'mypassword'),
));

Configuring the Table and Column Names
--------------------------------------
Expand Down Expand Up @@ -106,15 +108,14 @@ a second array argument to ``PdoSessionHandler``:

// app/config/config.php

use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
// ...

$storageDefinition = new Definition(PdoSessionHandler::class, array(
'mysql:dbname=mydatabase',
array('db_table' => 'sessions', 'db_username' => 'myuser', 'db_password' => 'mypassword')
));
$container->setDefinition('session.handler.pdo', $storageDefinition);
$container->register('session.handler.pdo', PdoSessionHandler::class)
->setArguments(array(
'mysql:dbname=mydatabase',
array('db_table' => 'sessions', 'db_username' => 'myuser', 'db_password' => 'mypassword'),
));

These are parameters that you must configure:

Expand Down
34 changes: 16 additions & 18 deletions event_dispatcher/before_after_filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,13 @@ your listener to be called just before any controller is executed.

// app/config/services.php
use AppBundle\EventListener\TokenListener;
use Symfony\Component\DependencyInjection\Definition;

$listener = new Definition(TokenListener::class, array('%tokens%'));
$listener->addTag('kernel.event_listener', array(
'event' => 'kernel.controller',
'method' => 'onKernelController'
));
$container->setDefinition('app.tokens.action_listener', $listener);
$container->register('app.tokens.action_listener', TokenListener::class)
->addArgument('%tokens%')
->addTag('kernel.event_listener', array(
'event' => 'kernel.controller',
'method' => 'onKernelController',
));

With this configuration, your ``TokenListener`` ``onKernelController()`` method
will be executed on each request. If the controller that is about to be executed
Expand Down Expand Up @@ -271,18 +270,17 @@ event:

// app/config/services.php
use AppBundle\EventListener\TokenListener;
use Symfony\Component\DependencyInjection\Definition;

$listener = new Definition(TokenListener::class, array('%tokens%'));
$listener->addTag('kernel.event_listener', array(
'event' => 'kernel.controller',
'method' => 'onKernelController'
));
$listener->addTag('kernel.event_listener', array(
'event' => 'kernel.response',
'method' => 'onKernelResponse'
));
$container->setDefinition('app.tokens.action_listener', $listener);
$container->register('app.tokens.action_listener', TokenListener::class)
->addArgument('%tokens%')
->addTag('kernel.event_listener', array(
'event' => 'kernel.controller',
'method' => 'onKernelController',
))
->addTag('kernel.event_listener', array(
'event' => 'kernel.response',
'method' => 'onKernelResponse',
));

That's it! The ``TokenListener`` is now notified before every controller is
executed (``onKernelController()``) and after every controller returns a response
Expand Down
13 changes: 4 additions & 9 deletions form/create_custom_field_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,10 @@ the ``genders`` parameter value as the first argument to its to-be-created

// src/AppBundle/Resources/config/services.php
use AppBundle\Form\Type\GenderType;
use Symfony\Component\DependencyInjection\Definition;

$container
->setDefinition('app.form.type.gender', new Definition(
GenderType::class,
array('%genders%')
))
->addTag('form.type')
;

$container->register('app.form.type.gender', GenderType::class)
->addArgument('%genders%')
->addTag('form.type');

.. tip::

Expand Down
13 changes: 3 additions & 10 deletions form/data_transformers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -458,19 +458,12 @@ it's recognized as a custom field type:

// app/config/services.php
use AppBundle\Form\IssueSelectorType;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
// ...

$container
->setDefinition('app.type.issue_selector', new Definition(
IssueSelectorType::class,
array(
new Reference('doctrine.orm.entity_manager'),
)
))
->addTag('form.type')
;
$container->register('app.type.issue_selector', IssueSelectorType::class)
->addArgument(new Reference('doctrine.orm.entity_manager'))
->addTag('form.type');

Now, whenever you need to use your special ``issue_selector`` field type,
it's quite easy::
Expand Down
9 changes: 3 additions & 6 deletions form/dynamic_form_modification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,9 @@ you need to register it as a service and tag it with :ref:`form.type <dic-tags-f
use AppBundle\Form\Type\FriendMessageFormType;
use Symfony\Component\DependencyInjection\Reference;

$definition = new Definition(FriendMessageFormType::class, array(
new Reference('security.token_storage')
));
$definition->addTag('form.type');

$container->setDefinition('app.form.friend_message', $definition);
$container->register('app.form.friend_message', FriendMessageFormType::class)
->addArgument(new Reference('security.token_storage'))
->addTag('form.type');

.. versionadded:: 3.3
Prior to Symfony 3.3, you needed to define form type services as ``public``.
Expand Down
Loading