Skip to content

Commit 444a49a

Browse files
committed
minor #8748 Updated the console/* articles to Symfony 4 (javiereguiluz)
This PR was squashed before being merged into the 4.0 branch (closes #8748). Discussion ---------- Updated the console/* articles to Symfony 4 Commits ------- fcb4ac0 Update the main console article too 88e0f1d Don't mention the deprecated LockHandler utility e44f622 Updated the console/* articles to Symfony 4
2 parents e126bbe + fcb4ac0 commit 444a49a

10 files changed

+49
-75
lines changed

_build/redirection_map

+1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@
358358
/components/var_dumper/index /components/var_dumper
359359
/components/yaml/introduction /components/yaml
360360
/components/yaml/index /components/yaml
361+
/console/logging /console
361362
/deployment/tools /deployment
362363
/install/bundles /setup/bundles
363364
/event_dispatcher/class_extension /event_dispatcher

console.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ Getting Services from the Service Container
163163
To actually create a new user, the command has to access to some
164164
:doc:`services </service_container>`. Since your command is already registered
165165
as a service, you can use normal dependency injection. Imagine you have a
166-
``AppBundle\Service\UserManager`` service that you want to access::
166+
``App\Service\UserManager`` service that you want to access::
167167

168168
// ...
169169
use Symfony\Component\Console\Command\Command;
170-
use AppBundle\Service\UserManager;
170+
use App\Service\UserManager;
171171

172172
class CreateUserCommand extends Command
173173
{

console/calling_commands.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ user to remember the order of execution, you can call it directly yourself.
66
This is also useful if you want to create a "meta" command that just runs a
77
bunch of other commands (for instance, all commands that need to be run when
88
the project's code has changed on the production servers: clearing the cache,
9-
generating Doctrine2 proxies, dumping Assetic assets, ...).
9+
generating Doctrine2 proxies, dumping web assets, ...).
1010

1111
Calling a command from another one is straightforward::
1212

console/coloring.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ It is possible to define your own styles using the
4343
$style = new OutputFormatterStyle('red', 'yellow', array('bold', 'blink'));
4444
$output->getFormatter()->setStyle('fire', $style);
4545

46-
$output->writeln('<fire>foo</fire>');
46+
$output->writeln('<fire>foo</>');
4747

4848
Available foreground and background colors are: ``black``, ``red``, ``green``,
4949
``yellow``, ``blue``, ``magenta``, ``cyan`` and ``white``.
@@ -54,7 +54,7 @@ are swapped) and ``conceal`` (sets the foreground color to transparent, making
5454
the typed text invisible - although it can be selected and copied; this option is
5555
commonly used when asking the user to type sensitive information).
5656

57-
You can also set these colors and options directly inside the tagname::
57+
You can also set these colors and options directly inside the tag name::
5858

5959
// green text
6060
$output->writeln('<fg=green>foo</>');

console/commands_as_services.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -86,33 +86,32 @@ Or set the ``command`` attribute on the ``console.command`` tag in your service
8686

8787
.. code-block:: yaml
8888
89+
# config/services.yaml
8990
services:
90-
9191
App\Command\SunshineCommand:
9292
tags:
9393
- { name: 'console.command', command: 'app:sunshine' }
9494
# ...
9595
9696
.. code-block:: xml
9797
98+
<!-- config/services.xml -->
9899
<?xml version="1.0" encoding="UTF-8" ?>
99100
<container xmlns="http://symfony.com/schema/dic/services"
100101
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
101102
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
102103
103104
<services>
104-
105105
<service id="App\Command\SunshineCommand">
106106
<tag name="console.command" command="app:sunshine" />
107107
</service>
108-
109108
</services>
110109
</container>
111110
112111
.. code-block:: php
113112
113+
// config/services.php
114114
use App\Command\SunshineCommand;
115-
116115
//...
117116
118117
$container

console/lockable_trait.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ Prevent Multiple Executions of a Console Command
22
================================================
33

44
A simple but effective way to prevent multiple executions of the same command in
5-
a single server is to use **file locks**. The Filesystem component provides a
6-
:doc:`LockHandler </components/filesystem/lock_handler>` class that eases the
7-
creation and release of these locks.
5+
a single server is to use **file locks**. The Lock component eases the creation
6+
and release of these locks.
87

98
In addition, the Console component provides a PHP trait called ``LockableTrait``
109
that adds two convenient methods to lock and release commands::

console/logging.rst

-15
This file was deleted.

console/request_context.rst

+28-20
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Configuring the Request Context Globally
2121

2222
To configure the Request Context - which is used by the URL Generator - you can
2323
redefine the parameters it uses as default values to change the default host
24-
(localhost) and scheme (http). You can also configure the base path if Symfony
25-
is not running in the root directory.
24+
(``localhost``) and scheme (``http``). You can also configure the base path if
25+
Symfony is not running in the root directory.
2626

2727
Note that this does not impact URLs generated via normal web requests, since those
2828
will override the defaults.
@@ -31,15 +31,15 @@ will override the defaults.
3131

3232
.. code-block:: yaml
3333
34-
# app/config/parameters.yml
34+
# config/services.yaml
3535
parameters:
3636
router.request_context.host: example.org
3737
router.request_context.scheme: https
3838
router.request_context.base_url: my/path
3939
4040
.. code-block:: xml
4141
42-
<!-- app/config/parameters.xml -->
42+
<!-- config/services.xml -->
4343
<?xml version="1.0" encoding="UTF-8"?>
4444
<container xmlns="http://symfony.com/schema/dic/services"
4545
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
@@ -54,29 +54,37 @@ will override the defaults.
5454
5555
.. code-block:: php
5656
57-
// app/config/parameters.php
57+
// config/services.php
5858
$container->setParameter('router.request_context.host', 'example.org');
5959
$container->setParameter('router.request_context.scheme', 'https');
6060
$container->setParameter('router.request_context.base_url', 'my/path');
6161
6262
Configuring the Request Context per Command
6363
-------------------------------------------
6464

65-
To change it only in one command you can simply fetch the Request Context
66-
from the ``router`` service and override its settings::
65+
To change it only in one command you can fetch the Request Context from the
66+
router service and override its settings::
6767

68-
// src/Command/DemoCommand.php
68+
// src/Command/DemoCommand.php
69+
use Symfony\Component\Routing\RouterInterface;
70+
// ...
6971

70-
// ...
71-
class DemoCommand extends ContainerAwareCommand
72-
{
73-
protected function execute(InputInterface $input, OutputInterface $output)
74-
{
75-
$context = $this->getContainer()->get('router')->getContext();
76-
$context->setHost('example.com');
77-
$context->setScheme('https');
78-
$context->setBaseUrl('my/path');
72+
class DemoCommand extends ContainerAwareCommand
73+
{
74+
private $router;
7975

80-
// ... your code here
81-
}
82-
}
76+
public function __construct(RouterInterface $router)
77+
{
78+
$this->router = $router;
79+
}
80+
81+
protected function execute(InputInterface $input, OutputInterface $output)
82+
{
83+
$context = $this->router->getContext();
84+
$context->setHost('example.com');
85+
$context->setScheme('https');
86+
$context->setBaseUrl('my/path');
87+
88+
// ... your code here
89+
}
90+
}

console/usage.rst

+10-21
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,13 @@ The :doc:`/components/console/usage` page of the components documentation looks
88
at the global console options. When you use the console as part of the full-stack
99
framework, some additional global options are available as well.
1010

11-
By default, console commands run in the ``dev`` environment and you may want to
12-
change this for some commands. For example, you may want to run some commands in
13-
the ``prod`` environment for performance reasons. Also, the result of some
14-
commands will be different depending on the environment. For example, the
15-
``cache:clear`` command will clear the cache for the specified environment only.
16-
To clear the ``prod`` cache you need to run:
17-
18-
.. code-block:: terminal
19-
20-
$ php bin/console cache:clear --no-warmup --env=prod
21-
22-
# this is equivalent:
23-
$ php bin/console cache:clear --no-warmup -e prod
24-
25-
In addition to changing the environment, you can also choose to disable debug mode.
26-
This can be useful where you want to run commands in the ``dev`` environment
27-
but avoid the performance hit of collecting debug data:
28-
29-
.. code-block:: terminal
30-
31-
$ php bin/console list --no-debug
11+
Console commands run in the environment defined in the ``APP_ENV`` variable of
12+
the ``.env`` file, which is ``dev`` by default. The result of some commands will
13+
be different depending on the environment (e.g. the ``cache:clear`` command
14+
clears the cache for the given environment only). To run the command in other
15+
environment, edit the value of ``APP_ENV``.
16+
17+
In addition to changing the environment, you can also choose to disable debug
18+
mode. This can be useful where you want to run commands in the ``dev``
19+
environment but avoid the performance hit of collecting debug data. To do that,
20+
set the value of the ``APP_DEBUG`` env var to ``0`` in the same ``.env`` file.

console/verbosity.rst

-7
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ verbosity levels::
6363
// ...
6464
}
6565

66-
.. note::
67-
68-
These semantic methods are defined in the ``OutputInterface`` starting from
69-
Symfony 3.0. In previous Symfony versions they are defined in the different
70-
implementations of the interface (e.g. :class:`Symfony\\Component\\Console\\Output\\Output`)
71-
in order to keep backward compatibility.
72-
7366
When the quiet level is used, all output is suppressed as the default
7467
:method:`Symfony\\Component\\Console\\Output\\Output::write` method returns
7568
without actually printing.

0 commit comments

Comments
 (0)