From 4f48fb3ab15c2bec55721369545378a518c65dfc Mon Sep 17 00:00:00 2001 From: Biuhub Studio Date: Fri, 17 May 2019 18:30:43 +0000 Subject: [PATCH] updated package as Toolbox --- Test/CommandTest.php | 6 +++--- src/Application.php | 31 +++++++++++++++++++++++-------- src/Colors.php | 2 +- src/Command.php | 2 +- src/Command/CommandList.php | 4 ++-- src/Concerns/FileUtils.php | 2 +- src/Concerns/InputUtils.php | 2 +- src/Exception/JetError.php | 4 ++-- src/Formatter.php | 2 +- src/PSR3.php | 2 +- 10 files changed, 36 insertions(+), 21 deletions(-) diff --git a/Test/CommandTest.php b/Test/CommandTest.php index 06235d3..8530fc7 100644 --- a/Test/CommandTest.php +++ b/Test/CommandTest.php @@ -14,11 +14,11 @@ * @author Divine Niiquaye */ - namespace Radion\Console\Test; + namespace Radion\Toolbox\ConsoleLite\Test; use PHPUnit\Framework\TestCase; -use Radion\Component\Console\Application; -use Radion\Component\Console\Command; +use Radion\Toolbox\ConsoleLite\Application; +use Radion\Toolbox\ConsoleLite\Command; class CommandTest extends TestCase { diff --git a/src/Application.php b/src/Application.php index 2b68655..12e2592 100644 --- a/src/Application.php +++ b/src/Application.php @@ -15,13 +15,13 @@ * @author Muhammad Syifa */ -namespace Radion\Component\Console; +namespace Radion\Toolbox\ConsoleLite; use Closure; use Exception; use InvalidArgumentException; -use Radion\Autoloader\Console\Exception\JetError; -use Radion\Component\Console\Command\CommandList; +use Radion\Toolbox\ConsoleLite\Exception\JetError; +use Radion\Toolbox\ConsoleLite\Command\CommandList; class Application { @@ -44,7 +44,6 @@ class Application protected $resolvedOptions = []; protected $formatter; protected $errorhandle; - protected $autoloadone; /** @var array PSR-3 compatible foreground color and their prefix, color, output channel */ protected $foregroundColors = [ @@ -99,7 +98,6 @@ private function loadCommands() { $this->command('hello {name?::Enter a name}', 'Enter your name to start', function ($name) { $this->block("Hello {$name}, Nice Meeting you, I'm Biurad Slim Lite Console.", 'white', 'black'); - }); } @@ -310,7 +308,7 @@ public function execute($command) call_user_func_array($handler, $arguments); } catch (JetError $e) { - throw new JetError('The Application runned into an error', $e->getCode()); + $this->handleError($e); } } @@ -527,7 +525,7 @@ public function block($message, $fgColor = null, $bgColor = null, $width = null) if ($width !== null) { $this->formatter->setMaxWidth($width); } else { - // do nothing. + $this->formatter->getMaxWidth(); } $this->line(); $this->line(1, true); @@ -539,6 +537,18 @@ public function block($message, $fgColor = null, $bgColor = null, $width = null) $this->line(); } + /** + * Write a help block + * + * @param mixed $name is the subject + * @param string $description is the description + * @return void + */ + public function helpblock($name, $description) + { + return $this->writeln(' '.$this->style($name, 'purple').str_repeat(' ', 2 - strlen($name)) . ' -> ' . $description); + } + /** * @param string $fgcolor * @param string $message @@ -1069,7 +1079,12 @@ public function handleError(\Throwable $exception) { //$exception = new Exception; $indent = str_repeat(' ', 2); - $class = get_class($exception); + //$class = get_class($exception); + if (get_class($exception) === 'Radion\Toolbox\ConsoleLite\Exception\JetError') { + $class = 'Application Error'; + } else { + $class = get_class($exception); + } $file = $exception->getFile(); $line = $exception->getLine(); $filepath = function ($file) { diff --git a/src/Colors.php b/src/Colors.php index f375c94..8e7d142 100644 --- a/src/Colors.php +++ b/src/Colors.php @@ -14,7 +14,7 @@ * @author Divine Niiquaye */ -namespace Radion\Component\Console; +namespace Radion\Toolbox\ConsoleLite; use Exception; diff --git a/src/Command.php b/src/Command.php index 823561c..284d371 100644 --- a/src/Command.php +++ b/src/Command.php @@ -15,7 +15,7 @@ * @author Muhammad Syifa */ -namespace Radion\Component\Console; +namespace Radion\Toolbox\ConsoleLite; abstract class Command { diff --git a/src/Command/CommandList.php b/src/Command/CommandList.php index 825375c..85c139f 100644 --- a/src/Command/CommandList.php +++ b/src/Command/CommandList.php @@ -14,9 +14,9 @@ * @author Divine Niiquaye */ -namespace Radion\Component\Console\Command; +namespace Radion\Toolbox\ConsoleLite\Command; -use Radion\Component\Console\Command; +use Radion\Toolbox\ConsoleLite\Command; class CommandList extends Command { diff --git a/src/Concerns/FileUtils.php b/src/Concerns/FileUtils.php index e809820..11d1905 100644 --- a/src/Concerns/FileUtils.php +++ b/src/Concerns/FileUtils.php @@ -14,7 +14,7 @@ * @author Divine Niiquaye */ -namespace Radion\Component\Console\Concerns; +namespace Radion\Toolbox\ConsoleLite\Concerns; class FileUtils { diff --git a/src/Concerns/InputUtils.php b/src/Concerns/InputUtils.php index 905ac55..66afe2b 100644 --- a/src/Concerns/InputUtils.php +++ b/src/Concerns/InputUtils.php @@ -15,7 +15,7 @@ * @author Muhammad Syifa */ -namespace Radion\Component\Console\Concerns; +namespace Radion\Toolbox\ConsoleLite\Concerns; use RuntimeException; diff --git a/src/Exception/JetError.php b/src/Exception/JetError.php index 320b7a4..85aec8b 100644 --- a/src/Exception/JetError.php +++ b/src/Exception/JetError.php @@ -14,7 +14,7 @@ * @author Divine Niiquaye */ -namespace Radion\Autoloader\Console\Exception; +namespace Radion\Toolbox\ConsoleLite\Exception; /** * JetError. @@ -28,6 +28,6 @@ class JetError extends \Exception implements \Throwable { public function run() { - set_exception_handler('Radion\Autoloader\Console\Application::exception'); + set_exception_handler('Radion\Toolbox\ConsoleLite\Application::exception'); } } diff --git a/src/Formatter.php b/src/Formatter.php index bdbadbf..5ca29a5 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -14,7 +14,7 @@ * @author Divine Niiquaye */ -namespace Radion\Component\Console; +namespace Radion\Toolbox\ConsoleLite; use Exception; diff --git a/src/PSR3.php b/src/PSR3.php index 36fb5a2..e78eb99 100644 --- a/src/PSR3.php +++ b/src/PSR3.php @@ -14,7 +14,7 @@ * @author Divine Niiquaye */ -namespace Radion\Component\Console; +namespace Radion\Toolbox\ConsoleLite; use Psr\Log\LoggerInterface;