add possibility to render a block on command output

This commit is contained in:
Manuel Raynaud
2013-07-11 12:54:38 +02:00
parent 6baac9e36c
commit 6fa815d174
3 changed files with 45 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
<?php
namespace Thelia\Command\Output;
use Symfony\Component\Console\Output\ConsoleOutput;
class TheliaConsoleOutput extends ConsoleOutput{
public function renderBlock(array $messages, $style = "info")
{
$strlen = function ($string) {
if (!function_exists('mb_strlen')) {
return strlen($string);
}
if (false === $encoding = mb_detect_encoding($string)) {
return strlen($string);
}
return mb_strlen($string, $encoding);
};
$length = 0;
foreach ($messages as $message) {
$length = ($strlen($message) > $length) ? $strlen($message) : $length;
}
$ouput = array();
foreach ($messages as $message) {
$output[] = "<" . $style . ">" . " " . $message . str_repeat(' ', $length - $strlen($message)) . " </" . $style . ">";
}
$this->writeln($output);
}
}