Skip to content

Commit 9353c49

Browse files
committed
Merge branch '3.2'
* 3.2: (22 commits) add missing config formats [symfony#7224] fix indentation [symfony#7220] some minor tweaks [symfony#7196] add versionadded directive Explained how to improve the readability of long numeric literals Fix typo in workflow usage code lock Added "How to Use a Custom Version Strategy for Assets" Use PHP 5.5's ::class notation Update state-machines.rst [PHPUnitBridge] Fix copy/paste error [PHPUnitBridge] Fix copy/paste error [symfony#7243] minor tweak Deletes duplicate "Deprecated" and adds a more explicit example. Accepted Suggestions Update 'query_builder' option Mentioned %env(...)% variables in Best Practices book Accepted suggestions in the guard documentation Accepted suggestions in the guard documentation Accepted suggestions in the guard documentation Update guard_authentication.rst ...
2 parents acdd7ad + 1d96829 commit 9353c49

File tree

103 files changed

+1021
-563
lines changed

Some content is hidden

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

103 files changed

+1021
-563
lines changed

_build/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@
112112
lexers['terminal'] = TerminalLexer()
113113

114114
config_block = {
115+
'apache': 'Apache',
115116
'markdown': 'Markdown',
117+
'nginx': 'Nginx',
116118
'rst': 'reStructuredText',
119+
'terminal': 'Terminal',
117120
'varnish3': 'Varnish 3',
118121
'varnish4': 'Varnish 4'
119122
}

_includes/service_container/_my_mailer.rst.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
.. code-block:: php
2828

2929
// app/config/services.php
30+
use AppBundle\Mailer;
3031
use Symfony\Component\DependencyInjection\Definition;
3132

3233
$container->setDefinition('app.mailer', new Definition(
33-
'AppBundle\Mailer',
34+
Mailer::class,
3435
array('sendmail')
3536
));

best_practices/configuration.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,20 @@ Moving Sensitive Options Outside of Symfony Entirely
175175

176176
When dealing with sensitive options, like database credentials, we also recommend
177177
that you store them outside the Symfony project and make them available
178-
through environment variables. Learn how to do it in the following article:
179-
:doc:`/configuration/external_parameters`.
178+
through environment variables:
179+
180+
.. code-block:: yaml
181+
182+
# app/config/config.yml
183+
doctrine:
184+
dbal:
185+
# ...
186+
password: "%env(DB_PASSWORD)%"
187+
188+
.. versionadded:: 3.2
189+
Support for runtime environment variables via the ``%env(...)%`` syntax
190+
was added in Symfony 3.2. Prior to version 3.2, you needed to use the
191+
:doc:`special SYMFONY__ variables </configuration/external_parameters>`.
180192

181193
.. _`feature toggles`: https://en.wikipedia.org/wiki/Feature_toggle
182194
.. _`constant() function`: http://twig.sensiolabs.org/doc/functions/constant.html

best_practices/forms.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ form in its own PHP class::
1919

2020
namespace AppBundle\Form;
2121

22+
use AppBundle\Entity\Post;
2223
use Symfony\Component\Form\AbstractType;
2324
use Symfony\Component\Form\FormBuilderInterface;
2425
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -42,7 +43,7 @@ form in its own PHP class::
4243
public function configureOptions(OptionsResolver $resolver)
4344
{
4445
$resolver->setDefaults(array(
45-
'data_class' => 'AppBundle\Entity\Post'
46+
'data_class' => Post::class,
4647
));
4748
}
4849
}

bundles/extension.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,17 @@ Your bundles can also add their own classes into this file thanks to the
137137
``addClassesToCompile()`` method. Define the classes to compile as an array of
138138
their fully qualified class names::
139139

140+
use AppBundle\Manager\UserManager;
141+
use AppBundle\Utils\Slugger;
142+
140143
// ...
141144
public function load(array $configs, ContainerBuilder $container)
142145
{
143146
// ...
144147

145148
$this->addClassesToCompile(array(
146-
'AppBundle\\Manager\\UserManager',
147-
'AppBundle\\Utils\\Slugger',
149+
UserManager::class,
150+
Slugger::class,
148151
// ...
149152
));
150153
}

bundles/override.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ example, the implementing class for the ``original-service-id`` is changed to
4545
// src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php
4646
namespace Acme\DemoBundle\DependencyInjection\Compiler;
4747

48+
use Acme\DemoBundle\YourService;
4849
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
4950
use Symfony\Component\DependencyInjection\ContainerBuilder;
5051

@@ -53,7 +54,7 @@ example, the implementing class for the ``original-service-id`` is changed to
5354
public function process(ContainerBuilder $container)
5455
{
5556
$definition = $container->getDefinition('original-service-id');
56-
$definition->setClass('Acme\DemoBundle\YourService');
57+
$definition->setClass(YourService::class);
5758
}
5859
}
5960

components/class_loader/class_loader.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ looked for in a location list to ease the vendoring of a sub-set of classes
5959
for large projects::
6060

6161
$loader->addPrefixes(array(
62-
'Doctrine\\Common' => __DIR__.'/vendor/doctrine/common/lib',
63-
'Doctrine\\DBAL\\Migrations' => __DIR__.'/vendor/doctrine/migrations/lib',
64-
'Doctrine\\DBAL' => __DIR__.'/vendor/doctrine/dbal/lib',
65-
'Doctrine' => __DIR__.'/vendor/doctrine/orm/lib',
62+
'Doctrine\Common' => __DIR__.'/vendor/doctrine/common/lib',
63+
'Doctrine\DBAL\Migrations' => __DIR__.'/vendor/doctrine/migrations/lib',
64+
'Doctrine\DBAL' => __DIR__.'/vendor/doctrine/dbal/lib',
65+
'Doctrine' => __DIR__.'/vendor/doctrine/orm/lib',
6666
));
6767

6868
In this example, if you try to use a class in the ``Doctrine\Common`` namespace

components/class_loader/psr4_class_loader.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,15 @@ The directory structure will look like this:
3838
demo.php
3939
4040
In ``demo.php`` you are going to parse the ``config.yml`` file. To do that, you
41-
first need to configure the ``Psr4ClassLoader``:
42-
43-
.. code-block:: php
41+
first need to configure the ``Psr4ClassLoader``::
4442

4543
use Symfony\Component\ClassLoader\Psr4ClassLoader;
4644
use Symfony\Component\Yaml\Yaml;
4745

4846
require __DIR__.'/lib/ClassLoader/Psr4ClassLoader.php';
4947

5048
$loader = new Psr4ClassLoader();
51-
$loader->addPrefix('Symfony\\Component\\Yaml\\', __DIR__.'/lib/Yaml');
49+
$loader->addPrefix('Symfony\Component\Yaml\\', __DIR__.'/lib/Yaml');
5250
$loader->register();
5351

5452
$data = Yaml::parse(file_get_contents(__DIR__.'/config.yml'));

components/dependency_injection/autowiring.rst

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ service is marked as autowired:
7373
7474
.. code-block:: php
7575
76+
use Acme\TwitterClient;
7677
use Symfony\Component\DependencyInjection\Definition;
7778
7879
// ...
79-
$definition = new Definition('Acme\TwitterClient');
80+
$definition = new Definition(TwitterClient::class);
8081
$definition->setAutowired(true);
8182
8283
$container->setDefinition('twitter_client', $definition);
@@ -147,9 +148,8 @@ modifying the class depending of them.
147148

148149
To follow this best practice, constructor arguments must be typehinted with interfaces
149150
and not concrete classes. It allows to replace easily the current implementation
150-
if necessary. It also allows to use other transformers.
151-
152-
Let's introduce a ``TransformerInterface``::
151+
if necessary. It also allows to use other transformers. You can create a
152+
``TransformerInterface`` containing just one method (``transform()``)::
153153

154154
namespace Acme;
155155

@@ -161,18 +161,15 @@ Let's introduce a ``TransformerInterface``::
161161
Then edit ``Rot13Transformer`` to make it implementing the new interface::
162162

163163
// ...
164-
165164
class Rot13Transformer implements TransformerInterface
166-
167-
// ...
168-
165+
{
166+
// ...
167+
}
169168

170169
And update ``TwitterClient`` to depend of this new interface::
171170

172171
class TwitterClient
173172
{
174-
// ...
175-
176173
public function __construct(TransformerInterface $transformer)
177174
{
178175
// ...
@@ -212,12 +209,13 @@ subsystem isn't able to find itself the interface implementation to register:
212209
213210
.. code-block:: php
214211
212+
use Acme\TwitterClient;
215213
use Symfony\Component\DependencyInjection\Definition;
216214
217215
// ...
218216
$container->register('rot13_transformer', 'Acme\Rot13Transformer');
219217
220-
$clientDefinition = new Definition('Acme\TwitterClient');
218+
$clientDefinition = new Definition(TwitterClient::class);
221219
$clientDefinition->setAutowired(true);
222220
$container->setDefinition('twitter_client', $clientDefinition);
223221
@@ -350,23 +348,27 @@ and a Twitter client using it:
350348
351349
.. code-block:: php
352350
351+
use Acme\Rot13Transformer;
352+
use Acme\TransformerInterface;
353+
use Acme\TwitterClient;
354+
use Acme\UppercaseTransformer;
353355
use Symfony\Component\DependencyInjection\Reference;
354356
use Symfony\Component\DependencyInjection\Definition;
355357
356358
// ...
357-
$rot13Definition = new Definition('Acme\Rot13Transformer');
358-
$rot13Definition->setAutowiringTypes(array('Acme\TransformerInterface'));
359+
$rot13Definition = new Definition(Rot13Transformer::class);
360+
$rot13Definition->setAutowiringTypes(array(TransformerInterface::class));
359361
$container->setDefinition('rot13_transformer', $rot13Definition);
360362
361-
$clientDefinition = new Definition('Acme\TwitterClient');
363+
$clientDefinition = new Definition(TwitterClient::class);
362364
$clientDefinition->setAutowired(true);
363365
$container->setDefinition('twitter_client', $clientDefinition);
364366
365-
$uppercaseDefinition = new Definition('Acme\UppercaseTransformer');
367+
$uppercaseDefinition = new Definition(UppercaseTransformer::class);
366368
$uppercaseDefinition->setAutowired(true);
367369
$container->setDefinition('uppercase_transformer', $uppercaseDefinition);
368370
369-
$uppercaseClientDefinition = new Definition('Acme\TwitterClient', array(
371+
$uppercaseClientDefinition = new Definition(TwitterClient::class, array(
370372
new Reference('uppercase_transformer'),
371373
));
372374
$container->setDefinition('uppercase_twitter_client', $uppercaseClientDefinition);

components/event_dispatcher.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,27 +201,28 @@ determine which instance is passed.
201201
use Symfony\Component\DependencyInjection\Definition;
202202
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
203203
use Symfony\Component\DependencyInjection\Reference;
204+
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
204205
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
205206

206207
$containerBuilder = new ContainerBuilder(new ParameterBag());
207208
$containerBuilder->addCompilerPass(new RegisterListenersPass());
208209

209210
// register the event dispatcher service
210211
$containerBuilder->setDefinition('event_dispatcher', new Definition(
211-
'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher',
212+
ContainerAwareEventDispatcher::class,
212213
array(new Reference('service_container'))
213214
));
214215

215216
// register your event listener service
216-
$listener = new Definition('AcmeListener');
217+
$listener = new Definition(\AcmeListener::class);
217218
$listener->addTag('kernel.event_listener', array(
218219
'event' => 'foo.action',
219220
'method' => 'onFooAction',
220221
));
221222
$containerBuilder->setDefinition('listener_service_id', $listener);
222223

223224
// register an event subscriber
224-
$subscriber = new Definition('AcmeSubscriber');
225+
$subscriber = new Definition(\AcmeSubscriber::class);
225226
$subscriber->addTag('kernel.event_subscriber');
226227
$containerBuilder->setDefinition('subscriber_service_id', $subscriber);
227228

0 commit comments

Comments
 (0)