8
0
daux.io/libs/Console/RunAction.php

26 Zeilen
751 B
PHP

2015-07-23 17:44:24 +02:00
<?php namespace Todaymade\Daux\Console;
2015-07-14 22:06:01 +02:00
use Symfony\Component\Console\Output\OutputInterface;
trait RunAction
{
protected function runAction($title, OutputInterface $output, $width, \Closure $closure)
{
$output->write($title);
2015-07-23 17:44:24 +02:00
$length = function_exists("mb_strlen")? mb_strlen($title) : strlen($title);
2015-07-14 22:06:01 +02:00
// 8 is the length of the label + 2 let it breathe
2015-07-23 17:44:24 +02:00
$padding = $width - $length - 10;
2015-07-14 22:06:01 +02:00
try {
$response = $closure();
} catch (\Exception $e) {
$output->writeln(str_pad(" ", $padding) . "[ <fg=red>FAIL</fg=red> ]");
throw $e;
}
$output->writeln(str_pad(" ", $padding) . "[ <fg=green>OK</fg=green> ]");
return $response;
}
}