diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-08-18 13:30:22 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-08-18 13:30:22 +0300 |
commit | c541693b0f400251d613e6ba8c7ca26899e93e92 (patch) | |
tree | 829481aa615ddec7f5c0ecd7a6b3633917804b2a /lib | |
parent | 44a5fa48fef0adb9389ef1ee2a7c65e11575d9e4 (diff) |
info & error
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Model/Runner.php | 70 | ||||
-rw-r--r-- | lib/Service/CliService.php | 12 |
2 files changed, 72 insertions, 10 deletions
diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php index 153abfe..b29be19 100644 --- a/lib/Model/Runner.php +++ b/lib/Model/Runner.php @@ -81,6 +81,9 @@ class Runner { /** @var array */ private $methodOnInfoUpdate = []; + /** @var array */ + private $methodOnIndexError = []; + /** @var bool */ private $paused = false; @@ -191,9 +194,11 @@ class Runner { /** * @param string $info * @param string $value + * @param string $colored */ - public function setInfo($info, $value) { + public function setInfo($info, $value, $colored = '') { $this->info[$info] = $value; + $this->setInfoColored($info, $value, $colored); $this->infoUpdated(); } @@ -210,6 +215,40 @@ class Runner { $this->infoUpdated(); } + private function setInfoColored($info, $value, $colored) { + if ($colored === '') { + return; + } + + $color = ''; + switch ($colored) { + case 'success': + $color = 'info'; + break; + + case 'fail' : + $color = 'error'; + break; + + case 'warning': + $color = 'comment'; + break; + } + + if ($color !== '') { + $this->info[$info . 'Colored'] = '<' . $color . '>' . $value . '</' . $color . '>'; + } + + + } + + /** + * @return array + */ + public function getInfo() { + return $this->info; + } + /** * @param array $method @@ -236,7 +275,7 @@ class Runner { } /** - * @param $key + * @param string $action */ public function newAction($action) { foreach ($this->methodOnNewAction as $method) { @@ -263,6 +302,33 @@ class Runner { /** + * @param array $method + */ + public function onNewIndexError($method) { + $this->methodOnIndexError[] = $method; + } + + /** + * @param Index $index + * @param string $message + * @param string $class + * @param int $sev + */ + public function newIndexError($index, $message, $class = '', $sev = 3) { + $error = [ + 'index' => $index, + 'message' => $message, + 'exception' => $class, + 'severity' => $sev + ]; + + foreach ($this->methodOnIndexError as $method) { + call_user_func($method, $error); + } + } + + + /** * @throws InterruptException */ private function hasBeenInterrupted() { diff --git a/lib/Service/CliService.php b/lib/Service/CliService.php index 19338f2..5e0a8bc 100644 --- a/lib/Service/CliService.php +++ b/lib/Service/CliService.php @@ -156,6 +156,7 @@ class CliService { $this->display = new ProgressBar($this->output); $this->display->setOverwrite(true); + $initVar = $this->runner->getInfo(); $keys = array_keys($initVar); foreach ($keys as $key) { $this->display->setMessage($initVar[$key], $key); @@ -193,6 +194,8 @@ class CliService { } else { $this->display->setMessage('', '_paused'); } + + $this->display->display(); } /** @@ -203,18 +206,11 @@ class CliService { return; } - $this->refreshInfo(); $keys = array_keys($info); foreach ($keys as $k) { - if ($info[$k] === 'ok') { - $this->display->setMessage('<info>ok</info>', $k . 'Colored'); - } - if ($info[$k] === 'fail') { - $this->display->setMessage('<error>failed</error>', $k . 'Colored'); - } - $this->display->setMessage($info[$k], $k); } + $this->refreshInfo(); $this->display->display(); } |