Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 2 commits intosymfony:masterfromchalasr:rm-ct-aware-cmd-refs
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionsconsole/commands_as_services.rst
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 deletionsconsole/style.rst
View file
Open in desktop
Original file line numberDiff line numberDiff 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 extendsContainerAwareCommand
class GreetCommand extendsCommand
{
// ...

Expand DownExpand 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 extendsContainerAwareCommand
class GreetCommand extendsCommand
{
// ...

Expand DownExpand 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 extendsContainerAwareCommand
class GreetCommand extendsCommand
{
// ...

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp