public function main() { $input = new \ezcConsoleInput(); $output = new \ezcConsoleOutput(); $input->registerOption(new \ezcConsoleOption('h', 'help')); $input->registerOption(new \ezcConsoleOption('p', 'process')); $input->process(); if ($input->getOption("p")->value) { $parser = new PHPLpm\Parser(); $result = $parser->parse(file_get_contents("_testdata/sample.php", 1)); $table = new \ezcConsoleTable($output, 60); $table[0][0]->content = "Class"; $table[0][1]->content = "Method"; $table[0][2]->content = "Lines"; $i = 1; foreach ($result as $class => $methods) { foreach ($methods as $method) { $row = $table[$i]; $row[0]->content = $class; $row[1]->content = $method["name"]; $row[2]->content = (string) $method["lines"]; $i++; } } $table->outputTable(); print "\n"; //print_r($result); } }
/** * Sets up the CLI option & argument definitions on the ezcConsoleInput member. * @return void */ protected function setupInput() { $this->input->registerOption(new \ezcConsoleOption('r', 'recursive', \ezcConsoleInput::TYPE_NONE)); $this->input->getOption('recursive')->shorthelp = 'Analyze directories recursively'; $this->input->registerOption(new \ezcConsoleOption('h', 'help')); $this->input->getOption('help')->isHelpOption = true; // if parameter is set, all options marked as mandatory may be skipped $this->input->getOption('help')->shorthelp = 'Display help'; $this->input->argumentDefinition = new \ezcConsoleArguments(); $this->input->argumentDefinition[0] = new \ezcConsoleArgument('sources', \ezcConsoleInput::TYPE_STRING, 'Files and/or directories to analyze', '', true, true); }
/** * Main method. */ public function main() { $input = new ezcConsoleInput(); $output = new ezcConsoleOutput(); $input->registerOption(new ezcConsoleOption('', 'count-tests', ezcConsoleInput::TYPE_NONE, FALSE, FALSE)); $input->registerOption(new ezcConsoleOption('', 'exclude', ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('', 'log-xml', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'log-csv', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'suffixes', ezcConsoleInput::TYPE_STRING, 'php', FALSE)); $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('', 'progress', ezcConsoleInput::TYPE_NONE)); try { $input->process(); } catch (ezcConsoleOptionException $e) { print $e->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { $this->showHelp(); exit(0); } else { if ($input->getOption('version')->value) { $this->printVersionString(); exit(0); } } $arguments = $input->getArguments(); if (empty($arguments)) { $this->showHelp(); exit(1); } $countTests = $input->getOption('count-tests')->value; $excludes = $input->getOption('exclude')->value; $logXml = $input->getOption('log-xml')->value; $logCsv = $input->getOption('log-csv')->value; $suffixes = array_map('trim', explode(',', $input->getOption('suffixes')->value)); if ($input->getOption('progress')->value !== FALSE) { $progress = $output; } else { $progress = NULL; } $this->printVersionString(); $files = $this->findFiles($arguments, $excludes, $suffixes); if (empty($files)) { $this->showError("No files found to scan.\n"); } $analyser = new PHPLOC_Analyser($progress); $count = $analyser->countFiles($files, $countTests); $printer = new PHPLOC_TextUI_ResultPrinter_Text(); $printer->printResult($count, $countTests); if ($logXml) { $printer = new PHPLOC_TextUI_ResultPrinter_XML(); $printer->printResult($logXml, $count); } if ($logCsv) { $printer = new PHPLOC_TextUI_ResultPrinter_CSV(); $printer->printResult($logCsv, $count); } }
/** * Main method. */ public static function main() { $input = new ezcConsoleInput(); $input->registerOption(new ezcConsoleOption('', 'bootstrap', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'class', ezcConsoleInput::TYPE_NONE)); $input->registerOption(new ezcConsoleOption('', 'test', ezcConsoleInput::TYPE_NONE)); $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); try { $input->process(); } catch (ezcConsoleOptionException $e) { print $e->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { self::showHelp(); exit(0); } else { if ($input->getOption('version')->value) { self::printVersionString(); exit(0); } } $arguments = $input->getArguments(); $bootstrap = $input->getOption('bootstrap')->value; $class = $input->getOption('class')->value; $test = $input->getOption('test')->value; if (empty($arguments) || !$class && !$test || $class && $test) { self::showHelp(); exit(1); } if ($class) { $reflector = new ReflectionClass('PHPUnit_SkeletonGenerator_Class'); } else { if ($test) { $reflector = new ReflectionClass('PHPUnit_SkeletonGenerator_Test'); } } self::printVersionString(); if ($bootstrap && file_exists($bootstrap)) { include $bootstrap; } $generator = $reflector->newInstanceArgs($arguments); $generator->write(); printf('Wrote skeleton for "%s" to "%s".' . "\n", $generator->getOutClassName(), $generator->getOutSourceFile()); exit(0); }
/** * Main method. */ public static function main() { $input = new ezcConsoleInput(); $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); try { $input->process(); } catch (ezcConsoleOptionException $e) { print $e->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { self::showHelp(); exit(0); } else { if ($input->getOption('version')->value) { self::printVersionString(); exit(0); } } $arguments = $input->getArguments(); if (empty($arguments)) { self::showHelp(); exit(1); } self::printVersionString(); print "Line Token Text\n" . str_repeat('-', 79) . "\n"; foreach (new PHP_Token_Stream($arguments[0]) as $token) { if ($token instanceof PHP_Token_WHITESPACE) { $text = ''; } else { $text = str_replace(array("\r", "\n"), '', (string) $token); if (strlen($text) > 40) { $text = explode("\n", wordwrap($text, 40)); $text = $text[0]; } } printf("%5d %-30s %s\n", $token->getLine(), str_replace('PHP_Token_', '', get_class($token)), $text); } }
/** * Create a new generator. * This method initializes the necessary objects to run the application. * * @return void */ public function __construct() { $schemaFormats = implode(", ", ezcDbSchemaHandlerManager::getSupportedFormats()); $this->output = new ezcConsoleOutput(); $this->output->options->autobreak = 80; $this->output->formats->info->color = 'blue'; $this->output->formats->info->style = array('bold'); $this->output->formats->help->color = 'blue'; $this->output->formats->error->color = 'red'; $this->output->formats->error->style = array('bold'); $this->output->formats->success->color = 'green'; $this->output->formats->success->style = array('bold'); $this->input = new ezcConsoleInput(); $this->input->registerOption(new ezcConsoleOption("s", "source", ezcConsoleInput::TYPE_STRING, null, false, "DatabaseSchema source to use.", "The DatabaseSchema to use for the generation of the PersistentObject definition. Or the DSN to the database to grab the schema from.", array(), array(), true, true)); $this->input->registerOption(new ezcConsoleOption("f", "format", ezcConsoleInput::TYPE_STRING, null, false, "DatabaseSchema format of the input source.", "The format, the input DatabaseSchema is in. Valid formats are {$schemaFormats}.", array(), array(), true, true)); $this->input->registerOption(new ezcConsoleOption("o", "overwrite", ezcConsoleInput::TYPE_NONE, null, false, "Overwrite existing files.", "If this option is set, files will be overwriten if they alreday exist.")); $this->input->registerOption(new ezcConsoleOption("p", "prefix", ezcConsoleInput::TYPE_STRING, null, false, "Class prefix.", "Unique prefix that will be prepended to all class names.", array(), array(), true, false)); $this->input->registerOption(new ezcConsoleOption("h", "help", ezcConsoleInput::TYPE_NONE, null, false, "Retrieve detailed help about this application.", "Print out this help information.", array(), array(), true, false, true)); $this->input->argumentDefinition = new ezcConsoleArguments(); $this->input->argumentDefinition[0] = new ezcConsoleArgument("def dir"); $this->input->argumentDefinition[0]->shorthelp = "PersistentObject definition directory."; $this->input->argumentDefinition[0]->longhelp = "Directory where PersistentObject definitions will be stored."; $this->input->argumentDefinition[1] = new ezcConsoleArgument("class dir"); $this->input->argumentDefinition[1]->mandatory = false; $this->input->argumentDefinition[1]->shorthelp = "Class directory."; $this->input->argumentDefinition[1]->longhelp = "Directory where PHP classes will be stored. Classes will not be generated if this argument is ommited."; $this->output->outputLine('eZ components PersistentObject definition generator', 'info'); $this->output->outputLine(); }
/** * Create a new generator. * This method initializes the necessary objects to run the application. * * @return void */ public function __construct() { $schemaFormats = implode(", ", ezcDbSchemaHandlerManager::getSupportedFormats()); $this->output = new ezcConsoleOutput(); $this->output->options->autobreak = 80; $this->output->formats->info->color = 'blue'; $this->output->formats->info->style = array('bold'); $this->output->formats->help->color = 'blue'; $this->output->formats->error->color = 'red'; $this->output->formats->error->style = array('bold'); $this->output->formats->success->color = 'green'; $this->output->formats->success->style = array('bold'); $this->input = new ezcConsoleInput(); $this->input->registerOption(new ezcConsoleOption("s", "source", ezcConsoleInput::TYPE_STRING, null, false, "DatabaseSchema source to use.", "The DatabaseSchema to use for the generation of the PersistentObject definition. Or the DSN to the database to grab the schema from.", array(), array(), true, true)); $this->input->registerOption(new ezcConsoleOption("f", "format", ezcConsoleInput::TYPE_STRING, null, false, "DatabaseSchema format of the input source.", "The format, the input DatabaseSchema is in. Valid formats are {$schemaFormats}.", array(), array(), true, true)); $this->input->registerOption(new ezcConsoleOption("o", "overwrite", ezcConsoleInput::TYPE_NONE, null, false, "Overwrite existing files.", "If this option is set, files will be overwriten if they alreday exist.")); $this->input->registerOption(new ezcConsoleOption("p", "prefix", ezcConsoleInput::TYPE_STRING, null, false, "Class prefix.", "Unique prefix that will be prepended to all class names.", array(), array(), true, false)); $this->input->registerOption(new ezcConsoleOption("t", "template", ezcConsoleInput::TYPE_NONE, null, false, "Use template rendering.", "Switch on template rendering. Use --class-template, --definition-template, --template-path to customize.", array(), array(), true, false)); $this->input->registerOption(new ezcConsoleOption("ct", "class-template", ezcConsoleInput::TYPE_STRING, 'class_template.ezt', false, "Class template.", "Template file to use for writing class stubs, defaults to eZ Components style classes. Look at default template to customize.", array(), array(), true, false)); $this->input->registerOption(new ezcConsoleOption("dt", "definition-template", ezcConsoleInput::TYPE_STRING, 'definition_template.ezt', false, "Definition template.", "Template file to use for writing definition stubs, defaults configs fitting the default class template. Look at default template to customize.", array(), array(), true, false)); $this->input->registerOption(new ezcConsoleOption("tp", "template-path", ezcConsoleInput::TYPE_STRING, dirname(__FILE__) . '/template_writer/templates', false, "Base template path.", "Path where templates are located. Will also by used as the path to compile templates to.", array(), array(), true, false)); $this->input->registerOption(new ezcConsoleOption("h", "help", ezcConsoleInput::TYPE_NONE, null, false, "Retrieve detailed help about this application.", "Print out this help information.", array(), array(), true, false, true)); $this->input->getOption('template-path')->addDependency(new ezcConsoleOptionRule($this->input->getOption('template'))); $this->input->getOption('definition-template')->addDependency(new ezcConsoleOptionRule($this->input->getOption('template'))); $this->input->getOption('class-template')->addDependency(new ezcConsoleOptionRule($this->input->getOption('template'))); $this->input->argumentDefinition = new ezcConsoleArguments(); $this->input->argumentDefinition[0] = new ezcConsoleArgument("def dir"); $this->input->argumentDefinition[0]->shorthelp = "PersistentObject definition directory."; $this->input->argumentDefinition[0]->longhelp = "Directory where PersistentObject definitions will be stored."; $this->input->argumentDefinition[1] = new ezcConsoleArgument("class dir"); $this->input->argumentDefinition[1]->mandatory = false; $this->input->argumentDefinition[1]->shorthelp = "Class directory."; $this->input->argumentDefinition[1]->longhelp = "Directory where PHP classes will be stored. Classes will not be generated if this argument is ommited."; $this->output->outputLine('eZ components PersistentObject definition generator', 'info'); $this->output->outputLine(); }
/** * Create a new generator. * This method initializes the necessary objects to run the application. */ public function __construct() { $this->output = new ezcConsoleOutput(); $this->output->options->autobreak = 80; $this->output->formats->info->color = 'blue'; $this->output->formats->info->style = array('bold'); $this->output->formats->help->color = 'blue'; $this->output->formats->error->color = 'red'; $this->output->formats->error->style = array('bold'); $this->output->formats->success->color = 'green'; $this->output->formats->success->style = array('bold'); $this->input = new ezcConsoleInput(); $this->input->registerOption(new ezcConsoleOption("t", "templates", ezcConsoleInput::TYPE_STRING, null, false, "Template directory to search for translatable strings.", "A directory with eZ Components template files. It is searched recursivly for new translatable strings.", array(), array(), true, true)); $this->input->registerOption(new ezcConsoleOption("f", "format", ezcConsoleInput::TYPE_STRING, '[LOCALE].xml', false, "File name format of translation file.", "The file format the generated translation files should get. The string \"[LOCALE]\" is automatically replaced with the locale name.", array(), array(), true, false)); $this->input->registerOption(new ezcConsoleOption("l", "locale", ezcConsoleInput::TYPE_STRING, 'en', false, "Template locale.", "The locale of the strings within the templates.", array(), array(), true, false)); $this->input->registerOption(new ezcConsoleOption("o", "overwrite", ezcConsoleInput::TYPE_NONE, null, false, "Overwrite existing files.", "If this option is set, files will be overwriten if they already exist.", array(), array(), true, false)); $this->input->registerOption(new ezcConsoleOption("h", "help", ezcConsoleInput::TYPE_NONE, null, false, "Retrieve detailed help about this application.", "Print out this help information.", array(), array(), true, false, true)); $this->input->argumentDefinition = new ezcConsoleArguments(); $this->input->argumentDefinition[0] = new ezcConsoleArgument("translation dir"); $this->input->argumentDefinition[0]->shorthelp = "Translation file directory."; $this->input->argumentDefinition[0]->longhelp = "Directory where translation files will be stored."; $this->output->outputLine('eZ components extractor for translatable strings in templates.', 'info'); $this->output->outputLine(); }
/** * Main method. */ public function main() { $input = new ezcConsoleInput(); $output = new ezcConsoleOutput(); $input->registerOption(new ezcConsoleOption('', 'exclude', ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('', 'recursive', ezcConsoleInput::TYPE_NONE)); $input->registerOption(new ezcConsoleOption('', 'suffixes', ezcConsoleInput::TYPE_STRING, 'php', FALSE)); $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('', 'verbose', ezcConsoleInput::TYPE_NONE)); try { $input->process(); } catch (ezcConsoleOptionException $e) { print $e->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { $this->showHelp(); exit(0); } else { if ($input->getOption('version')->value) { $this->printVersionString(); exit(0); } } $arguments = $input->getArguments(); if (empty($arguments)) { $this->showHelp(); exit(1); } $excludes = $input->getOption('exclude')->value; $recursive = $input->getOption('recursive')->value; $suffixes = explode(',', $input->getOption('suffixes')->value); array_map('trim', $suffixes); if ($input->getOption('verbose')->value !== FALSE) { $verbose = $output; } else { $verbose = NULL; } $this->printVersionString(); $files = $this->findFiles($arguments, $excludes, $suffixes); if (empty($files)) { $this->showError("No files found to scan.\n"); } $detector = new PHPDCD_Detector($verbose); $result = $detector->detectDeadCode($files, $recursive); $printer = new PHPDCD_TextUI_ResultPrinter(); $printer->printResult($result, $commonPath); unset($printer); }
if ($file == '.' || $file == '..') { continue; } if (is_dir($dir . '/' . $file)) { $fileList[] = array('path' => $path, 'name' => $file, 'type' => 'dir'); recursiveList($dir . '/' . $file, $path . '/' . $file, $fileList); } else { $fileList[] = array('path' => $path, 'name' => $file, 'type' => 'file'); } } @closedir($handle); } } $input = new ezcConsoleInput(); $output = new ezcConsoleOutput(); $helpOption = $input->registerOption(new ezcConsoleOption('h', 'help')); $helpOption->isHelpOption = true; $helpOption->shorthelp = 'Display current help information.'; $extensionOption = $input->registerOption(new ezcConsoleOption('e', 'extension', ezcConsoleInput::TYPE_STRING)); $extensionOption->mandatory = true; $extensionOption->shorthelp = 'Full path to the eZ Publish extension e.g \'/home/ls/public_html/ezp/extension/myextension\''; $extensionNameOption = $input->registerOption(new ezcConsoleOption('n', 'extension-name', ezcConsoleInput::TYPE_STRING)); $extensionNameOption->mandatory = true; $extensionNameOption->shorthelp = 'Extension name. e.g \'myextension\''; try { $input->process(); } catch (ezcConsoleOptionException $e) { $output->outputLine($e->getMessage()); exit; } if ($helpOption->value === true) {
if ($baseEnabled) { spl_autoload_register(array('ezcBase', 'autoload')); } require 'kernel/private/classes/ezautoloadgenerator.php'; require 'kernel/private/interfaces/ezpautoloadoutput.php'; require 'kernel/private/classes/ezpautoloadclioutput.php'; require 'kernel/private/options/ezpautoloadgeneratoroptions.php'; require 'kernel/private/structs/ezpautoloadfilefindcontext.php'; //} // Setup console parameters //{ $params = new ezcConsoleInput(); $helpOption = new ezcConsoleOption('h', 'help'); $helpOption->mandatory = false; $helpOption->shorthelp = "Show help information"; $params->registerOption($helpOption); $targetOption = new ezcConsoleOption('t', 'target', ezcConsoleInput::TYPE_STRING); $targetOption->mandatory = false; $targetOption->shorthelp = "The directory to where the generated autoload file should be written."; $params->registerOption($targetOption); $verboseOption = new ezcConsoleOption('v', 'verbose', ezcConsoleInput::TYPE_NONE); $verboseOption->mandatory = false; $verboseOption->shorthelp = "Whether or not to display more information."; $params->registerOption($verboseOption); $dryrunOption = new ezcConsoleOption('n', 'dry-run', ezcConsoleInput::TYPE_NONE); $dryrunOption->mandatory = false; $dryrunOption->shorthelp = "Whether a new file autoload file should be written."; $params->registerOption($dryrunOption); $kernelFilesOption = new ezcConsoleOption('k', 'kernel', ezcConsoleInput::TYPE_NONE); $kernelFilesOption->mandatory = false; $kernelFilesOption->shorthelp = "If an autoload array for the kernel files should be generated.";
public function testGetHelpTextBinarySafe() { $input = new ezcConsoleInput(); $input->registerOption(new ezcConsoleOption('ö', 'öder', ezcConsoleInput::TYPE_NONE, null, false, 'ööö äää ööö äää', 'ööö äää ööö äää ööö äää ööö äää ööö äää ööö äää')); $res = "Usage: \$ {$_SERVER['argv'][0]} [-ö] [[--] <args>]" . PHP_EOL . 'Test with UTF-8' . PHP_EOL . 'characters...' . PHP_EOL . '' . PHP_EOL . '-ö / --öder ööö äää' . PHP_EOL . ' ööö äää' . PHP_EOL . ' ööö äää' . PHP_EOL . ' ööö äää' . PHP_EOL . ' ööö äää' . PHP_EOL . ' ööö äää' . PHP_EOL; $this->assertEquals($res, $input->getHelpText('Test with UTF-8 characters...', 20, true), 'Help text not generated correctly.'); }
/** * Main method. */ public static function main() { $input = new ezcConsoleInput(); $input->registerOption(new ezcConsoleOption('', 'clover', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'html', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'blacklist', ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new ezcConsoleOption('', 'whitelist', ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new ezcConsoleOption('', 'merge', ezcConsoleInput::TYPE_NONE, FALSE)); $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); try { $input->process(); } catch (ezcConsoleOptionException $e) { print $e->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { self::showHelp(); exit(0); } else { if ($input->getOption('version')->value) { self::printVersionString(); exit(0); } } $arguments = $input->getArguments(); $clover = $input->getOption('clover')->value; $html = $input->getOption('html')->value; $blacklist = $input->getOption('blacklist')->value; $whitelist = $input->getOption('whitelist')->value; $merge = $input->getOption('merge')->value; if (count($arguments) == 1) { self::printVersionString(); $coverage = new PHP_CodeCoverage(); $filter = $coverage->filter(); if (empty($whitelist)) { $c = new ReflectionClass('ezcBase'); $filter->addDirectoryToBlacklist(dirname($c->getFileName())); $c = new ReflectionClass('ezcConsoleInput'); $filter->addDirectoryToBlacklist(dirname($c->getFileName())); foreach ($blacklist as $item) { if (is_dir($item)) { $filter->addDirectoryToBlacklist($item); } else { if (is_file($item)) { $filter->addFileToBlacklist($item); } } } } else { foreach ($whitelist as $item) { if (is_dir($item)) { $filter->addDirectoryToWhitelist($item); } else { if (is_file($item)) { $filter->addFileToWhitelist($item); } } } } if (!$merge) { $coverage->start('phpcov'); require $arguments[0]; $coverage->stop(); } else { $facade = new File_Iterator_Facade(); $result = $facade->getFilesAsArray($arguments[0], '.cov'); foreach ($files as $file) { $coverage->merge(unserialize(file_get_contents($file))); } } if ($clover) { $writer = new PHP_CodeCoverage_Report_Clover(); $writer->process($coverage, $clover); } if ($html) { $writer = new PHP_CodeCoverage_Report_HTML(); $writer->process($coverage, $html); } } else { self::showHelp(); exit(1); } }
/** * Main method. */ public function main() { $input = new \ezcConsoleInput(); $input->registerOption(new \ezcConsoleOption('', 'exclude', \ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new \ezcConsoleOption('h', 'help', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new \ezcConsoleOption('', 'log-pmd', \ezcConsoleInput::TYPE_STRING)); $input->registerOption(new \ezcConsoleOption('', 'min-lines', \ezcConsoleInput::TYPE_INT, 5)); $input->registerOption(new \ezcConsoleOption('', 'min-tokens', \ezcConsoleInput::TYPE_INT, 70)); $input->registerOption(new \ezcConsoleOption('', 'names', \ezcConsoleInput::TYPE_STRING, '*.php', FALSE)); $input->registerOption(new \ezcConsoleOption('', 'quiet', \ezcConsoleInput::TYPE_NONE, NULL, FALSE)); $input->registerOption(new \ezcConsoleOption('v', 'version', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new \ezcConsoleOption('', 'progress', \ezcConsoleInput::TYPE_NONE)); $input->registerOption(new \ezcConsoleOption('', 'verbose', \ezcConsoleInput::TYPE_NONE)); try { $input->process(); } catch (\ezcConsoleOptionException $e) { print $e->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { $this->showHelp(); exit(0); } else { if ($input->getOption('version')->value) { $this->printVersionString(); exit(0); } } $arguments = $input->getArguments(); if (empty($arguments)) { $this->showHelp(); exit(1); } $excludes = $input->getOption('exclude')->value; $logPmd = $input->getOption('log-pmd')->value; $minLines = $input->getOption('min-lines')->value; $minTokens = $input->getOption('min-tokens')->value; $names = explode(',', $input->getOption('names')->value); $quiet = $input->getOption('quiet')->value; $verbose = $input->getOption('verbose')->value; array_map('trim', $names); if ($input->getOption('progress')->value !== FALSE) { $output = new \ezcConsoleOutput(); } else { $output = NULL; } $this->printVersionString(); $finder = new FinderFacade($arguments, $excludes, $names); $files = $finder->findFiles(); if (empty($files)) { $this->showError("No files found to scan.\n"); } $strategy = new DefaultStrategy(); $detector = new Detector($strategy, $output); $clones = $detector->copyPasteDetection($files, $minLines, $minTokens); $printer = new ResultPrinter(); $printer->printResult($clones, !$quiet, $verbose); unset($printer); if ($logPmd) { $pmd = new PMD($logPmd); $pmd->processClones($clones); unset($pmd); } if (count($clones) > 0) { exit(1); } }
/** * Sets up all the input options (cli arguments) * * @param ezcConsoleInput $input A not configured input instance * @return ezcConsoleInput Fully configured input instance */ protected function cliInputOptions( $input ) { $this->siteAccessOption = $input->registerOption( new ezcConsoleOption( 's', 'siteaccess', ezcConsoleInput::TYPE_STRING, null, false, "Which siteaccess to use" )); $this->helpOption = $input->registerOption( new ezcConsoleOption( 'h', 'help', ezcConsoleInput::TYPE_NONE, null, false, "Display this help message" )); $this->dryRunOption = $input->registerOption( new ezcConsoleOption( 'd', 'dry-run', ezcConsoleInput::TYPE_NONE, null, false, "Output what will be cleaned up" )); $this->subtreeNodeOption = $input->registerOption( new ezcConsoleOption( 't', 'subtree', ezcConsoleInput::TYPE_STRING, null, false, "Node id of subtree to process" )); $this->subtreeNodeOption->mandatory = true; $this->actionOption = $input->registerOption( new ezcConsoleOption( 'a', 'action', ezcConsoleInput::TYPE_STRING, null, false, "Which cleanup action to take 'unpublish' or 'orphans'" )); $this->actionOption->mandatory = true; return $input; }
/** * Main method. */ public function main() { $input = new \ezcConsoleInput(); $input->registerOption(new \ezcConsoleOption('', 'clover', \ezcConsoleInput::TYPE_STRING)); $input->registerOption(new \ezcConsoleOption('', 'configuration', \ezcConsoleInput::TYPE_STRING)); $input->registerOption(new \ezcConsoleOption('', 'html', \ezcConsoleInput::TYPE_STRING)); $input->registerOption(new \ezcConsoleOption('', 'php', \ezcConsoleInput::TYPE_STRING)); $input->registerOption(new \ezcConsoleOption('', 'text', \ezcConsoleInput::TYPE_STRING)); $input->registerOption(new \ezcConsoleOption('', 'blacklist', \ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new \ezcConsoleOption('', 'whitelist', \ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new \ezcConsoleOption('', 'merge', \ezcConsoleInput::TYPE_NONE, FALSE)); $input->registerOption(new \ezcConsoleOption('', 'add-uncovered', \ezcConsoleInput::TYPE_NONE, FALSE)); $input->registerOption(new \ezcConsoleOption('', 'process-uncovered', \ezcConsoleInput::TYPE_NONE, FALSE)); $input->registerOption(new \ezcConsoleOption('h', 'help', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new \ezcConsoleOption('v', 'version', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); try { $input->process(); } catch (ezcConsoleOptionException $e) { print $e->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { $this->showHelp(); exit(0); } else { if ($input->getOption('version')->value) { $this->printVersionString(); exit(0); } } $arguments = $input->getArguments(); $clover = $input->getOption('clover')->value; $configuration = $input->getOption('configuration')->value; $html = $input->getOption('html')->value; $php = $input->getOption('php')->value; $text = $input->getOption('text')->value; $blacklist = $input->getOption('blacklist')->value; $whitelist = $input->getOption('whitelist')->value; $addUncovered = $input->getOption('add-uncovered')->value; $processUncovered = $input->getOption('process-uncovered')->value; $merge = $input->getOption('merge')->value; $coverage = new \PHP_CodeCoverage(); $filter = $coverage->filter(); if ($configuration) { $this->handleConfiguration($configuration, $coverage); } if (count($arguments) == 1) { $this->printVersionString(); if (empty($whitelist)) { $c = new \ReflectionClass('ezcBase'); $filter->addDirectoryToBlacklist(dirname($c->getFileName())); $c = new \ReflectionClass('ezcConsoleInput'); $filter->addDirectoryToBlacklist(dirname($c->getFileName())); foreach ($blacklist as $item) { if (is_dir($item)) { $filter->addDirectoryToBlacklist($item); } else { if (is_file($item)) { $filter->addFileToBlacklist($item); } } } } else { $coverage->setAddUncoveredFilesFromWhitelist($addUncovered); $coverage->setProcessUncoveredFilesFromWhitelist($processUncovered); foreach ($whitelist as $item) { if (is_dir($item)) { $filter->addDirectoryToWhitelist($item); } else { if (is_file($item)) { $filter->addFileToWhitelist($item); } } } } if (!$merge) { $coverage->start('phpcov'); require $arguments[0]; $coverage->stop(); } else { $facade = new \File_Iterator_Facade(); $files = $facade->getFilesAsArray($arguments[0], '.cov'); foreach ($files as $file) { $coverage->merge(unserialize(file_get_contents($file))); } } if ($clover) { print "\nGenerating code coverage report in Clover XML format ..."; $writer = new \PHP_CodeCoverage_Report_Clover(); $writer->process($coverage, $clover); print " done\n"; } if ($html) { print "\nGenerating code coverage report in HTML format ..."; $writer = new \PHP_CodeCoverage_Report_HTML(); $writer->process($coverage, $html); print " done\n"; } if ($php) { print "\nGenerating code coverage report in PHP format ..."; $writer = new \PHP_CodeCoverage_Report_PHP(); $writer->process($coverage, $php); print " done\n"; } if ($text) { $writer = new \PHP_CodeCoverage_Report_Text(); $writer->process($coverage, $text); } } else { $this->showHelp(); exit(1); } }
/** * Helper to register and process supported CLI options into an ezcConsoleInput * * @throws CLIOptionsException * @return CLIOptions */ protected function processOptions() { $input = new \ezcConsoleInput(); $versionOption = $input->registerOption(new \ezcConsoleOption('v', 'version')); $versionOption->shorthelp = 'Prints the version and exits'; $versionOption->isHelpOption = TRUE; $helpOption = $input->registerOption(new \ezcConsoleOption('h', 'help')); $helpOption->isHelpOption = TRUE; $helpOption->shorthelp = 'Prints this usage information'; $input->registerOption(new \ezcConsoleOption('f', 'file', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Configuration file to load')); $c = $input->registerOption(new \ezcConsoleOption('c', 'collector', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Run collector process only')); $g = $input->registerOption(new \ezcConsoleOption('g', 'generator', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Run generator process only')); $g->addExclusion(new \ezcConsoleOptionRule($c)); $c->addExclusion(new \ezcConsoleOptionRule($g)); $input->registerOption(new \ezcConsoleOption(NULL, 'engines', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Show a list of available engines and exit')); $input->registerOption(new \ezcConsoleOption(NULL, 'enrichers', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Show a list of available enrichers and exit')); $input->registerOption(new \ezcConsoleOption(NULL, 'backends', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Show a list of available backends and exit')); $skel = $input->registerOption(new \ezcConsoleOption(NULL, 'skel', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Show a skeleton config xml file and exit')); $strip = $input->registerOption(new \ezcConsoleOption(NULL, 'strip', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Strip xml config when showing')); $strip->addDependency(new \ezcConsoleOptionRule($skel)); try { $input->process(); return new CLIOptions($input); } catch (\ezcConsoleException $e) { throw new CLIOptionsException($e->getMessage(), $e->getCode()); } }
* @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved. * @license http://ez.no/licenses/new_bsd New BSD License */ require_once 'Base/src/base.php'; /** * Autoload ezc classes * * @param string $className */ function __autoload($className) { ezcBase::autoload($className); } $optionHandler = new ezcConsoleInput(); // Register simple parameter -h/--help $optionHandler->registerOption(new ezcConsoleOption('h', 'help')); // Register complex parameter -f/--file $file = new ezcConsoleOption('f', 'file', ezcConsoleInput::TYPE_STRING, null, false, 'Process a file.', 'Processes a single file.'); $optionHandler->registerOption($file); // Manipulate parameter -f/--file after registration $file->multiple = true; // Register another complex parameter that depends on -f and excludes -h $dir = new ezcConsoleOption('d', 'dir', ezcConsoleInput::TYPE_STRING, null, true, 'Process a directory.', 'Processes a complete directory.', array(new ezcConsoleOptionRule($optionHandler->getOption('f'))), array(new ezcConsoleOptionRule($optionHandler->getOption('h')))); $optionHandler->registerOption($dir); // Register an alias for this parameter $optionHandler->registerAlias('e', 'extended-dir', $dir); // Process registered parameters and handle errors try { $optionHandler->process(array('example_input.php', '-h')); } catch (ezcConsoleOptionException $e) { echo $e->getMessage();
/** * Main method. */ public static function main() { $input = new ezcConsoleInput(); $output = new ezcConsoleOutput(); $input->registerOption(new ezcConsoleOption('', 'exclude', ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('', 'log-pmd', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'min-lines', ezcConsoleInput::TYPE_INT, 5)); $input->registerOption(new ezcConsoleOption('', 'min-tokens', ezcConsoleInput::TYPE_INT, 70)); $input->registerOption(new ezcConsoleOption('', 'save-memory', ezcConsoleInput::TYPE_NONE, NULL, FALSE)); $input->registerOption(new ezcConsoleOption('', 'suffixes', ezcConsoleInput::TYPE_STRING, 'php', FALSE)); $input->registerOption(new ezcConsoleOption('', 'quiet', ezcConsoleInput::TYPE_NONE, NULL, FALSE)); $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('', 'verbose', ezcConsoleInput::TYPE_NONE)); try { $input->process(); } catch (ezcConsoleOptionException $e) { print $e->getMessage() . PHP_EOL; exit(1); } if ($input->getOption('help')->value) { self::showHelp(); exit(0); } else { if ($input->getOption('version')->value) { self::printVersionString(); exit(0); } } $arguments = $input->getArguments(); $exclude = $input->getOption('exclude')->value; if (is_array($exclude) && count($exclude) == 1) { array_map('trim', explode(',', array_pop($exclude))); } $logPmd = $input->getOption('log-pmd')->value; $minLines = $input->getOption('min-lines')->value; $minTokens = $input->getOption('min-tokens')->value; $saveMemory = $input->getOption('save-memory')->value; $suffixes = array_map('trim', explode(',', $input->getOption('suffixes')->value)); $quiet = $input->getOption('quiet')->value; if ($input->getOption('verbose')->value !== FALSE) { $verbose = $output; } else { $verbose = NULL; } if (!empty($arguments)) { $facade = new File_Iterator_Facade(); $result = $facade->getFilesAsArray($arguments, $suffixes, array(), $exclude, TRUE); $files = $result['files']; $commonPath = $result['commonPath']; unset($result); } else { self::showHelp(); exit(1); } if (empty($files)) { self::showError('No files found to scan.' . PHP_EOL); } self::printVersionString(); if (!$saveMemory) { $strategy = new PHPCPD_Detector_Strategy_Default(); } else { $strategy = new PHPCPD_Detector_Strategy_SaveMemory(); } $detector = new PHPCPD_Detector($strategy, $verbose); $clones = $detector->copyPasteDetection($files, $minLines, $minTokens); $printer = new PHPCPD_TextUI_ResultPrinter(); $printer->printResult($clones, $commonPath, !$quiet); unset($printer); if ($logPmd) { $pmd = new PHPCPD_Log_XML_PMD($logPmd); $pmd->processClones($clones); unset($pmd); } if (count($clones) > 0) { exit(1); } }
/** * Main method. */ public static function main() { $input = new ezcConsoleInput(); $input->registerOption(new ezcConsoleOption('', 'clover', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'html', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'php', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'text', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'blacklist', ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new ezcConsoleOption('', 'whitelist', ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new ezcConsoleOption('', 'merge', ezcConsoleInput::TYPE_NONE, FALSE)); $input->registerOption(new ezcConsoleOption('', 'add-uncovered', ezcConsoleInput::TYPE_NONE, FALSE)); $input->registerOption(new ezcConsoleOption('', 'process-uncovered', ezcConsoleInput::TYPE_NONE, FALSE)); $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); try { $input->process(); } catch (ezcConsoleOptionException $e) { print $e->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { self::showHelp(); exit(0); } else { if ($input->getOption('version')->value) { self::printVersionString(); exit(0); } } $arguments = $input->getArguments(); $clover = $input->getOption('clover')->value; $html = $input->getOption('html')->value; $php = $input->getOption('php')->value; $text = $input->getOption('text')->value; $blacklist = $input->getOption('blacklist')->value; $whitelist = $input->getOption('whitelist')->value; $addUncovered = $input->getOption('add-uncovered')->value; $processUncovered = $input->getOption('process-uncovered')->value; $merge = $input->getOption('merge')->value; if (count($arguments) == 1) { self::printVersionString(); $coverage = new PHP_CodeCoverage(); $filter = $coverage->filter(); if (empty($whitelist)) { $c = new ReflectionClass('ezcBase'); $filter->addDirectoryToBlacklist(dirname($c->getFileName())); $c = new ReflectionClass('ezcConsoleInput'); $filter->addDirectoryToBlacklist(dirname($c->getFileName())); foreach ($blacklist as $item) { if (is_dir($item)) { $filter->addDirectoryToBlacklist($item); } else { if (is_file($item)) { $filter->addFileToBlacklist($item); } } } } else { $coverage->setAddUncoveredFilesFromWhitelist($addUncovered); $coverage->setProcessUncoveredFilesFromWhitelist($processUncovered); foreach ($whitelist as $item) { if (is_dir($item)) { $filter->addDirectoryToWhitelist($item); } else { if (is_file($item)) { $filter->addFileToWhitelist($item); } } } } if (!$merge) { $coverage->start('phpcov'); require $arguments[0]; $coverage->stop(); } else { $finder = new Symfony\Component\Finder\Finder(); $finder->in($arguments[0])->name('*.cov'); foreach ($finder as $file) { $coverage->merge(unserialize(file_get_contents($file->getRealpath()))); } } if ($clover) { $writer = new PHP_CodeCoverage_Report_Clover(); $writer->process($coverage, $clover); } if ($html) { $writer = new PHP_CodeCoverage_Report_HTML(); $writer->process($coverage, $html); } if ($php) { $writer = new PHP_CodeCoverage_Report_PHP(); $writer->process($coverage, $php); } if ($text) { $writer = new PHP_CodeCoverage_Report_Text(); $writer->process($coverage, $text); } } else { self::showHelp(); exit(1); } }
} return $res; } $out = new ezcConsoleOutput(); $out->formats->error->color = 'red'; $out->formats->error->style = array('bold'); $out->formats->error->target = ezcConsoleOutput::TARGET_STDERR; $out->formats->headline_1->color = 'green'; $out->formats->headline_1->style = array('bold'); $out->formats->headline_2->color = 'cyan'; $out->formats->headline_2->style = array('bold'); $out->formats->headline_3->color = 'blue'; $out->formats->border->color = 'gray'; $out->formats->border->style = array('bold'); $in = new ezcConsoleInput(); $helpOpt = $in->registerOption(new ezcConsoleOption('h', 'help')); $helpOpt->isHelpOption = true; $helpOpt->shorthelp = 'Print help information.'; $helpOpt->longhelp = 'Display this help information about the program.'; $suiteOpt = $in->registerOption(new ezcConsoleOption('s', 'suite', ezcConsoleInput::TYPE_STRING, '*')); $suiteOpt->shorthelp = 'Path pattern defining the client test suites to display data for.'; $suiteOpt->longhelp = 'This option may contain a path pattern as understood by glob(), defining the client test suites to display data for. An example would be "rfc" to only see the rfc tests or "r*" to see all suites starting with "r".'; $testOpt = $in->registerOption(new ezcConsoleOption('t', 'test', ezcConsoleInput::TYPE_STRING, '*')); $testOpt->shorthelp = 'Path pattern defining the test cases to display data for.'; $testOpt->longhelp = 'This option may contain a path pattern as understood by glob(), defining the test cases to display data for. An example would be "get_*" to only see all test cases that start with "get_".'; $noColorOpt = $in->registerOption(new ezcConsoleOption('n', 'no-color')); $noColorOpt->shorthelp = 'Switch of use of format codes (for logging).'; $noColorOpt->longhelp = 'Switches of the use of shell formatting codes, like color and style. This is particularly useful if you want to log the generated output.'; try { $in->process(); } catch (ezcConsoleException $e) {
/** * @return \ezcConsoleInput */ protected function setupInput() { $input = new \ezcConsoleInput(); $this->versionOption = $input->registerOption(new \ezcConsoleOption('v', 'version')); $this->versionOption->shorthelp = 'Prints the version and exits'; $this->versionOption->isHelpOption = TRUE; $this->helpOption = $input->registerOption(new \ezcConsoleOption('h', 'help')); $this->helpOption->isHelpOption = TRUE; $this->helpOption->shorthelp = 'Prints this usage information'; $input->registerOption(new \ezcConsoleOption('', 'cache', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Enable cache and set cache filename')); $this->outputOption = $input->registerOption(new \ezcConsoleOption('o', 'output', \ezcConsoleInput::TYPE_STRING, 'STDOUT', FALSE, 'Output file for generated code (default: STDOUT)')); $this->pharOption = $input->registerOption(new \ezcConsoleOption('p', 'phar', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Build a phar archive of directory contents', NULL, array(new \ezcConsoleOptionRule($input->getOption('o'))))); $input->registerOption(new \ezcConsoleOption('', 'all', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Add all files from src dir to phar', NULL, array(new \ezcConsoleOptionRule($input->getOption('p'))))); $input->registerOption(new \ezcConsoleOption('', 'alias', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Provide explicit internal alias filename for phar', NULL, array(new \ezcConsoleOptionRule($input->getOption('p'))))); $bzip2 = $input->registerOption(new \ezcConsoleOption('', 'bzip2', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Compress files phar with bzip2', NULL, array(new \ezcConsoleOptionRule($input->getOption('p'))))); $gzip = $input->registerOption(new \ezcConsoleOption('', 'gzip', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Compress files phar with gzip', NULL, array(new \ezcConsoleOptionRule($input->getOption('p'))), array(new \ezcConsoleOptionRule($bzip2)))); $bzip2->addExclusion(new \ezcConsoleOptionRule($gzip)); $input->registerOption(new \ezcConsoleOption('', 'key', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Keyfile to use for signing phar archive', NULL, array(new \ezcConsoleOptionRule($input->getOption('p'))))); $this->outputOption = $input->registerOption(new \ezcConsoleOption('', 'hash', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Force given hash algorithm (SHA-1, SHA-256 or SHA-512) (requires -p)', NULL, array(new \ezcConsoleOptionRule($input->getOption('p'))), array(new \ezcConsoleOptionRule($input->getOption('key'))))); $input->registerOption(new \ezcConsoleOption('i', 'include', \ezcConsoleInput::TYPE_STRING, '*.php', TRUE, 'File pattern to include (default: *.php)')); $input->registerOption(new \ezcConsoleOption('', 'blacklist', \ezcConsoleInput::TYPE_STRING, NULL, TRUE, 'Name pattern to exclude')); $input->registerOption(new \ezcConsoleOption('', 'whitelist', \ezcConsoleInput::TYPE_STRING, '*', TRUE, 'Name pattern to include (default: *)')); $input->registerOption(new \ezcConsoleOption('e', 'exclude', \ezcConsoleInput::TYPE_STRING, NULL, TRUE, 'File pattern to exclude')); $input->registerOption(new \ezcConsoleOption('b', 'basedir', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Basedir for filepaths')); $input->registerOption(new \ezcConsoleOption('t', 'template', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Path to code template to use')); $input->registerOption(new \ezcConsoleOption('', 'follow', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Enables following symbolic links', NULL, array(), array(new \ezcConsoleOptionRule($this->pharOption)))); $input->registerOption(new \ezcConsoleOption('', 'format', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Dateformat string for timestamp')); $input->registerOption(new \ezcConsoleOption('', 'linebreak', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'Linebreak style (CR, CR/LF or LF)')); $input->registerOption(new \ezcConsoleOption('', 'indent', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'String used for indenting (default: 3 spaces)')); $this->lintOption = $input->registerOption(new \ezcConsoleOption('', 'lint', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Run lint on generated code')); $input->registerOption(new \ezcConsoleOption('', 'lint-php', \ezcConsoleInput::TYPE_STRING, NULL, FALSE, 'PHP binary path for linting (default: /usr/bin/php or c:\\php\\php.exe)', NULL, array(new \ezcConsoleOptionRule($input->getOption('lint'))))); $compat = $input->registerOption(new \ezcConsoleOption('c', 'compat', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Generate PHP 5.2 compliant code')); $this->staticOption = $input->registerOption(new \ezcConsoleOption('s', 'static', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Build a static require file')); $input->registerOption(new \ezcConsoleOption('', 'tolerant', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Ignore Class Redeclarations in the same file')); $trusting = $input->registerOption(new \ezcConsoleOption('', 'trusting', \ezcConsoleInput::TYPE_NONE, TRUE, FALSE, 'Do not check mimetype of files prior to parsing')); $paranoid = $input->registerOption(new \ezcConsoleOption('', 'paranoid', \ezcConsoleInput::TYPE_NONE, FALSE, FALSE, 'Do check mimetype of files prior to parsing', NULL, array(), array(new \ezcConsoleOptionRule($trusting)))); $trusting->addExclusion(new \ezcConsoleOptionRule($paranoid)); $this->onceOption = $input->registerOption(new \ezcConsoleOption('', 'once', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Use require_once in static require mode', NULL, array(new \ezcConsoleOptionRule($input->getOption('s'))))); $input->registerOption(new \ezcConsoleOption('n', 'nolower', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Do not lowercase classnames for case insensitivity')); $input->registerOption(new \ezcConsoleOption('q', 'quiet', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Run in quiet mode, no output')); $input->registerOption(new \ezcConsoleOption('1', 'prepend', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Prepend autoloader to stack', NULL, array(), array(new \ezcConsoleOptionRule($compat)))); $input->registerOption(new \ezcConsoleOption('d', 'no-exception', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, 'Disable exceptions on registration error')); $input->registerOption(new \ezcConsoleOption(NULL, 'var', \ezcConsoleInput::TYPE_STRING, array(), TRUE, 'Assign variable')); $input->argumentDefinition = new \ezcConsoleArguments(); $input->argumentDefinition[0] = new \ezcConsoleArgument("directory"); $input->argumentDefinition[0]->shorthelp = "The directory to process."; $input->argumentDefinition[0]->multiple = TRUE; return $input; }
#!/usr/bin/env php <?php require_once 'ezc/Base/ezc_bootstrap.php'; ezcBase::addClassRepository(dirname(__FILE__) . '/..', dirname(__FILE__) . '/..'); $input = new ezcConsoleInput(); $helpOption = $input->registerOption(new ezcConsoleOption('h', 'help')); $helpOption->isHelpOption = true; $input->argumentDefinition = new ezcConsoleArguments(); $input->argumentDefinition[0] = new ezcConsoleArgument("infile"); $input->argumentDefinition[0]->mandatory = false; $input->argumentDefinition[0]->default = '-'; $input->argumentDefinition[0]->type = ezcConsoleInput::TYPE_STRING; $input->argumentDefinition[0]->shorthelp = "pipe definition file"; $input->argumentDefinition[0]->longhelp = "Pipe XML definition file to convert or - to read from STDIN ( not implemented yet )"; try { $input->process(); main($input); } catch (Exception $e) { echo $e->getMessage(); exit(1); } function main(ezcConsoleInput $input) { $pipe = getPipe($input->argumentDefinition["infile"]->value); $dotVisitor = new ymcPipeDotVisitor(); $pipe->accept($dotVisitor); echo $dotVisitor->getDot(); } function getPipe($infile) { // get XML String
$generator->appendCustomCode( "public function $methodName" ); $generator->appendCustomCode( '{' ); $generator->indentLevel++; $generator->appendCustomCode( 'self::markTestIncomplete( "Not implemented" );' ); $generator->indentLevel--; $generator->appendCustomCode( '}' ); } } } // Set input options // --------------------------------------------------------------------------- $input = new ezcConsoleInput(); $helpOption = $input->registerOption( new ezcConsoleOption( 'h', 'help' ) ); $helpOption->shorthelp = "Show help"; $helpOption->isHelpOption = true; $sourceFileOption = $input->registerOption( new ezcConsoleOption( 's', 'source-file' ) ); $sourceFileOption->shorthelp = "File containing class to generate tests from"; $sourceFileOption->mandatory = true; $sourceFileOption->type = ezcConsoleInput::TYPE_STRING; $destinationFileOption = $input->registerOption( new ezcConsoleOption( 'd', 'dest-file' ) ); $destinationFileOption->shorthelp = "File to write the tests to"; $destinationFileOption->mandatory = true; $destinationFileOption->type = ezcConsoleInput::TYPE_STRING; // Set ouput formatting
<?php /** * Analyses a FOF song and gets tracks & difficulties */ include dirname(__FILE__) . '/lib/autoload.php'; $input = new ezcConsoleInput(); $dryRunOption = $input->registerOption(new ezcConsoleOption('d', 'dry-run', ezcConsoleInput::TYPE_NONE, false)); $quietOption = $input->registerOption(new ezcConsoleOption('q', 'quiet', ezcConsoleInput::TYPE_NONE, false)); $helpOption = $input->registerOption(new ezcConsoleOption('h', 'help')); $verboseOption = $input->registerOption(new ezcConsoleOption('v', 'verbose', ezcConsoleInput::TYPE_NONE, false)); $input->argumentDefinition = new ezcConsoleArguments(); $input->argumentDefinition[0] = new ezcConsoleArgument("artist"); $input->argumentDefinition[0]->mandatory = true; $input->argumentDefinition[0]->shorthelp = "The artist to search for"; $output = new ezcConsoleOutput(); $output->formats->info->color = 'blue'; $output->formats->error->color = 'red'; $output->formats->error->style = array('bold'); $output->formats->fatal->color = 'red'; $output->formats->fatal->style = array('bold', 'underlined'); $output->formats->fatal->bgcolor = 'black'; try { $input->process(); } catch (ezcConsoleArgumentMandatoryViolationException $e) { if ($helpOption->value === true) { $output->outputText($input->getHelpText("Auto-link by artist name")); exit; } else { $output->outputLine("No arguments given", "fatal"); $output->outputText($input->getHelpText("Auto-link by artist name"));
/** * Registers the consoleInput options and arguments. * * The options and arguments are registered in the given $consoleInput object. * * @param ezcConsoleInput $consoleInput */ protected static function registerConsoleArguments($consoleInput) { // Ansi option $ansi = new ezcConsoleOption('a', 'ansi', ezcConsoleInput::TYPE_NONE); $ansi->shorthelp = "Use ANSI colors in output. Needs PHPUnit 3.3 or newer."; $consoleInput->registerOption($ansi); // Color option, 'ansi' renamed. Will keep ansi for PHPUnit 3.3.0 for now. $colors = new ezcConsoleOption('', 'colors', ezcConsoleInput::TYPE_NONE); $colors->shorthelp = "Use ANSI colors in output. Needs PHPUnit 3.3.2 or newer."; $consoleInput->registerOption($colors); // Configuration XML File option $configuration = new ezcConsoleOption('', 'configuration', ezcConsoleInput::TYPE_STRING); $configuration->shorthelp = "Read configuration from XML file."; $consoleInput->registerOption($configuration); // Database-per-test option $dbPerTest = new ezcConsoleOption('', 'db-per-test', ezcConsoleInput::TYPE_NONE); $dbPerTest->shorthelp = "Use a clean database per test"; $consoleInput->registerOption($dbPerTest); // DSN option $dsn = new ezcConsoleOption('D', 'dsn', ezcConsoleInput::TYPE_STRING); $dsn->shorthelp = "Use the database specified with a DSN: type://user:password@host/database."; $dsn->longhelp = "An example to connect with the local MySQL database is:\n"; $dsn->longhelp .= "mysql://root@mypass@localhost/unittests"; $consoleInput->registerOption($dsn); // Coverage Clover XML option $coverageXml = new ezcConsoleOption('', 'coverage-xml', ezcConsoleInput::TYPE_STRING); $coverageXml->shorthelp = "Write code coverage information in Clover XML format."; $consoleInput->registerOption($coverageXml); // Code Coverage generation in html format $coverageHtml = new ezcConsoleOption('', 'coverage-html', ezcConsoleInput::TYPE_STRING); $coverageHtml->shorthelp = "Generate code coverage report in HTML format [dir]."; $consoleInput->registerOption($coverageHtml); // Filter option $filter = new ezcConsoleOption('f', 'filter', ezcConsoleInput::TYPE_STRING); $filter->shorthelp = "Filter which tests to run."; $consoleInput->registerOption($filter); // Groups option $groups = new ezcConsoleOption('g', 'group', ezcConsoleInput::TYPE_STRING); $groups->shorthelp = "Only runs tests from the specified group(s)."; $consoleInput->registerOption($groups); // Help option $help = new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE); $help->shorthelp = "Show this help"; $help->isHelpOption = true; $consoleInput->registerOption($help); // List groups option $listGroups = new ezcConsoleOption('', 'list-groups', ezcConsoleInput::TYPE_NONE); $listGroups->shorthelp = "List available test groups."; $consoleInput->registerOption($listGroups); // List tests option $listTests = new ezcConsoleOption('', 'list-tests', ezcConsoleInput::TYPE_NONE); $listTests->shorthelp = "Lists all tests"; $consoleInput->registerOption($listTests); // Metrics XML option $metrics = new ezcConsoleOption('', 'log-metrics', ezcConsoleInput::TYPE_STRING); $metrics->shorthelp = "Write metrics report in XML format."; $consoleInput->registerOption($metrics); // Project Mess Detector (PMD) XML option $pmd = new ezcConsoleOption('', 'log-pmd', ezcConsoleInput::TYPE_STRING); $pmd->shorthelp = "Write violations report in PMD XML format."; $consoleInput->registerOption($pmd); // Verbose option $verbose = new ezcConsoleOption('v', 'verbose', ezcConsoleInput::TYPE_NONE); $verbose->shorthelp = "Output more verbose information."; $consoleInput->registerOption($verbose); // XML logfile option $xml = new ezcConsoleOption('x', 'log-xml', ezcConsoleInput::TYPE_STRING); $xml->shorthelp = "Log test execution in XML format to file."; $consoleInput->registerOption($xml); // Stop on failure option $stopOnFailure = new ezcConsoleOption('', 'stop-on-failure', ezcConsoleInput::TYPE_NONE); $stopOnFailure->shorthelp = "Stop execution upon first error or failure."; $consoleInput->registerOption($stopOnFailure); // PHPUnit debug output option $debug = new ezcConsoleOption('', 'debug', ezcConsoleInput::TYPE_NONE); $debug->shorthelp = "Turns on debugout output from PHPUnit."; $consoleInput->registerOption($debug); // Temporary workaround for selenium suite, as this info is not readily available in ant $phpBin = new ezcConsoleOption('', 'php-binary', ezcConsoleInput::TYPE_STRING); $phpBin->shorthelp = "The location of the PHP binary"; $consoleInput->registerOption($phpBin); // Set up dependencies $dbPerTest->addDependency(new ezcConsoleOptionRule($dsn)); }
/** * Main function. Sets up the environment and coordinate the work. * * @return void */ public static function run() { // Set autoload up require_once 'VcsStats/Loader.php'; spl_autoload_register(array('VcsStats_Loader', 'autoload')); require_once 'ezc/Base/base.php'; spl_autoload_register(array('ezcBase', 'autoload')); // Set console output up $output = new ezcConsoleOutput(); $output->formats->version->style = array('bold'); $output->formats->debug->color = 'yellow'; $output->formats->debug->style = array('italic'); $output->formats->error->color = 'red'; self::$consoleOutput = $output; // Set console input up $input = new ezcConsoleInput(); self::$consoleInput = $input; $debugOption = new ezcConsoleOption('d', 'debug'); $debugOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($debugOption); $helpOption = new ezcConsoleOption('h', 'help'); $helpOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($helpOption); $revisionsOption = new ezcConsoleOption('r', 'revisions'); $revisionsOption->type = ezcConsoleInput::TYPE_STRING; $input->registerOption($revisionsOption); $verboseOption = new ezcConsoleOption('v', 'verbose'); $verboseOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($verboseOption); $versionOption = new ezcConsoleOption(null, 'version'); $versionOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($versionOption); // Process console input try { $input->process(); } catch (ezcConsoleOptionException $exception) { echo $exception->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { self::displayHelp(); exit(0); } else { if ($input->getOption('version')->value) { self::displayVersion(); exit(0); } } $arguments = $input->getArguments(); if (1 !== count($arguments)) { self::displayError('Path to repository is missing', 'error'); exit(1); } $repositoryPath = $arguments[0]; // Do the actual work self::displayVersion(); try { $options = array('path' => $repositoryPath); $wrapper = new VcsStats_Wrapper_Subversion($options); $cachePath = realpath(dirname(__FILE__) . '/../../tmp'); $cache = new VcsStats_Cache($wrapper, $cachePath); $revisionsRange = self::_extractRevisionsRange($input->getOption('revisions')->value); $cache->updateData($revisionsRange['end']); $analyzer = new VcsStats_Analyzer($cache); $report = $analyzer->getReport($revisionsRange['start'], $revisionsRange['end']); $renderer = new VcsStats_Renderer_Text(); $renderer->render($report); } catch (Exception $exception) { self::displayError($exception->getMessage()); exit(1); } }
<?php require 'ezc-setup.php'; $optionHandler = new ezcConsoleInput(); $file = new ezcConsoleOption('f', 'file', ezcConsoleInput::TYPE_STRING); $file->mandatory = true; $optionHandler->registerOption($file); try { $optionHandler->process(); } catch (ezcConsoleException $e) { die($e->getMessage()); } echo "Processing file: ", $optionHandler->getOption('f')->value, "\n";
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ ini_set('error_reporting', E_ALL); ini_set('register_globals', 0); ini_set('display_errors', 1); ini_set("max_execution_time", "3600"); require_once dirname(__FILE__) . "/ezcomponents/Base/src/base.php"; function __autoload($className) { ezcBase::autoload($className); } ezcBase::addClassRepository(dirname(__FILE__) . '/', dirname(__FILE__) . '/lib/autoloads'); $input = new ezcConsoleInput(); $helpOption = $input->registerOption(new ezcConsoleOption('s', 'siteaccess', ezcConsoleInput::TYPE_STRING)); $cronjobPartOption = $input->registerOption(new ezcConsoleOption('c', 'cronjob', ezcConsoleInput::TYPE_STRING)); $cronjobPathOption = $input->registerOption(new ezcConsoleOption('p', 'path', ezcConsoleInput::TYPE_STRING)); $extensionPartOption = $input->registerOption(new ezcConsoleOption('e', 'extension', ezcConsoleInput::TYPE_STRING)); try { $input->process(); } catch (ezcConsoleOptionException $e) { die($e->getMessage()); } ezcBaseInit::setCallback('ezcInitDatabaseInstance', 'erLhcoreClassLazyDatabaseConfiguration'); $instance = erLhcoreClassSystem::instance(); $instance->SiteAccess = $helpOption->value; $instance->SiteDir = dirname(__FILE__) . '/'; $cfgSite = erConfigClassLhConfig::getInstance(); $defaultSiteAccess = $cfgSite->getSetting('site', 'default_site_access'); $optionsSiteAccess = $cfgSite->getSetting('site_access_options', $helpOption->value);
* * You should have received a copy of version 2.0 of the GNU General * Public License along with this program; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * @category helper script * @package ymcExtensionLoader * @copyright 2010 by YMC AG. All rights reserved. * @license GNU General Public License v2.0 * @author ymc-toko * @filesource */ require_once 'ezc/Base/ezc_bootstrap.php'; $input = new ezcConsoleInput(); $option = $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, null, FALSE)); $option->isHelpOption = TRUE; $option->arguments = FALSE; $option = $input->registerOption(new ezcConsoleOption('d', 'dir', ezcConsoleInput::TYPE_STRING, '.', FALSE, 'Search Directory.', 'Directory to search for php class files, defaults to .')); $option->arguments = FALSE; $option = $input->registerOption(new ezcConsoleOption('t', 'target', ezcConsoleInput::TYPE_STRING, './autoload', FALSE, 'autoload dir', 'The directory where to save the autoload file, defaults to ./autoload')); $option->arguments = FALSE; $option = $input->registerOption(new ezcConsoleOption('p', 'prefix', ezcConsoleInput::TYPE_STRING, null, FALSE, 'classes prefix', 'The prefix of the classes for which the autoload file should be created')); $option->arguments = FALSE; $input->registerOption(new ezcConsoleOption('b', 'basedir', ezcConsoleInput::TYPE_STRING, '.', FALSE, 'basedir for autoload paths', 'Paths in the autoload array are written relatively to this dir. Defaults to .')); try { $input->process(); } catch (ezcConsoleOptionException $e) { die($e->getMessage() . "\n"); } if ($input->getOption('h')->value === true) {