From f3e8f0e4cf045a275390a35c793c5bb7068322d7 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sun, 9 Sep 2018 19:50:53 +0200 Subject: [PATCH 1/2] [WCM][Console] Remove mentions about the deprecated ContainerAwareCommand class --- console/commands_as_services.rst | 6 ------ console/style.rst | 11 ++++++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/console/commands_as_services.rst b/console/commands_as_services.rst index 0617030bbc0..1dad29b0bdc 100644 --- a/console/commands_as_services.rst +++ b/console/commands_as_services.rst @@ -13,12 +13,6 @@ recommended setup. You can also manually register your command as a service by configuring the service and :doc:`tagging it ` 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 `. - For example, suppose you want to log something from within your command:: namespace App\Command; diff --git a/console/style.rst b/console/style.rst index 9bdcbaf1631..c40dbb9ca18 100644 --- a/console/style.rst +++ b/console/style.rst @@ -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 { // ... @@ -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 { // ... @@ -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 { // ... From 4143835f9da826a1c006ff56b2506826f8848bdc Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 10 Sep 2018 11:16:08 +0200 Subject: [PATCH 2/2] Maintained a note about ContainerAwareCommand being deprecated --- console/commands_as_services.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/console/commands_as_services.rst b/console/commands_as_services.rst index 1dad29b0bdc..2794dc56aac 100644 --- a/console/commands_as_services.rst +++ b/console/commands_as_services.rst @@ -60,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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy