public function __construct() { $this->_c = new \Colors\Color(); $this->_c->setTheme(array('command' => 'yellow', 'message' => 'blue', 'error' => 'red')); }
/** * Prepare CLI application * * @param SlimApp $app Application object * @param ContainerInterface $container ContainerInterface to prepare */ private static function prepareCliContainer(SlimApp $app, ContainerInterface $container) { $argv = $GLOBALS['argv']; array_shift($argv); $pathInfo = '/' . implode('/', explode(':', array_shift($argv))); $container['environment'] = \Slim\Http\Environment::mock(['REQUEST_URI' => $pathInfo, 'REQUEST_METHOD' => 'GET']); $container['formatter'] = function () { $c = new Color(); $c->setTheme(['error' => ['red', 'bg_white'], 'success' => 'green', 'info' => ['cyan'], 'warn' => ['orange']]); return $c; }; $container['output'] = function ($c) { return function ($text, $newLine = true) use($c) { if ($newLine) { $text .= PHP_EOL; } $f = $c['formatter']; echo $f($text)->colorize(); }; }; $container['errorHandler'] = function ($c) { return function ($request, $response, $exception) use($c) { $f = $c['formatter']; echo $f('Exception: <error>' . $exception->getMessage() . '</error>')->colorize(); exit; }; }; $container['notFoundHandler'] = function ($c) use($app) { return function ($request, $response) use($c, $app) { $path = implode(':', explode('/', trim($request->getUri()->getPath(), '/'))); $output = $c['output']; $output('<error>Could not find the action <bold>' . $path . '</bold></error>'); actions\cli\IndexAction::registerApp($app); actions\cli\IndexAction::displayHelp(true); exit; }; }; }