Skip to content

Commit

Permalink
[console] Add showBy to messageManager. (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas committed Jan 30, 2018
1 parent 3b4d66f commit d4f12a4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
5 changes: 4 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ public function doRun(InputInterface $input, OutputInterface $output)
$messages = $messageManager->getMessages();

foreach ($messages as $message) {
$showBy = $message['showBy'];
if ($showBy!=='all' && $showBy!==$this->commandName) {
continue;
}
$type = $message['type'];
$io->$type($message['message']);
}
Expand Down Expand Up @@ -637,7 +641,6 @@ private function registerExtendCommands()
->loadExtendConfiguration();
}


public function getData()
{
$singleCommands = [
Expand Down
1 change: 1 addition & 0 deletions src/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
);

$this->command = null;
$this->getIo()->newLine();
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/Utils/ChainDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,15 @@ public function getFiles()
$this->getFileMetadata($filePath);

if ($this->files[$filePath]['messages']) {
$this->messageManager->info($filePath);
$this->messageManager->comment(
$filePath,
0,
'list'
);
$this->messageManager->listing(
$this->files[$filePath]['messages']
$this->files[$filePath]['messages'],
0,
'list'
);
}

Expand Down
51 changes: 34 additions & 17 deletions src/Utils/MessageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,73 @@ class MessageManager
* @param $type
* @param $message
* @param $code
* @param $removableBy
* @param $showBy
* @param $removeBy
*/
private function add($type, $message, $code, $removableBy)
private function add($type, $message, $code, $showBy, $removeBy)
{
$this->messages[] = [
'type' =>$type,
'message' => $message,
'code' => $code,
'removableBy' => $removableBy
'showBy' => $showBy,
'removeBy' => $removeBy,
];
}

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

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

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

/**
* @param $message
* @param $code
* @param $removableBy
* @param $showBy
* @param $removeBy
*/
public function listing(array $message, $code = 0, $removableBy = null)
public function listing(array $message, $code = 0, $showBy = 'all', $removeBy = null)
{
$this->add('listing', $message, $code, $removableBy);
$this->add('listing', $message, $code, $showBy, $removeBy);
}

/**
* @param $message
* @param $code
* @param $showBy
* @param $removeBy
*/
public function comment($message, $code = 0, $showBy = 'all', $removeBy = null)
{
$this->add('comment', $message, $code, $showBy, $removeBy);
}