From 85583503f6c3a12fdd80933fa9d3002f414f9224 Mon Sep 17 00:00:00 2001 From: Maarten Date: Tue, 24 Dec 2019 01:54:04 +0100 Subject: [PATCH] Update Cli setup --- src/Cli/Assets/Colors.php | 92 ++++++++++++++++++++++++ src/Cli/Commands/Commands.php | 27 +++++++ src/Cli/Factory.php | 5 +- src/Runtime/Factory/BootstrapFactory.php | 27 ++++--- src/Runtime/Helpers/helpers.php | 5 +- 5 files changed, 144 insertions(+), 12 deletions(-) create mode 100644 src/Cli/Assets/Colors.php create mode 100644 src/Cli/Commands/Commands.php diff --git a/src/Cli/Assets/Colors.php b/src/Cli/Assets/Colors.php new file mode 100644 index 0000000..33f9074 --- /dev/null +++ b/src/Cli/Assets/Colors.php @@ -0,0 +1,92 @@ +args = $args; + } + + public function handle() + { + + } + +} \ No newline at end of file diff --git a/src/Cli/Factory.php b/src/Cli/Factory.php index a92c546..60fe608 100644 --- a/src/Cli/Factory.php +++ b/src/Cli/Factory.php @@ -2,12 +2,15 @@ namespace Cli; +use Cli\Commands\Commands; + class Factory { public function handle() { - echo 'het werkt :)'; + global $argv; + app(Commands::class, [$argv])->handle(); } } \ No newline at end of file diff --git a/src/Runtime/Factory/BootstrapFactory.php b/src/Runtime/Factory/BootstrapFactory.php index d4896d9..9e751e8 100644 --- a/src/Runtime/Factory/BootstrapFactory.php +++ b/src/Runtime/Factory/BootstrapFactory.php @@ -2,19 +2,17 @@ namespace Runtime\Factory; -use Cli\Factory; +use Cli\Factory as CliFactory; use Runtime\Exceptions\Exceptions\ClassNotFoundException; use Runtime\Http\View\ViewEngine; use Runtime\Router\Route; use Runtime\Exceptions\ExceptionHandler; -use Runtime\Router\Router; use Twig\Environment; -use Twig\Loader\FilesystemLoader; class BootstrapFactory { /** - * + * Handle Http core */ public function handle() { @@ -33,27 +31,38 @@ class BootstrapFactory { } } + /** + * Handle kernel core + */ public function kernel() { - app(Factory::class)->handle(); + app(CliFactory::class)->handle(); } /** * @param $abstract + * @param array $arguments * @return mixed */ - public function make($abstract) + public function make($abstract, $arguments = []) { - return $this->resolve($abstract); + return $this->resolve($abstract, $arguments); } /** * @param $abstract + * @param $arguments * @return mixed|null */ - private function resolve($abstract) { + private function resolve($abstract, array $arguments) { if(class_exists($abstract)) { - return new $abstract; + try { + $reflection = new \ReflectionClass($abstract); + return $reflection->newInstanceArgs($arguments); + } + catch (\ReflectionException $e) { + ExceptionHandler::make($e); + } } ExceptionHandler::make(ClassNotFoundException::class); diff --git a/src/Runtime/Helpers/helpers.php b/src/Runtime/Helpers/helpers.php index 2f7bbaa..48c968d 100644 --- a/src/Runtime/Helpers/helpers.php +++ b/src/Runtime/Helpers/helpers.php @@ -13,15 +13,16 @@ if(!function_exists('app')) { /** * @param null $abstract + * @param array $arguments * @return \Runtime\Factory\BootstrapFactory|Container */ - function app($abstract = null) + function app($abstract = null, $arguments = []) { if (is_null($abstract)) { return Bootstrap::getInstance(); } - return Bootstrap::getInstance()->make($abstract); + return Bootstrap::getInstance()->make($abstract, $arguments); } }