Skip to content

Commit 674348b

Browse files
committed
Merge branch '4.0'
* 4.0: Added a short section about registering commands Use create-project instead of require to create reproducer project Explain which branch to select for Pull Requests Removed some wrong mentions to AppBundle Better explain how to inject mailers different than the default one Missing the obvious <?php SF 4+ does not rely on Command inheritance anymore Update email field length in annotation Update upload_file.rst Clarify Symfony Console option conventions Clarify how to use short options with values. Use the long array syntax the bundle no longer recommend for Sf4 Fixes deprecated ProcessBuilder usage
2 parents fbfd51b + 1ef3db3 commit 674348b

File tree

14 files changed

+119
-40
lines changed

14 files changed

+119
-40
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--
2+
3+
If your pull request fixes a BUG, use the oldest maintained branch that contains
4+
the bug (see https://symfony.com/roadmap for the list of maintained branches).
5+
6+
If your pull request documents a NEW FEATURE, use the same Symfony branch where
7+
the feature was introduced (and `master` for features of unreleased versions).
8+
9+
-->

components/console/helpers/processhelper.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ a very verbose verbosity (e.g. -vv)::
1414
use Symfony\Component\Process\ProcessBuilder;
1515

1616
$helper = $this->getHelper('process');
17-
$process = ProcessBuilder::create(array('figlet', 'Symfony'))->getProcess();
17+
$process = new Process(array('figlet', 'Symfony'));
1818

1919
$helper->run($output, $process);
2020

@@ -55,7 +55,7 @@ There are three ways to use the process helper:
5555
use Symfony\Component\Process\ProcessBuilder;
5656

5757
// ...
58-
$process = ProcessBuilder::create(array('figlet', 'Symfony'))->getProcess();
58+
$process = new Process(array('figlet', 'Symfony'));
5959

6060
$helper->run($output, $process);
6161

console.rst

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,23 @@ method. Then you can optionally define a help message and the
6969
;
7070
}
7171

72+
Registering the Command
73+
-----------------------
74+
75+
Symfony commands must be registered as services and :doc:`tagged </service_container/tags>`
76+
with the ``console.command`` tag. If you're using the
77+
:ref:`default services.yaml configuration <service-container-services-load-example>`,
78+
this is already done for you, thanks to :ref:`autoconfiguration <services-autoconfigure>`.
79+
7280
Executing the Command
7381
---------------------
7482

75-
Symfony registers any PHP class extending :class:`Symfony\\Component\\Console\\Command\\Command`
76-
as a console command automatically. So you can now execute this command in the
77-
terminal:
83+
After configuring and registering the command, you can execute it in the terminal:
7884

7985
.. code-block:: terminal
8086
8187
$ php bin/console app:create-user
8288
83-
.. note::
84-
85-
If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`,
86-
your command classes are automatically registered as services.
87-
88-
You can also manually register your command as a service by configuring the service
89-
and :doc:`tagging it </service_container/tags>` with ``console.command``.
90-
9189
As you might expect, this command will do nothing as you didn't write any logic
9290
yet. Add your own logic inside the ``execute()`` method, which has access to the
9391
input stream (e.g. options and arguments) and the output stream (to write

console/input.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ flag:
174174
1
175175
);
176176

177+
Note that to comply with the `docopt standard`_, long options can specify their
178+
values after a white space or an ``=`` sign (e.g. ``--iterations 5`` or
179+
``--iterations=5``), but short options can only use white spaces or no
180+
separation at all (e.g. ``-i 5`` or ``-i5``).
181+
177182
There are four option variants you can use:
178183

179184
``InputOption::VALUE_IS_ARRAY``
@@ -184,8 +189,8 @@ There are four option variants you can use:
184189
behavior of options;
185190

186191
``InputOption::VALUE_REQUIRED``
187-
This value is required (e.g. ``--iterations=5``), the option itself is
188-
still optional;
192+
This value is required (e.g. ``--iterations=5`` or ``-i5``), the option
193+
itself is still optional;
189194

190195
``InputOption::VALUE_OPTIONAL``
191196
This option may or may not have a value (e.g. ``--yell`` or
@@ -211,3 +216,14 @@ You can combine ``VALUE_IS_ARRAY`` with ``VALUE_REQUIRED`` or
211216
when the option was used without a value (``command --language``) or when
212217
it wasn't used at all (``command``). In both cases, the value retrieved for
213218
the option will be ``null``.
219+
220+
.. caution::
221+
222+
While it is possible to separate an option from its value with a white space,
223+
using this form leads to an ambiguity should the option appear before the
224+
command name. For example, ``php bin/console --iterations 5 app:greet Fabien``
225+
is ambiguous; Symfony would interpret ``5`` as the command name. To avoid
226+
this situation, always place options after the command name, or avoid using
227+
a space to separate the option name from its value.
228+
229+
.. _`docopt standard`: http://docopt.org/

contributing/code/reproducer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ a PHP script, it's better to reproduce the bug by creating a new project. To do
3939

4040
.. code-block:: terminal
4141
42-
$ composer require symfony/skeleton bug_app
42+
$ composer create-project symfony/skeleton bug_app
4343
4444
2. Now you must add the minimum amount of code to reproduce the bug. This is the
4545
trickiest part and it's explained a bit more later.

controller/upload_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ Then, define a service for this class:
271271
272272
App\Service\FileUploader:
273273
arguments:
274-
$targetDir: '%brochures_directory%'
274+
$targetDirectory: '%brochures_directory%'
275275
276276
.. code-block:: xml
277277

event_dispatcher.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ using a special "tag":
9191
http://symfony.com/schema/dic/services/services-1.0.xsd">
9292
9393
<services>
94-
<service id="AppBundle\EventListener\ExceptionListener">
94+
<service id="App\EventListener\ExceptionListener">
9595
<tag name="kernel.event_listener" event="kernel.exception" />
9696
</service>
9797
</services>

http_cache/esi.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ matter), Symfony uses the standard ``render`` helper to configure ESI tags:
139139
<!-- you can use a controller reference -->
140140
<?php echo $view['actions']->render(
141141
new Symfony\Component\HttpKernel\Controller\ControllerReference(
142-
'AppBundle:News:latest',
142+
'App\Controller\NewsController::latest',
143143
array('maxPerPage' => 5)
144144
),
145145
array('strategy' => 'esi')

page_creation.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Suppose you want to create a page - ``/lucky/number`` - that generates a lucky (
4343
random) number and prints it. To do that, create a "Controller class" and a
4444
"controller" method inside of it::
4545

46+
<?php
4647
// src/Controller/LuckyController.php
4748
namespace App\Controller;
4849

@@ -281,7 +282,7 @@ project:
281282

282283
``src/``
283284
All your PHP code lives here.
284-
285+
285286
``templates/``
286287
All your Twig templates live here.
287288

reference/configuration/swiftmailer.rst

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ key (the default mailer is identified by the ``default_mailer`` option):
344344
),
345345
));
346346
347-
Each mailer is registered as a service::
347+
Each mailer is registered automatically as a service with these IDs::
348348

349349
// ...
350350

@@ -362,3 +362,70 @@ Each mailer is registered as a service::
362362
When configuring multiple mailers, options must be placed under the
363363
appropriate mailer key of the configuration instead of directly under the
364364
``swiftmailer`` key.
365+
366+
When using :ref:`autowiring <services-autowire>` only the default mailer is
367+
injected when type-hinting some argument with the ``\Swift_Mailer`` class. If
368+
you need to inject a different mailer in some service, use any of these
369+
alternatives based on the :ref:`service binding <services-binding>` feature:
370+
371+
.. configuration-block::
372+
373+
.. code-block:: yaml
374+
375+
# config/services.yaml
376+
services:
377+
_defaults:
378+
bind:
379+
# this injects the second mailer when type-hinting constructor arguments with \Swift_Mailer
380+
\Swift_Mailer: '@swiftmailer.mailer.second_mailer'
381+
# this injects the second mailer when a service constructor argument is called $specialMailer
382+
$specialMailer: '@swiftmailer.mailer.second_mailer'
383+
384+
App\Some\Service:
385+
# this injects the second mailer only for this argument of this service
386+
$differentMailer: '@swiftmailer.mailer.second_mailer'
387+
388+
# ...
389+
390+
.. code-block:: xml
391+
392+
<!-- config/services.xml -->
393+
<?xml version="1.0" encoding="UTF-8" ?>
394+
<container xmlns="http://symfony.com/schema/dic/services"
395+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
396+
xsi:schemaLocation="http://symfony.com/schema/dic/services
397+
http://symfony.com/schema/dic/services/services-1.0.xsd">
398+
399+
<services>
400+
<defaults autowire="true" autoconfigure="true" public="false">
401+
<!-- this injects the second mailer when type-hinting constructor arguments with \Swift_Mailer -->
402+
<bind key="\Swift_Mailer">@swiftmailer.mailer.second_mailer</bind>
403+
<!-- this injects the second mailer when a service constructor argument is called $specialMailer -->
404+
<bind key="$specialMailer">@swiftmailer.mailer.second_mailer</bind>
405+
</defaults>
406+
407+
<service id="App\Some\Service">
408+
<!-- this injects the second mailer only for this argument of this service -->
409+
<argument key="$differentMailer">@swiftmailer.mailer.second_mailer</argument>
410+
</service>
411+
412+
<!-- ... -->
413+
</services>
414+
</container>
415+
416+
.. code-block:: php
417+
418+
// config/services.php
419+
use App\Some\Service;
420+
use Symfony\Component\DependencyInjection\Reference;
421+
use Psr\Log\LoggerInterface;
422+
423+
$container->register(Service::class)
424+
->setPublic(true)
425+
->setBindings(array(
426+
// this injects the second mailer when this service type-hints constructor arguments with \Swift_Mailer
427+
\Swift_Mailer => '@swiftmailer.mailer.second_mailer',
428+
// this injects the second mailer when this service has a constructor argument called $specialMailer
429+
'$specialMailer' => '@swiftmailer.mailer.second_mailer',
430+
))
431+
;

security/entity_provider.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ with the following fields: ``id``, ``username``, ``password``,
6767
private $password;
6868

6969
/**
70-
* @ORM\Column(type="string", length=60, unique=true)
70+
* @ORM\Column(type="string", length=254, unique=true)
7171
*/
7272
private $email;
7373

security/securing_services.rst

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,3 @@ thanks to autowiring and the ``AuthorizationCheckerInterface`` type-hint.
8181

8282
If the current user does not have the ``ROLE_NEWSLETTER_ADMIN``, they will
8383
be prompted to log in.
84-
85-
Securing Methods Using Annotations
86-
----------------------------------
87-
88-
You can also secure method calls in any service with annotations by using the
89-
optional `JMSSecurityExtraBundle`_ bundle. This bundle is not included in the
90-
Symfony Standard Distribution, but you can choose to install it.
91-
92-
See the `JMSSecurityExtraBundle Documentation`_ for more details.
93-
94-
.. _`JMSSecurityExtraBundle`: https://github.com/schmittjoh/JMSSecurityExtraBundle
95-
.. _`JMSSecurityExtraBundle Documentation`: http://jmsyst.com/bundles/JMSSecurityExtraBundle

service_container/factories.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Configuration of the service container then looks like this:
152152
.. code-block:: yaml
153153
154154
# config/services.yaml
155-
AppBundle\Email\NewsletterManager:
155+
App\Email\NewsletterManager:
156156
# new syntax
157157
factory: 'App\Email\NewsletterManagerFactory:createNewsletterManager'
158158
# old syntax

templating/twig_extension.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ implementation. Following the same example as before, the first change would be
9494
to remove the ``priceFilter()`` method from the extension and update the PHP
9595
callable defined in ``getFilters()``::
9696

97-
// src/AppBundle/Twig/AppExtension.php
98-
namespace AppBundle\Twig;
97+
// src/Twig/AppExtension.php
98+
namespace App\Twig;
9999

100-
use AppBundle\Twig\AppRuntime;
100+
use App\Twig\AppRuntime;
101101

102102
class AppExtension extends \Twig_Extension
103103
{
@@ -114,8 +114,8 @@ Then, create the new ``AppRuntime`` class (it's not required but these classes
114114
are suffixed with ``Runtime`` by convention) and include the logic of the
115115
previous ``priceFilter()`` method::
116116

117-
// src/AppBundle/Twig/AppRuntime.php
118-
namespace AppBundle\Twig;
117+
// src/Twig/AppRuntime.php
118+
namespace App\Twig;
119119

120120
class AppRuntime
121121
{

0 commit comments

Comments
 (0)