77namespace Magento \Developer \Console \Command ;
88
99use Magento \Developer \Model \Di \Information ;
10+ use Magento \Framework \App \ObjectManager ;
1011use Symfony \Component \Console \Command \Command ;
1112use Symfony \Component \Console \Exception \InvalidArgumentException ;
1213use Symfony \Component \Console \Input \InputInterface ;
1314use Symfony \Component \Console \Output \OutputInterface ;
1415use Symfony \Component \Console \Input \InputArgument ;
1516use Symfony \Component \Console \Helper \Table ;
17+ use Magento \Framework \App \AreaList ;
1618
1719class DiInfoCommand extends Command
1820{
19- /**
20- * Command name
21- */
22- const COMMAND_NAME = 'dev:di:info ' ;
21+ public const COMMAND_NAME = 'dev:di:info ' ;
22+
23+ public const CLASS_NAME = 'class ' ;
24+
25+ public const AREA_CODE = 'area ' ;
2326
2427 /**
25- * input name
28+ * @var Information
2629 */
27- const CLASS_NAME = ' class ' ;
30+ private Information $ diInformation ;
2831
2932 /**
30- * @var Information
33+ * @var AreaList
3134 */
32- private $ diInformation ;
35+ private AreaList $ areaList ;
3336
3437 /**
3538 * @param Information $diInformation
39+ * @param AreaList $areaList
3640 */
3741 public function __construct (
38- Information $ diInformation
42+ Information $ diInformation ,
43+ AreaList $ areaList
3944 ) {
45+ $ this ->areaList = $ areaList ;
4046 $ this ->diInformation = $ diInformation ;
4147 parent ::__construct ();
4248 }
4349
4450 /**
45- * {@inheritdoc}
51+ * @inheritdoc
52+ *
4653 * @throws InvalidArgumentException
4754 */
4855 protected function configure ()
4956 {
5057 $ this ->setName (self ::COMMAND_NAME )
51- ->setDescription ('Provides information on Dependency Injection configuration for the Command. ' )
52- ->setDefinition ([
53- new InputArgument (self ::CLASS_NAME , InputArgument::REQUIRED , 'Class name ' )
54- ]);
58+ ->setDescription ('Provides information on Dependency Injection configuration for the Command. ' )
59+ ->setDefinition ([
60+ new InputArgument (self ::CLASS_NAME , InputArgument::REQUIRED , 'Class name ' ),
61+ new InputArgument (self ::AREA_CODE , InputArgument::OPTIONAL , 'Area Code ' )
62+ ]);
5563
5664 parent ::configure ();
5765 }
@@ -146,15 +154,19 @@ private function printPlugins($className, $output, $label)
146154 }
147155
148156 /**
149- * { @inheritdoc}
157+ * @inheritdoc
150158 * @throws \InvalidArgumentException
151159 */
152160 protected function execute (InputInterface $ input , OutputInterface $ output )
153161 {
162+ $ area = 'GLOBAL ' ;
163+ if ($ area = $ input ->getArgument (self ::AREA_CODE )) {
164+ $ this ->setDiArea ($ area );
165+ }
154166 $ className = $ input ->getArgument (self ::CLASS_NAME );
155167 $ output ->setDecorated (true );
156168 $ output ->writeln ('' );
157- $ output ->writeln (sprintf ('DI configuration for the class %s in the GLOBAL area ' , $ className ));
169+ $ output ->writeln (sprintf ('DI configuration for the class %s in the %s area ' , $ className, strtoupper ( $ area ) ));
158170
159171 if ($ this ->diInformation ->isVirtualType ($ className )) {
160172 $ output ->writeln (
@@ -170,4 +182,40 @@ protected function execute(InputInterface $input, OutputInterface $output)
170182
171183 return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
172184 }
185+
186+ /**
187+ * Set Area for DI Configuration
188+ *
189+ * @param string $area
190+ * @return void
191+ * @throws \InvalidArgumentException
192+ */
193+ private function setDiArea ($ area )
194+ {
195+ if ($ this ->validateAreaCodeFromInput ($ area )) {
196+ $ objectManager = ObjectManager::getInstance ();
197+
198+ $ objectManager ->configure (
199+ $ objectManager
200+ ->get (\Magento \Framework \App \ObjectManager \ConfigLoader::class)
201+ ->load ($ area )
202+ );
203+ $ objectManager ->get (\Magento \Framework \Config \ScopeInterface::class)
204+ ->setCurrentScope ($ area );
205+ } else {
206+ throw new InvalidArgumentException (sprintf ('The "%s" area code does not exist ' , $ area ));
207+ }
208+ }
209+
210+ /**
211+ * Validate Input
212+ *
213+ * @param string $area
214+ * @return bool
215+ */
216+ private function validateAreaCodeFromInput ($ area )
217+ {
218+ $ availableAreaCodes = $ this ->areaList ->getCodes ();
219+ return in_array ($ area , $ availableAreaCodes , true );
220+ }
173221}
0 commit comments