Update Cli setup

This commit is contained in:
Maarten 2019-12-24 01:54:04 +01:00
parent 7d8a207eee
commit 85583503f6
5 changed files with 144 additions and 12 deletions

92
src/Cli/Assets/Colors.php Normal file
View file

@ -0,0 +1,92 @@
<?php
namespace Cli\Assets;
class Colors {
/**
* @var array
*/
private static $foreground_colors = [];
/**
* @var array
*/
private static $background_colors = [];
/**
* Colors constructor.
*/
public static function setColors()
{
self::$foreground_colors['black'] = '0;30';
self::$foreground_colors['dark_gray'] = '1;30';
self::$foreground_colors['blue'] = '0;34';
self::$foreground_colors['light_blue'] = '1;34';
self::$foreground_colors['green'] = '0;32';
self::$foreground_colors['light_green'] = '1;32';
self::$foreground_colors['cyan'] = '0;36';
self::$foreground_colors['light_cyan'] = '1;36';
self::$foreground_colors['red'] = '0;31';
self::$foreground_colors['light_red'] = '1;31';
self::$foreground_colors['purple'] = '0;35';
self::$foreground_colors['light_purple'] = '1;35';
self::$foreground_colors['brown'] = '0;33';
self::$foreground_colors['yellow'] = '1;33';
self::$foreground_colors['light_gray'] = '0;37';
self::$foreground_colors['white'] = '1;37';
self::$background_colors['black'] = '40';
self::$background_colors['red'] = '41';
self::$background_colors['green'] = '42';
self::$background_colors['yellow'] = '43';
self::$background_colors['blue'] = '44';
self::$background_colors['magenta'] = '45';
self::$background_colors['cyan'] = '46';
self::$background_colors['light_gray'] = '47';
}
/**
* @param $string
* @param null $foreground_color
* @param null $background_color
* @return string
*/
public static function getColoredString($string, $foreground_color = null, $background_color = null)
{
self::setColors();
$colored_string = "";
if (isset(self::$foreground_colors[$foreground_color])) {
$colored_string .= "\033[" . self::$foreground_colors[$foreground_color] . "m";
}
if (isset(self::$background_colors[$background_color])) {
$colored_string .= "\033[" . self::$background_colors[$background_color] . "m";
}
$colored_string .= $string . "\033[0m";
return $colored_string;
}
/**
* @return array
*/
public function getForegroundColors()
{
self::setColors();
return array_keys(self::$foreground_colors);
}
/**
* @return array
*/
public function getBackgroundColors()
{
self::setColors();
return array_keys(self::$background_colors);
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Cli\Commands;
class Commands
{
/**
* @var array
*/
private $args = [];
/**
* Commands constructor.
* @param array $args
*/
public function __construct(array $args)
{
$this->args = $args;
}
public function handle()
{
}
}

View file

@ -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();
}
}

View file

@ -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);

View file

@ -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);
}
}