Skip to content

Commit

Permalink
Commands in container (#2604)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
enzolutions authored and jmolivas committed Aug 23, 2016
1 parent 25066a2 commit 2dc1954
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 92 deletions.
19 changes: 10 additions & 9 deletions config/services/chain.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#services:
# chain:
# class: Drupal\Console\Command\Chain\ChainCommand
# tags:
# - { name: console.command }
# chain_debug:
# class: Drupal\Console\Command\Chain\ChainDebugCommand
# tags:
# - { name: console.command }
services:
chain:
class: Drupal\Console\Command\Chain\ChainCommand
arguments: ['@console.file_util', '@console.chain_queue', '@console.configuration_manager', '@app.root']
tags:
- { name: console.command }
chain_debug:
class: Drupal\Console\Command\Chain\ChainDebugCommand
tags:
- { name: console.command }
56 changes: 31 additions & 25 deletions config/services/config.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
#services:
# config_debug:
# class: Drupal\Console\Command\Config\DebugCommand
# tags:
# - { name: console.command }
# config_delete:
# class: Drupal\Console\Command\Config\DeleteCommand
# tags:
# - { name: console.command }
# config_diff:
# class: Drupal\Console\Command\Config\DiffCommand
# tags:
# - { name: console.command }
# config_edit:
# class: Drupal\Console\Command\Config\EditCommand
# tags:
# - { name: console.command }
# config_export:
# class: Drupal\Console\Command\Config\ExportCommand
# tags:
# - { name: console.command }
# config_export_content_type:
# class: Drupal\Console\Command\Config\ExportContentTypeCommand
# tags:
# - { name: console.command }
services:
config_debug:
class: Drupal\Console\Command\Config\DebugCommand
arguments: ['@config.factory', '@config.storage']
tags:
- { name: console.command }
config_delete:
class: Drupal\Console\Command\Config\DeleteCommand
arguments: ['@config.factory', '@config.storage', '@config.storage.sync']
tags:
- { name: console.command }
config_diff:
class: Drupal\Console\Command\Config\DiffCommand
arguments: ['@config.storage', '@config.manager']
tags:
- { name: console.command }
config_edit:
class: Drupal\Console\Command\Config\EditCommand
arguments: ['@config.factory', '@config.storage', '@console.configuration_manager']
tags:
- { name: console.command }
config_export:
class: Drupal\Console\Command\Config\ExportCommand
arguments: ['@config.manager']
tags:
- { name: console.command }
config_export_content_type:
class: Drupal\Console\Command\Config\ExportContentTypeCommand
arguments: ['@entity_type.manager', '@config.storage']
tags:
- { name: console.command }
# config_export_view:
# class: Drupal\Console\Command\Config\ExportViewCommand
# tags:
Expand Down
15 changes: 15 additions & 0 deletions services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ services:
# console.command_dependencies:
# class: Drupal\Console\Command\CommandDependencies
# arguments: ["@console.annotation_file_cache"]
console.site:
class: Drupal\Console\Utils\Site
console.file_util:
class: Drupal\Console\Utils\File
# translator:
# class: Drupal\Console\Utils\Translator
# arguments: ["@parser", "@filesystem"]
# console.translator:
# class: Drupal\Console\Utils\Translator
# showfile:
# class: Drupal\Console\Utils\ShowFile
# arguments: ["@site", "@translator"]
# shell_process:
# class: Drupal\Console\Utils\ShellProcess
# arguments: ["@site", '@config']
console.validator:
class: Drupal\Console\Utils\Validator
console.drupal_api:
Expand Down
38 changes: 30 additions & 8 deletions src/Command/Chain/ChainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Parser;
use Drupal\Console\Command\Shared\ChainFilesTrait;
use Drupal\Console\Command\Shared\InputTrait;
use Drupal\Console\Style\DrupalStyle;
use Drupal\Console\Command\Shared\CommandTrait;


/**
* Class ChainCommand
* @package Drupal\Console\Command\Chain
Expand All @@ -28,6 +31,27 @@ class ChainCommand extends Command
use ChainFilesTrait;
use InputTrait;


protected $fileUtil;
protected $chainQueue;
protected $configurationManager;
protected $appRoot;

/**
* ChainCommand constructor.
* @param $fileUtil
* @param $chainQueue
* @param $configurationManager
* @param $appRoot
*/
public function __construct($fileUtil, $chainQueue, $configurationManager, $appRoot) {
$this->fileUtil = $fileUtil;
$this->chainQueue = $chainQueue;
$this->configurationManager = $configurationManager;
$this->appRoot = $appRoot;
parent::__construct();
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -57,7 +81,6 @@ protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$file = $input->getOption('file');
$fileUtil = $this->getApplication()->getContainerHelper()->get('file_util');

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

$file = $fileUtil->calculateRealPath($file);
$file = $this->fileUtil->calculateRealPath($file);
$input->setOption('file', $file);

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

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

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

return 1;
}

$file = $fileUtil->calculateRealPath($file);
$fileSystem = new Filesystem();

$file = $this->fileUtil->calculateRealPath($file);

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

$parser = $this->getApplication()->getContainerHelper()->get('parser');
$parser = new Parser();
$configData = $parser->parse($chainContent);

$commands = [];
Expand Down Expand Up @@ -259,8 +282,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

$this->get('chain_queue')
->addCommand(
$this->chainQueue->addCommand(
$command['command'],
$moduleInputs,
$interactive,
Expand Down
27 changes: 19 additions & 8 deletions src/Command/Config/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,26 @@
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Component\Serialization\Yaml;
use Symfony\Component\Console\Command\Command;
use Drupal\Console\Command\Shared\ContainerAwareCommandTrait;
use Drupal\Console\Command\Shared\CommandTrait;
use Drupal\Console\Style\DrupalStyle;

class DebugCommand extends Command
{
use ContainerAwareCommandTrait;
use CommandTrait;

protected $configFactory;
protected $configStorage;

/**
* ChainCommand constructor.
* @param $fileUtil
*/
public function __construct($configFactory, $configStorage) {
$this->configFactory = $configFactory;
$this->configStorage = $configStorage;
parent::__construct();
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -53,8 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
private function getAllConfigurations(DrupalStyle $io)
{
$configFactory = $this->getDrupalService('config.factory');
$names = $configFactory->listAll();
$names = $this->configFactory->listAll();
$tableHeader = [
$this->trans('commands.config.debug.arguments.name'),
];
Expand All @@ -74,14 +87,12 @@ private function getAllConfigurations(DrupalStyle $io)
*/
private function getConfigurationByName(DrupalStyle $io, $config_name)
{
$configStorage = $this->getDrupalService('config.storage');

if ($configStorage->exists($config_name)) {
if ($this->configStorage->exists($config_name)) {
$tableHeader = [
$config_name,
];

$configuration = $configStorage->read($config_name);
$configuration = $this->configStorage->read($config_name);
$configurationEncoded = Yaml::encode($configuration);
$tableRows = [];
$tableRows[] = [
Expand Down
28 changes: 21 additions & 7 deletions src/Command/Config/DeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,36 @@

namespace Drupal\Console\Command\Config;

use Drupal\Console\Command\Shared\ContainerAwareCommandTrait;
use Drupal\Core\Config\FileStorage;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Exception\RuntimeException;
use Symfony\Component\Console\Command\Command;
use Drupal\Console\Command\Shared\CommandTrait;
use Drupal\Console\Style\DrupalStyle;

class DeleteCommand extends Command
{
use ContainerAwareCommandTrait;
use CommandTrait;

protected $allConfig = [];
protected $configFactory;
protected $configStorage;
protected $configStorageSync;

/**
* ChainCommand constructor.
* @param $configFactory
* @param $configStorage
* @param $configStorageSync
*/
public function __construct($configFactory , $configStorage, $configStorageSync ) {
$this->configFactory = $configFactory;
$this->configStorage = $configStorage;
$this->configStorageSync = $configStorageSync;
parent::__construct();
}

/**
* {@inheritdoc}
Expand Down Expand Up @@ -88,9 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}

$configStorage = ('active' === $type) ?
$this->getDrupalService('config.storage') :
\Drupal::service('config.storage.sync');
$configStorage = ('active' === $type) ? $this->configStorage : $this->configStorageSync;

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

foreach ($this->getDrupalService('config.factory')->listAll() as $name) {
foreach ($this->configFactory->listAll() as $name) {
$this->allConfig[] = $name;
}

Expand Down Expand Up @@ -177,7 +191,7 @@ private function yieldAllConfig()
private function removeConfig($name)
{
try {
$this->getDrupalService('config.factory')->getEditable($name)->delete();
$this->configFactory->getEditable($name)->delete();
} catch (\Exception $e) {
throw new RuntimeException($e->getMessage());
}
Expand Down
24 changes: 18 additions & 6 deletions src/Command/Config/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
use Drupal\Console\Command\Shared\ContainerAwareCommandTrait;
use Drupal\Console\Command\Shared\CommandTrait;
use Drupal\Console\Style\DrupalStyle;

class DiffCommand extends Command
{
use ContainerAwareCommandTrait;
use CommandTrait;

protected $configStorage;
protected $configManager;

/**
* ChainCommand constructor.
* @param $fileUtil
*/
public function __construct($configStorage, $configManager ) {
$this->configStorage = $configStorage;
$this->configManager = $configManager;
parent::__construct();
}

/**
* A static array map of operations -> color strings.
*
Expand Down Expand Up @@ -82,13 +96,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io = new DrupalStyle($input, $output);
$directory = $input->getArgument('directory');
$source_storage = new FileStorage($directory);
$active_storage = $this->getDrupalService('config.storage');
$config_manager = $this->getDrupalService('config.manager');

if ($input->getOption('reverse')) {
$config_comparer = new StorageComparer($source_storage, $active_storage, $config_manager);
$config_comparer = new StorageComparer($source_storage, $this->configStorage, $this->configManager);
} else {
$config_comparer = new StorageComparer($active_storage, $source_storage, $config_manager);
$config_comparer = new StorageComparer($this->configStorage, $source_storage, $this->configManager);
}
if (!$config_comparer->createChangelist()->hasChanges()) {
$output->writeln($this->trans('commands.config.diff.messages.no-changes'));
Expand Down
Loading

0 comments on commit 2dc1954

Please sign in to comment.