Skip to content

[Console] Remove mentions about the deprecated ContainerAwareCommand #10307

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 2 commits into from
Sep 10, 2018
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
13 changes: 7 additions & 6 deletions console/commands_as_services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ recommended setup.
You can also manually register your command as a service by configuring the service
and :doc:`tagging it </service_container/tags>` with ``console.command``.

In either case, if your class extends :class:`Symfony\\Bundle\\FrameworkBundle\\Command\\ContainerAwareCommand`,
you can access public services via ``$this->getContainer()->get('SERVICE_ID')``.

But if your class is registered as a service, you can instead access services by
using normal :ref:`dependency injection <services-constructor-injection>`.

For example, suppose you want to log something from within your command::

namespace App\Command;
Expand Down Expand Up @@ -66,6 +60,13 @@ works! You can call the ``app:sunshine`` command and start logging.
work (e.g. making database queries), as that code will be run, even if you're using
the console to execute a different command.

.. note::

In previous Symfony versions, you could make the command class extend from
:class:`Symfony\\Bundle\\FrameworkBundle\\Command\\ContainerAwareCommand` to
get services via ``$this->getContainer()->get('SERVICE_ID')``. This is
deprecated in Symfony 4.2 and it won't work in future Symfony versions.

.. _console-command-service-lazy-loading:

Lazy Loading
Expand Down
11 changes: 6 additions & 5 deletions console/style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Consider for example the code used to display the title of the following command
// src/Command/GreetCommand.php
namespace App\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class GreetCommand extends ContainerAwareCommand
class GreetCommand extends Command
{
// ...

Expand Down Expand Up @@ -53,12 +53,12 @@ title of the command::
// src/Command/GreetCommand.php
namespace App\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class GreetCommand extends ContainerAwareCommand
class GreetCommand extends Command
{
// ...

Expand Down Expand Up @@ -355,10 +355,11 @@ of your commands to change their appearance::
namespace App\Console;

use App\Console\CustomStyle;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class GreetCommand extends ContainerAwareCommand
class GreetCommand extends Command
{
// ...

Expand Down