Skip to content

Commit 2dc1954

Browse files
enzolutionsjmolivas
authored andcommitted
Commands in container (#2604)
* [generate:post:update] New Command * Fixed services call as option in some commands * Language separation * Revert "Language separation" This reverts commit e4d45c9. * Register cache commands in Container #1 * Revert "Register cache commands in Container #1" This reverts commit dee0362. * Register chain commands in Container #1 * Register chain commands in Container #2 * Register chain commands in Container #3 * Register chain commands in Container #4 * Register chain commands in Container #5 * Register chain commands in Container #5 * Register chain commands in Container #6 * Register chain commands in Container #7 * Register config commands in Container #1 * Register config commands in Container #2 * Register config commands in Container #3 * Register config commands in Container #4 * Register config commands in Container #5 * Register config commands in Container #6 * Register config commands in Container #7 * Register config commands in Container #8 * Register config commands in Container #9 * Register config commands in Container #10 * Register config commands in Container #11 * Register config commands in Container #12 * Register config commands in Container #13 * Register config commands in Container #15
1 parent 25066a2 commit 2dc1954

File tree

11 files changed

+202
-92
lines changed

11 files changed

+202
-92
lines changed

config/services/chain.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#services:
2-
# chain:
3-
# class: Drupal\Console\Command\Chain\ChainCommand
4-
# tags:
5-
# - { name: console.command }
6-
# chain_debug:
7-
# class: Drupal\Console\Command\Chain\ChainDebugCommand
8-
# tags:
9-
# - { name: console.command }
1+
services:
2+
chain:
3+
class: Drupal\Console\Command\Chain\ChainCommand
4+
arguments: ['@console.file_util', '@console.chain_queue', '@console.configuration_manager', '@app.root']
5+
tags:
6+
- { name: console.command }
7+
chain_debug:
8+
class: Drupal\Console\Command\Chain\ChainDebugCommand
9+
tags:
10+
- { name: console.command }

config/services/config.yml

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
1-
#services:
2-
# config_debug:
3-
# class: Drupal\Console\Command\Config\DebugCommand
4-
# tags:
5-
# - { name: console.command }
6-
# config_delete:
7-
# class: Drupal\Console\Command\Config\DeleteCommand
8-
# tags:
9-
# - { name: console.command }
10-
# config_diff:
11-
# class: Drupal\Console\Command\Config\DiffCommand
12-
# tags:
13-
# - { name: console.command }
14-
# config_edit:
15-
# class: Drupal\Console\Command\Config\EditCommand
16-
# tags:
17-
# - { name: console.command }
18-
# config_export:
19-
# class: Drupal\Console\Command\Config\ExportCommand
20-
# tags:
21-
# - { name: console.command }
22-
# config_export_content_type:
23-
# class: Drupal\Console\Command\Config\ExportContentTypeCommand
24-
# tags:
25-
# - { name: console.command }
1+
services:
2+
config_debug:
3+
class: Drupal\Console\Command\Config\DebugCommand
4+
arguments: ['@config.factory', '@config.storage']
5+
tags:
6+
- { name: console.command }
7+
config_delete:
8+
class: Drupal\Console\Command\Config\DeleteCommand
9+
arguments: ['@config.factory', '@config.storage', '@config.storage.sync']
10+
tags:
11+
- { name: console.command }
12+
config_diff:
13+
class: Drupal\Console\Command\Config\DiffCommand
14+
arguments: ['@config.storage', '@config.manager']
15+
tags:
16+
- { name: console.command }
17+
config_edit:
18+
class: Drupal\Console\Command\Config\EditCommand
19+
arguments: ['@config.factory', '@config.storage', '@console.configuration_manager']
20+
tags:
21+
- { name: console.command }
22+
config_export:
23+
class: Drupal\Console\Command\Config\ExportCommand
24+
arguments: ['@config.manager']
25+
tags:
26+
- { name: console.command }
27+
config_export_content_type:
28+
class: Drupal\Console\Command\Config\ExportContentTypeCommand
29+
arguments: ['@entity_type.manager', '@config.storage']
30+
tags:
31+
- { name: console.command }
2632
# config_export_view:
2733
# class: Drupal\Console\Command\Config\ExportViewCommand
2834
# tags:

services.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ services:
1010
# console.command_dependencies:
1111
# class: Drupal\Console\Command\CommandDependencies
1212
# arguments: ["@console.annotation_file_cache"]
13+
console.site:
14+
class: Drupal\Console\Utils\Site
15+
console.file_util:
16+
class: Drupal\Console\Utils\File
17+
# translator:
18+
# class: Drupal\Console\Utils\Translator
19+
# arguments: ["@parser", "@filesystem"]
20+
# console.translator:
21+
# class: Drupal\Console\Utils\Translator
22+
# showfile:
23+
# class: Drupal\Console\Utils\ShowFile
24+
# arguments: ["@site", "@translator"]
25+
# shell_process:
26+
# class: Drupal\Console\Utils\ShellProcess
27+
# arguments: ["@site", '@config']
1328
console.validator:
1429
class: Drupal\Console\Utils\Validator
1530
console.drupal_api:

src/Command/Chain/ChainCommand.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
use Symfony\Component\Console\Output\OutputInterface;
1414
use Symfony\Component\Console\Input\InputOption;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Filesystem\Filesystem;
17+
use Symfony\Component\Yaml\Parser;
1618
use Drupal\Console\Command\Shared\ChainFilesTrait;
1719
use Drupal\Console\Command\Shared\InputTrait;
1820
use Drupal\Console\Style\DrupalStyle;
1921
use Drupal\Console\Command\Shared\CommandTrait;
2022

23+
2124
/**
2225
* Class ChainCommand
2326
* @package Drupal\Console\Command\Chain
@@ -28,6 +31,27 @@ class ChainCommand extends Command
2831
use ChainFilesTrait;
2932
use InputTrait;
3033

34+
35+
protected $fileUtil;
36+
protected $chainQueue;
37+
protected $configurationManager;
38+
protected $appRoot;
39+
40+
/**
41+
* ChainCommand constructor.
42+
* @param $fileUtil
43+
* @param $chainQueue
44+
* @param $configurationManager
45+
* @param $appRoot
46+
*/
47+
public function __construct($fileUtil, $chainQueue, $configurationManager, $appRoot) {
48+
$this->fileUtil = $fileUtil;
49+
$this->chainQueue = $chainQueue;
50+
$this->configurationManager = $configurationManager;
51+
$this->appRoot = $appRoot;
52+
parent::__construct();
53+
}
54+
3155
/**
3256
* {@inheritdoc}
3357
*/
@@ -57,7 +81,6 @@ protected function interact(InputInterface $input, OutputInterface $output)
5781
{
5882
$io = new DrupalStyle($input, $output);
5983
$file = $input->getOption('file');
60-
$fileUtil = $this->getApplication()->getContainerHelper()->get('file_util');
6184

6285
if (!$file) {
6386
$files = $this->getChainFiles(true);
@@ -68,7 +91,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
6891
);
6992
}
7093

71-
$file = $fileUtil->calculateRealPath($file);
94+
$file = $this->fileUtil->calculateRealPath($file);
7295
$input->setOption('file', $file);
7396

7497
$chainContent = file_get_contents($file);
@@ -113,16 +136,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
113136
$learning = $input->hasOption('learning')?$input->getOption('learning'):false;
114137

115138
$file = $input->getOption('file');
116-
$fileUtil = $this->getApplication()->getContainerHelper()->get('file_util');
117-
$fileSystem = $this->getApplication()->getContainerHelper()->get('filesystem');
118139

119140
if (!$file) {
120141
$io->error($this->trans('commands.chain.messages.missing_file'));
121142

122143
return 1;
123144
}
124145

125-
$file = $fileUtil->calculateRealPath($file);
146+
$fileSystem = new Filesystem();
147+
148+
$file = $this->fileUtil->calculateRealPath($file);
126149

127150
if (!$fileSystem->exists($file)) {
128151
$io->error(
@@ -230,7 +253,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
230253
$placeholderResolver = new RegexPlaceholderResolver($inlinePlaceHolderData, '%{{', '}}');
231254
$chainContent = $placeholderResolver->resolvePlaceholder($chainContent);
232255

233-
$parser = $this->getApplication()->getContainerHelper()->get('parser');
256+
$parser = new Parser();
234257
$configData = $parser->parse($chainContent);
235258

236259
$commands = [];
@@ -259,8 +282,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
259282
}
260283
}
261284

262-
$this->get('chain_queue')
263-
->addCommand(
285+
$this->chainQueue->addCommand(
264286
$command['command'],
265287
$moduleInputs,
266288
$interactive,

src/Command/Config/DebugCommand.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@
1212
use Symfony\Component\Console\Output\OutputInterface;
1313
use Drupal\Component\Serialization\Yaml;
1414
use Symfony\Component\Console\Command\Command;
15-
use Drupal\Console\Command\Shared\ContainerAwareCommandTrait;
15+
use Drupal\Console\Command\Shared\CommandTrait;
1616
use Drupal\Console\Style\DrupalStyle;
1717

1818
class DebugCommand extends Command
1919
{
20-
use ContainerAwareCommandTrait;
20+
use CommandTrait;
21+
22+
protected $configFactory;
23+
protected $configStorage;
24+
25+
/**
26+
* ChainCommand constructor.
27+
* @param $fileUtil
28+
*/
29+
public function __construct($configFactory, $configStorage) {
30+
$this->configFactory = $configFactory;
31+
$this->configStorage = $configStorage;
32+
parent::__construct();
33+
}
34+
2135
/**
2236
* {@inheritdoc}
2337
*/
@@ -53,8 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5367
*/
5468
private function getAllConfigurations(DrupalStyle $io)
5569
{
56-
$configFactory = $this->getDrupalService('config.factory');
57-
$names = $configFactory->listAll();
70+
$names = $this->configFactory->listAll();
5871
$tableHeader = [
5972
$this->trans('commands.config.debug.arguments.name'),
6073
];
@@ -74,14 +87,12 @@ private function getAllConfigurations(DrupalStyle $io)
7487
*/
7588
private function getConfigurationByName(DrupalStyle $io, $config_name)
7689
{
77-
$configStorage = $this->getDrupalService('config.storage');
78-
79-
if ($configStorage->exists($config_name)) {
90+
if ($this->configStorage->exists($config_name)) {
8091
$tableHeader = [
8192
$config_name,
8293
];
8394

84-
$configuration = $configStorage->read($config_name);
95+
$configuration = $this->configStorage->read($config_name);
8596
$configurationEncoded = Yaml::encode($configuration);
8697
$tableRows = [];
8798
$tableRows[] = [

src/Command/Config/DeleteCommand.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,36 @@
66

77
namespace Drupal\Console\Command\Config;
88

9-
use Drupal\Console\Command\Shared\ContainerAwareCommandTrait;
109
use Drupal\Core\Config\FileStorage;
1110
use Symfony\Component\Console\Input\InputArgument;
1211
use Symfony\Component\Console\Input\InputInterface;
1312
use Symfony\Component\Console\Output\OutputInterface;
1413
use Symfony\Component\Yaml\Exception\RuntimeException;
1514
use Symfony\Component\Console\Command\Command;
15+
use Drupal\Console\Command\Shared\CommandTrait;
1616
use Drupal\Console\Style\DrupalStyle;
1717

1818
class DeleteCommand extends Command
1919
{
20-
use ContainerAwareCommandTrait;
20+
use CommandTrait;
2121

2222
protected $allConfig = [];
23+
protected $configFactory;
24+
protected $configStorage;
25+
protected $configStorageSync;
26+
27+
/**
28+
* ChainCommand constructor.
29+
* @param $configFactory
30+
* @param $configStorage
31+
* @param $configStorageSync
32+
*/
33+
public function __construct($configFactory , $configStorage, $configStorageSync ) {
34+
$this->configFactory = $configFactory;
35+
$this->configStorage = $configStorage;
36+
$this->configStorageSync = $configStorageSync;
37+
parent::__construct();
38+
}
2339

2440
/**
2541
* {@inheritdoc}
@@ -88,9 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
88104
return 1;
89105
}
90106

91-
$configStorage = ('active' === $type) ?
92-
$this->getDrupalService('config.storage') :
93-
\Drupal::service('config.storage.sync');
107+
$configStorage = ('active' === $type) ? $this->configStorage : $this->configStorageSync;
94108

95109
if (!$configStorage) {
96110
$io->error($this->trans('commands.config.delete.errors.config-storage'));
@@ -148,7 +162,7 @@ private function getAllConfigNames()
148162
return $this->allConfig;
149163
}
150164

151-
foreach ($this->getDrupalService('config.factory')->listAll() as $name) {
165+
foreach ($this->configFactory->listAll() as $name) {
152166
$this->allConfig[] = $name;
153167
}
154168

@@ -177,7 +191,7 @@ private function yieldAllConfig()
177191
private function removeConfig($name)
178192
{
179193
try {
180-
$this->getDrupalService('config.factory')->getEditable($name)->delete();
194+
$this->configFactory->getEditable($name)->delete();
181195
} catch (\Exception $e) {
182196
throw new RuntimeException($e->getMessage());
183197
}

src/Command/Config/DiffCommand.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,26 @@
1313
use Symfony\Component\Console\Input\InputOption;
1414
use Symfony\Component\Console\Output\OutputInterface;
1515
use Symfony\Component\Console\Command\Command;
16-
use Drupal\Console\Command\Shared\ContainerAwareCommandTrait;
16+
use Drupal\Console\Command\Shared\CommandTrait;
1717
use Drupal\Console\Style\DrupalStyle;
1818

1919
class DiffCommand extends Command
2020
{
21-
use ContainerAwareCommandTrait;
21+
use CommandTrait;
22+
23+
protected $configStorage;
24+
protected $configManager;
25+
26+
/**
27+
* ChainCommand constructor.
28+
* @param $fileUtil
29+
*/
30+
public function __construct($configStorage, $configManager ) {
31+
$this->configStorage = $configStorage;
32+
$this->configManager = $configManager;
33+
parent::__construct();
34+
}
35+
2236
/**
2337
* A static array map of operations -> color strings.
2438
*
@@ -82,13 +96,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
8296
$io = new DrupalStyle($input, $output);
8397
$directory = $input->getArgument('directory');
8498
$source_storage = new FileStorage($directory);
85-
$active_storage = $this->getDrupalService('config.storage');
86-
$config_manager = $this->getDrupalService('config.manager');
8799

88100
if ($input->getOption('reverse')) {
89-
$config_comparer = new StorageComparer($source_storage, $active_storage, $config_manager);
101+
$config_comparer = new StorageComparer($source_storage, $this->configStorage, $this->configManager);
90102
} else {
91-
$config_comparer = new StorageComparer($active_storage, $source_storage, $config_manager);
103+
$config_comparer = new StorageComparer($this->configStorage, $source_storage, $this->configManager);
92104
}
93105
if (!$config_comparer->createChangelist()->hasChanges()) {
94106
$output->writeln($this->trans('commands.config.diff.messages.no-changes'));

0 commit comments

Comments
 (0)