Skip to content

Updated the console/* articles to Symfony 4 #8748

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

Merged
merged 3 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions _build/redirection_map
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
/components/var_dumper/index /components/var_dumper
/components/yaml/introduction /components/yaml
/components/yaml/index /components/yaml
/console/logging /console
/deployment/tools /deployment
/install/bundles /setup/bundles
/event_dispatcher/class_extension /event_dispatcher
Expand Down
4 changes: 2 additions & 2 deletions console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ Getting Services from the Service Container
To actually create a new user, the command has to access to some
:doc:`services </service_container>`. Since your command is already registered
as a service, you can use normal dependency injection. Imagine you have a
``AppBundle\Service\UserManager`` service that you want to access::
``App\Service\UserManager`` service that you want to access::

// ...
use Symfony\Component\Console\Command\Command;
use AppBundle\Service\UserManager;
use App\Service\UserManager;

class CreateUserCommand extends Command
{
Expand Down
2 changes: 1 addition & 1 deletion console/calling_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ user to remember the order of execution, you can call it directly yourself.
This is also useful if you want to create a "meta" command that just runs a
bunch of other commands (for instance, all commands that need to be run when
the project's code has changed on the production servers: clearing the cache,
generating Doctrine2 proxies, dumping Assetic assets, ...).
generating Doctrine2 proxies, dumping web assets, ...).

Calling a command from another one is straightforward::

Expand Down
4 changes: 2 additions & 2 deletions console/coloring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ It is possible to define your own styles using the
$style = new OutputFormatterStyle('red', 'yellow', array('bold', 'blink'));
$output->getFormatter()->setStyle('fire', $style);

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

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

You can also set these colors and options directly inside the tagname::
You can also set these colors and options directly inside the tag name::

// green text
$output->writeln('<fg=green>foo</>');
Expand Down
7 changes: 3 additions & 4 deletions console/commands_as_services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,32 @@ Or set the ``command`` attribute on the ``console.command`` tag in your service

.. code-block:: yaml

# config/services.yaml
services:

App\Command\SunshineCommand:
tags:
- { name: 'console.command', command: 'app:sunshine' }
# ...

.. code-block:: xml

<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>

<service id="App\Command\SunshineCommand">
<tag name="console.command" command="app:sunshine" />
</service>

</services>
</container>

.. code-block:: php

// config/services.php
use App\Command\SunshineCommand;

//...

$container
Expand Down
5 changes: 2 additions & 3 deletions console/lockable_trait.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ Prevent Multiple Executions of a Console Command
================================================

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

In addition, the Console component provides a PHP trait called ``LockableTrait``
that adds two convenient methods to lock and release commands::
Expand Down
15 changes: 0 additions & 15 deletions console/logging.rst

This file was deleted.

48 changes: 28 additions & 20 deletions console/request_context.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Configuring the Request Context Globally

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

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

.. code-block:: yaml

# app/config/parameters.yml
# config/services.yaml
parameters:
router.request_context.host: example.org
router.request_context.scheme: https
router.request_context.base_url: my/path

.. code-block:: xml

<!-- app/config/parameters.xml -->
<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Expand All @@ -54,29 +54,37 @@ will override the defaults.

.. code-block:: php

// app/config/parameters.php
// config/services.php
$container->setParameter('router.request_context.host', 'example.org');
$container->setParameter('router.request_context.scheme', 'https');
$container->setParameter('router.request_context.base_url', 'my/path');

Configuring the Request Context per Command
-------------------------------------------

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

// src/Command/DemoCommand.php
// src/Command/DemoCommand.php
use Symfony\Component\Routing\RouterInterface;
// ...

// ...
class DemoCommand extends ContainerAwareCommand
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$context = $this->getContainer()->get('router')->getContext();
$context->setHost('example.com');
$context->setScheme('https');
$context->setBaseUrl('my/path');
class DemoCommand extends ContainerAwareCommand
{
private $router;

// ... your code here
}
}
public function __construct(RouterInterface $router)
{
$this->router = $router;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$context = $this->router->getContext();
$context->setHost('example.com');
$context->setScheme('https');
$context->setBaseUrl('my/path');

// ... your code here
}
}
31 changes: 10 additions & 21 deletions console/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,13 @@ The :doc:`/components/console/usage` page of the components documentation looks
at the global console options. When you use the console as part of the full-stack
framework, some additional global options are available as well.

By default, console commands run in the ``dev`` environment and you may want to
change this for some commands. For example, you may want to run some commands in
the ``prod`` environment for performance reasons. Also, the result of some
commands will be different depending on the environment. For example, the
``cache:clear`` command will clear the cache for the specified environment only.
To clear the ``prod`` cache you need to run:

.. code-block:: terminal

$ php bin/console cache:clear --no-warmup --env=prod

# this is equivalent:
$ php bin/console cache:clear --no-warmup -e prod

In addition to changing the environment, you can also choose to disable debug mode.
This can be useful where you want to run commands in the ``dev`` environment
but avoid the performance hit of collecting debug data:

.. code-block:: terminal

$ php bin/console list --no-debug
Console commands run in the environment defined in the ``APP_ENV`` variable of
the ``.env`` file, which is ``dev`` by default. The result of some commands will
be different depending on the environment (e.g. the ``cache:clear`` command
clears the cache for the given environment only). To run the command in other
environment, edit the value of ``APP_ENV``.

In addition to changing the environment, you can also choose to disable debug
mode. This can be useful where you want to run commands in the ``dev``
environment but avoid the performance hit of collecting debug data. To do that,
set the value of the ``APP_DEBUG`` env var to ``0`` in the same ``.env`` file.
7 changes: 0 additions & 7 deletions console/verbosity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ verbosity levels::
// ...
}

.. note::

These semantic methods are defined in the ``OutputInterface`` starting from
Symfony 3.0. In previous Symfony versions they are defined in the different
implementations of the interface (e.g. :class:`Symfony\\Component\\Console\\Output\\Output`)
in order to keep backward compatibility.

When the quiet level is used, all output is suppressed as the default
:method:`Symfony\\Component\\Console\\Output\\Output::write` method returns
without actually printing.
Expand Down