Skip to content

Commit

Permalink
[console] Rename service message_parser => message_manager. (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas committed Nov 23, 2017
1 parent 017b6fc commit 76a89f8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 48 deletions.
4 changes: 2 additions & 2 deletions services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ services:
arguments: ['@console.root', '@console.configuration_manager']
console.count_code_lines:
class: Drupal\Console\Core\Utils\CountCodeLines
console.message_parser:
class: Drupal\Console\Core\Utils\MessageParser
console.message_manager:
class: Drupal\Console\Core\Utils\MessageManager
# DrupalConsoleCore Commands
console.about:
class: Drupal\Console\Core\Command\AboutCommand
Expand Down
31 changes: 15 additions & 16 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class Application extends BaseApplication
*/
protected $drupal;


/**
* @var bool
*/
Expand Down Expand Up @@ -102,10 +101,7 @@ public function trans($key)
public function doRun(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$messages = [];
if ($this->container->hasParameter('console.messages')) {
$messages = $this->container->getParameter('console.messages');
}
$messageManager = $this->container->get('console.message_manager');
$this->commandName = $this->getCommandName($input)?:'list';

$clear = $this->container->get('console.configuration_manager')
Expand Down Expand Up @@ -146,13 +142,13 @@ public function doRun(InputInterface $input, OutputInterface $output)

if (array_key_exists($this->commandName, $mappings)) {
$commandNameMap = $mappings[$this->commandName];
$messages[] =[
'warning' => sprintf(
$messageManager->warning(
sprintf(
$this->trans('application.errors.renamed-command'),
$this->commandName,
$commandNameMap
)
];
);
$this->add(
$this->find($commandNameMap)->setAliases([$this->commandName])
);
Expand All @@ -165,13 +161,13 @@ public function doRun(InputInterface $input, OutputInterface $output)
$this->find($drushCommand)->setAliases([$this->commandName])
);
$isValidCommand = true;
$messages[] = [
'warning' => sprintf(
$messageManager->warning(
sprintf(
$this->trans('application.errors.drush-command'),
$this->commandName,
$drushCommand
)
];
);
}

if (!$isValidCommand) {
Expand Down Expand Up @@ -204,10 +200,11 @@ public function doRun(InputInterface $input, OutputInterface $output)
)
);
}
$messages = $messageManager->getMessages();

foreach ($messages as $key => $message) {
$type = key($message);
$io->$type($message);
foreach ($messages as $message) {
$type = $message['type'];
$io->$type($message['message']);
}

return $code;
Expand Down Expand Up @@ -614,14 +611,16 @@ private function registerExtendCommands()
/**
* @return DrupalInterface
*/
public function getDrupal() {
public function getDrupal()
{
return $this->drupal;
}

/**
* @param DrupalInterface $drupal
*/
public function setDrupal($drupal) {
public function setDrupal($drupal)
{
$this->drupal = $drupal;
}

Expand Down
66 changes: 66 additions & 0 deletions src/Utils/MessageManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Drupal\Console\Core\Utils;

/**
* Class MessageParser
*
* @package Drupal\Console\Core\Utils
*/
class MessageManager
{

/**
* @var array
*/
protected $messages = [];

/**
* @param $type
* @param $message
* @param $code
*/
private function add($type, $message, $code)
{
$this->messages[] = [
'type' =>$type,
'message' => $message,
'code' => $code,
];
}

/**
* @param $message
* @param $code
*/
public function error($message, $code = 0)
{
$this->add('error', $message, $code);
}

/**
* @param $message
* @param $code
*/
public function warning($message, $code = 0)
{
$this->add('warning', $message, $code);
}

/**
* @param $message
* @param $code
*/
public function info($message, $code = 0)
{
$this->add('info', $message, $code);
}

/**
* @return array
*/
public function getMessages()
{
return $this->messages;
}
}
30 changes: 0 additions & 30 deletions src/Utils/MessageParser.php

This file was deleted.

0 comments on commit 76a89f8

Please sign in to comment.