/** * Main method. */ public static function main() { list($command, $arguments, $config) = self::preProcess(); $migration = new Migration($config); try { $cli = new Cli(); $cli->execute($migration, $command, $arguments, $config); } catch (\Exception $e) { $debug = $migration->getConfig()->get('debug'); $colors = $migration->getConfig()->get('colors'); if (isset($debug) && $debug) { if ($colors) { fputs(STDERR, pack('c', 0x1b) . "[1;37;41m" . $e . pack('c', 0x1b) . "[0m\n"); } else { fputs(STDERR, $e); } } else { if ($colors) { fputs(STDERR, pack('c', 0x1b) . "[1;37;41m" . $e->getMessage() . pack('c', 0x1b) . "[0m\n"); } else { fputs(STDERR, $e->getMessage() . "\n"); } } } }
<?php /** * Написать простой CLI скрипт, который принимает на ввод строку, переворачивает ее * и удаляет все гласные и выводит на экран. * Пример: input: Hello world! output: !dlrw llH */ class Cli { public function execute($params) { require_once __DIR__ . '/Autoload_psr4.php'; $invertor = new \Cli\Invertor\String(); $inverted = $invertor->getInverted($params[1]); $filter = new \Cli\Filter\String\Vowels(); $filtered = $filter->getFiltered($inverted); $template = new \Cli\Template\Php(); $template->setTemplate(__DIR__ . '/Cli/Template/tpl/output.php'); $output = $template->process(array('filtered' => $filtered)); echo $output; } } Cli::execute($argv);