Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7b53ef2

Browse filesBrowse files
authored
Merge branch '2.7' into CONTROLLERASASERVICE
2 parents 5fb2e81 + 77b7fb0 commit 7b53ef2
Copy full SHA for 7b53ef2

File tree

Expand file treeCollapse file tree

79 files changed

+1252
-889
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

79 files changed

+1252
-889
lines changed

‎_build/redirection_map

Copy file name to clipboardExpand all lines: _build/redirection_map
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,4 @@
325325
/deployment/tools /deployment
326326
/install/bundles /setup/bundles
327327
/form /forms
328+
/testing/simulating_authentication /testing/http_authentication

‎_includes/service_container/_my_mailer.rst.inc

Copy file name to clipboardExpand all lines: _includes/service_container/_my_mailer.rst.inc
+2-5Lines 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');

‎bundles/configuration.rst

Copy file name to clipboardExpand all lines: bundles/configuration.rst
+48-4Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,64 @@ This class can now be used in your ``load()`` method to merge configurations and
218218
force validation (e.g. if an additional option was passed, an exception will be
219219
thrown)::
220220

221+
// src/Acme/SocialBundle/DependencyInjection/AcmeSocialExtension.php
222+
221223
public function load(array $configs, ContainerBuilder $container)
222224
{
223225
$configuration = new Configuration();
224226

225227
$config = $this->processConfiguration($configuration, $configs);
226-
// ...
228+
229+
// you now have these 2 config keys
230+
// $config['twitter']['client_id'] and $config['twitter']['client_secret']
227231
}
228232

229233
The ``processConfiguration()`` method uses the configuration tree you've defined
230234
in the ``Configuration`` class to validate, normalize and merge all the
231235
configuration arrays together.
232236

237+
Now, you can use the ``$config`` variable to modify a service provided by your bundle.
238+
For example, imagine your bundle has the following example config:
239+
240+
.. code-block:: xml
241+
242+
<!-- src/Acme/SocialBundle/Resources/config/services.xml -->
243+
<?xml version="1.0" encoding="UTF-8" ?>
244+
<container xmlns="http://symfony.com/schema/dic/services"
245+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
246+
xsi:schemaLocation="http://symfony.com/schema/dic/services
247+
http://symfony.com/schema/dic/services/services-1.0.xsd">
248+
249+
<services>
250+
<service id="acme.social.twitter_client" class="Acme\SocialBundle\TwitterClient">
251+
<argument></argument> <!-- will be filled in with client_id dynamically -->
252+
<argument></argument> <!-- will be filled in with client_secret dynamically -->
253+
</service>
254+
</services>
255+
</container>
256+
257+
In your extension, you can load this and dynamically set its arguments::
258+
259+
// src/Acme/SocialBundle/DependencyInjection/AcmeSocialExtension.php
260+
// ...
261+
262+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
263+
use Symfony\Component\Config\FileLocator;
264+
265+
public function load(array $configs, ContainerBuilder $container)
266+
{
267+
$loader = new XmlFileLoader($container, new FileLocator(dirname(__DIR__).'/Resources/config'));
268+
$loader->load('services.xml');
269+
270+
$configuration = new Configuration();
271+
$config = $this->processConfiguration($configuration, $configs);
272+
273+
$def = $container->getDefinition('acme.social.twitter_client');
274+
$def->replaceArgument(0, $config['twitter']['client_id']);
275+
$def->replaceArgument(1, $config['twitter']['client_secret']);
276+
}
277+
278+
233279
.. tip::
234280

235281
Instead of calling ``processConfiguration()`` in your extension each time you
@@ -253,9 +299,7 @@ configuration arrays together.
253299
}
254300

255301
This class uses the ``getConfiguration()`` method to get the Configuration
256-
instance. You should override it if your Configuration class is not called
257-
``Configuration`` or if it is not placed in the same namespace as the
258-
extension.
302+
instance.
259303

260304
.. sidebar:: Processing the Configuration yourself
261305

‎bundles/inheritance.rst

Copy file name to clipboardExpand all lines: bundles/inheritance.rst
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ The same goes for routing files and some other resources.
9393

9494
The overriding of resources only works when you refer to resources with
9595
the ``@FOSUserBundle/Resources/config/routing/security.xml`` method.
96-
If you refer to resources without using the ``@BundleName`` shortcut, they
97-
can't be overridden in this way.
96+
You need to use the ``@BundleName`` shortcut when referring to resources
97+
so they can be successfully overridden (except templates, which are
98+
overridden in a different way, as explained in :doc:`/templating/overriding`).
9899

99100
.. caution::
100101

‎bundles/installation.rst

Copy file name to clipboardExpand all lines: bundles/installation.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ version, include it as the second argument of the `composer require`_ command:
4848
B) Enable the Bundle
4949
--------------------
5050

51-
At this point, the bundle is installed in your Symfony project (in
51+
At this point, the bundle is installed in your Symfony project (e.g.
5252
``vendor/friendsofsymfony/``) and the autoloader recognizes its classes.
5353
The only thing you need to do now is register the bundle in ``AppKernel``::
5454

‎bundles/override.rst

Copy file name to clipboardExpand all lines: bundles/override.rst
+4-13Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Services & Configuration
3939

4040
If you want to modify service definitions of another bundle, you can use a compiler
4141
pass to change the class of the service or to modify method calls. In the following
42-
example, the implementing class for the ``original-service-id`` is changed to
42+
example, the implementing class for the ``original-service-id`` is changed to
4343
``Acme\DemoBundle\YourService``::
4444

4545
// src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php
@@ -72,17 +72,8 @@ associations. Learn more about this feature and its limitations in
7272
Forms
7373
-----
7474

75-
In order to override a form type, it has to be registered as a service (meaning
76-
it is tagged as ``form.type``). You can then override it as you would override any
77-
service as explained in `Services & Configuration`_. This, of course, will only
78-
work if the type is referred to by its alias rather than being instantiated,
79-
e.g.::
80-
81-
$builder->add('name', 'custom_type');
82-
83-
rather than::
84-
85-
$builder->add('name', new CustomType());
75+
Existing form types can be modified defining
76+
:doc:`form type extensions </form/create_form_type_extension>`.
8677

8778
.. _override-validation:
8879

@@ -93,7 +84,7 @@ Symfony loads all validation configuration files from every bundle and
9384
combines them into one validation metadata tree. This means you are able to
9485
add new constraints to a property, but you cannot override them.
9586

96-
To override this, the 3rd party bundle needs to have configuration for
87+
To overcome this, the 3rd party bundle needs to have configuration for
9788
:doc:`validation groups </validation/groups>`. For instance, the FOSUserBundle
9889
has this configuration. To create your own validation, add the constraints
9990
to a new validation group:

‎bundles/prepend_extension.rst

Copy file name to clipboardExpand all lines: bundles/prepend_extension.rst
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
single: Configuration; Semantic
33
single: Bundle; Extension configuration
44

5-
How to Simplify Configuration of multiple Bundles
5+
How to Simplify Configuration of Multiple Bundles
66
=================================================
77

88
When building reusable and extensible applications, developers are often
@@ -12,9 +12,9 @@ users to choose to remove functionality they are not using. Creating multiple
1212
bundles has the drawback that configuration becomes more tedious and settings
1313
often need to be repeated for various bundles.
1414

15-
Using the below approach, it is possible to remove the disadvantage of the
16-
multiple bundle approach by enabling a single Extension to prepend the settings
17-
for any bundle. It can use the settings defined in the ``app/config/config.yml``
15+
It is possible to remove the disadvantage of the multiple bundle approach
16+
by enabling a single Extension to prepend the settings for any bundle.
17+
It can use the settings defined in the ``app/config/config.yml``
1818
to prepend settings just as if they had been written explicitly by
1919
the user in the application configuration.
2020

‎components/console/helpers/dialoghelper.rst

Copy file name to clipboardExpand all lines: components/console/helpers/dialoghelper.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ method::
125125
'AcmeDemoBundle'
126126
);
127127

128-
This methods has 2 new arguments, the full signature is::
128+
This method has 2 new arguments, the full signature is::
129129

130130
askAndValidate(
131131
OutputInterface $output,

‎components/event_dispatcher.rst

Copy file name to clipboardExpand all lines: components/event_dispatcher.rst
+11-16Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ answer.
2222
Consider the real-world example where you want to provide a plugin system
2323
for your project. A plugin should be able to add methods, or do something
2424
before or after a method is executed, without interfering with other plugins.
25-
This is not an easy problem to solve with single inheritance, and even if
25+
This is not an easy problem to solve with single inheritance, and even if
2626
multiple inheritance was possible with PHP, it comes with its own drawbacks.
2727

2828
The Symfony EventDispatcher component implements the `Mediator`_ pattern
@@ -198,7 +198,6 @@ determine which instance is passed.
198198
to tag services as event listeners::
199199

200200
use Symfony\Component\DependencyInjection\ContainerBuilder;
201-
use Symfony\Component\DependencyInjection\Definition;
202201
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
203202
use Symfony\Component\DependencyInjection\Reference;
204203
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
@@ -208,23 +207,19 @@ determine which instance is passed.
208207
$containerBuilder->addCompilerPass(new RegisterListenersPass());
209208

210209
// register the event dispatcher service
211-
$containerBuilder->setDefinition('event_dispatcher', new Definition(
212-
ContainerAwareEventDispatcher::class,
213-
array(new Reference('service_container'))
214-
));
210+
$containerBuilder->register('event_dispatcher', ContainerAwareEventDispatcher::class)
211+
->addArgument(new Reference('service_container'));
215212

216213
// register your event listener service
217-
$listener = new Definition(\AcmeListener::class);
218-
$listener->addTag('kernel.event_listener', array(
219-
'event' => 'acme.foo.action',
220-
'method' => 'onFooAction',
221-
));
222-
$containerBuilder->setDefinition('listener_service_id', $listener);
214+
$containerBuilder->register('listener_service_id', \AcmeListener::class)
215+
->addTag('kernel.event_listener', array(
216+
'event' => 'acme.foo.action',
217+
'method' => 'onFooAction',
218+
));
223219

224220
// register an event subscriber
225-
$subscriber = new Definition(\AcmeSubscriber::class);
226-
$subscriber->addTag('kernel.event_subscriber');
227-
$containerBuilder->setDefinition('subscriber_service_id', $subscriber);
221+
$containerBuilder->register('subscriber_service_id', \AcmeSubscriber::class)
222+
->addTag('kernel.event_subscriber');
228223

229224
By default, the listeners pass assumes that the event dispatcher's service
230225
id is ``event_dispatcher``, that event listeners are tagged with the
@@ -441,7 +436,7 @@ EventDispatcher Aware Events and Listeners
441436
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
442437

443438
The ``EventDispatcher`` always passes the dispatched event, the event's
444-
name and a reference to itself to the listeners. This can lead to some advanced
439+
name and a reference to itself to the listeners. This can lead to some advanced
445440
applications of the ``EventDispatcher`` including dispatching other events inside
446441
listeners, chaining events or even lazy loading listeners into the dispatcher object.
447442

‎components/options_resolver.rst

Copy file name to clipboardExpand all lines: components/options_resolver.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ the ``Mailer`` class makes a mistake?
9898
.. code-block:: php
9999
100100
$mailer = new Mailer(array(
101-
'usernme' => 'johndoe', // usernAme misspelled
101+
'usernme' => 'johndoe', // usernme misspelled (instead of username)
102102
));
103103
104104
No error will be shown. In the best case, the bug will appear during testing,

‎console.rst

Copy file name to clipboardExpand all lines: console.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ you can extend your test from
273273
{
274274
public function testExecute()
275275
{
276-
$kernel = $this->createKernel();
276+
$kernel = static::createKernel();
277277
$kernel->boot();
278278

279279
$application = new Application($kernel);

‎console/coloring.rst

Copy file name to clipboardExpand all lines: console/coloring.rst
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ You can also set these colors and options directly inside the tagname::
6565
// bold text on a yellow background
6666
$output->writeln('<bg=yellow;options=bold>foo</>');
6767

68+
.. note::
69+
70+
If you need to render a tag literally, escape it with a backslash: ``\<info>``
71+
or use the :method:`Symfony\\Component\\Console\\Formatter\\OutputFormatter::escape`
72+
method to escape all the tags included in the given string.
73+
6874
.. _Cmder: http://cmder.net/
6975
.. _ConEmu: https://conemu.github.io/
7076
.. _ANSICON: https://github.com/adoxa/ansicon/releases

‎console/logging.rst

Copy file name to clipboardExpand all lines: console/logging.rst
+12-26Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,14 @@ First configure a listener for console exception events in the service container
110110
111111
// app/config/services.php
112112
use AppBundle\EventListener\ConsoleExceptionListener;
113-
use Symfony\Component\DependencyInjection\Definition;
114113
use Symfony\Component\DependencyInjection\Reference;
115114
116-
$definitionConsoleExceptionListener = new Definition(
117-
ConsoleExceptionListener::class,
118-
array(new Reference('logger'))
119-
);
120-
$definitionConsoleExceptionListener->addTag(
121-
'kernel.event_listener',
122-
array('event' => 'console.exception')
123-
);
124-
$container->setDefinition(
125-
'app.listener.command_exception',
126-
$definitionConsoleExceptionListener
127-
);
115+
$container->register('app.listener.command_exception', ConsoleExceptionListener::class)
116+
->addArgument(new Reference('logger'))
117+
->addTag(
118+
'kernel.event_listener',
119+
array('event' => 'console.exception')
120+
);
128121
129122
Then implement the actual listener::
130123

@@ -211,21 +204,14 @@ First configure a listener for console terminate events in the service container
211204
212205
// app/config/services.php
213206
use AppBundle\EventListener\ErrorLoggerListener;
214-
use Symfony\Component\DependencyInjection\Definition;
215207
use Symfony\Component\DependencyInjection\Reference;
216208
217-
$definitionErrorLoggerListener = new Definition(
218-
ErrorLoggerListener::class,
219-
array(new Reference('logger'))
220-
);
221-
$definitionErrorLoggerListener->addTag(
222-
'kernel.event_listener',
223-
array('event' => 'console.terminate')
224-
);
225-
$container->setDefinition(
226-
'app.listener.command_error',
227-
$definitionErrorLoggerListener
228-
);
209+
$container->register('app.listener.command_error', ErrorLoggerListener::class)
210+
->addArgument(new Reference('logger'))
211+
->addTag(
212+
'kernel.event_listener',
213+
array('event' => 'console.terminate')
214+
);
229215
230216
Then implement the actual listener::
231217

‎contributing/code/index.rst

Copy file name to clipboardExpand all lines: contributing/code/index.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Contributing Code
55
:maxdepth: 2
66

77
bugs
8+
reproducer
89
patches
910
maintenance
1011
core_team

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.