project = $project; // The absolute path to the html output templates $this->templatePath = $templatePath; // https://github.com/symfony/Console/blob/master/Output/Output.php // the alternative is OutputInterface::OUTPUT_PLAIN; $this->outputFormat = OutputInterface::OUTPUT_NORMAL; // Exits on missing dependencies $this->checkDependencies(); // We do this now because we've loaded the project info from the composer file $this->setName($this->project->description); $this->setVersion($this->project->version); // Load our commands into the application $this->add(new Command\HtmlCommand()); $this->add(new Command\PdfCommand()); $this->add(new Command\StatsCommand()); $this->add(new Command\TemplatesCommand()); $this->add(new Command\VersionCommand()); // We'll use [Twig](http://twig.sensiolabs.org/) for template output $loader = new \Twig_Loader_Filesystem($consoleTemplatePath); $this->twig = new \Twig_Environment( $loader, array( "cache" => false, "autoescape" => false, "strict_variables" => false // SET TO TRUE WHILE DEBUGGING ) ); // These are helpers that we use to format output on the cli: styling and padding and such $this->twig->addFilter('pad', new \Twig_Filter_Function("Resume\Cli\TwigFormatters::strpad")); $this->twig->addFilter('style', new \Twig_Filter_Function("Resume\Cli\TwigFormatters::style")); $this->twig->addFilter('repeat', new \Twig_Filter_Function("str_repeat")); $this->twig->addFilter('wrap', new \Twig_Filter_Function("wordwrap")); } public function getLongVersion() { return parent::getLongVersion().' by Craig Davis'; } public function checkDependencies() { $output = new ConsoleOutput(); if (!extension_loaded('mbstring')) { $output->writeln( "\nMissing Dependency: Please install the Multibyte String Functions.\n" . "More help: http://www.php.net/manual/en/mbstring.installation.php\n", $this->outputFormat ); exit(1); } } public function registerStyles(&$output) { // https://github.com/symfony/Console/blob/master/Formatter/OutputFormatterStyle.php // http://symfony.com/doc/2.0/components/console/introduction.html#coloring-the-output // // * green // * yellow // * black text on a cyan background // * yellow // * white text on a red background // * red text on a yellow background // * blue // * black on white $style = new OutputFormatterStyle('red', 'yellow', array('bold')); $output->getFormatter()->setStyle('fire', $style); $style = new OutputFormatterStyle('blue', 'black', array()); $output->getFormatter()->setStyle('notice', $style); $style = new OutputFormatterStyle('red', 'black', array('bold')); $output->getFormatter()->setStyle('alert', $style); $style = new OutputFormatterStyle('white', 'black', array('bold')); $output->getFormatter()->setStyle('bold', $style); $style = new OutputFormatterStyle('black', 'white', array()); $output->getFormatter()->setStyle('heading', $style); $style = new OutputFormatterStyle('blue', 'black', array('bold')); $output->getFormatter()->setStyle('logo', $style); return $output; } public function statusStyle($status) { switch (true) { case (strpos(strtolower($status), 'closed') === 0): return 'alert'; case (strpos(strtolower($status), 'open') === 0): case (strpos(strtolower($status), 'active') === 0): return 'logo'; // fallthrough to final return } return "info"; } public function run(InputInterface $input = null, OutputInterface $output = null) { if (null === $input) { $input = new ArgvInput(); } if (null === $output) { $output = new ConsoleOutput(); } $this->registerStyles($output); // Did they supply a command name? $name = $this->getCommandName($input); if ($name) { // Does the command exist and is not ambiguous? try { $command = $this->find($name); } catch (\Exception $e) { exit($e->getMessage() . "\n"); } } return parent::run($input, $output); } } /* End of file Resume.php */