/** * Internal routine for parsing the provider options from the command line * * @return null */ protected function _parseProviderOptionsPart() { if (current($this->_argumentsWorking) == '?') { $this->_help = true; return; } $searchParams = array('type' => 'Tool', 'providerName' => $this->_request->getProviderName(), 'actionName' => $this->_request->getActionName(), 'specialtyName' => $this->_request->getSpecialtyName(), 'clientName' => 'console'); $actionableMethodLongParamsMetadata = $this->_manifestRepository->getMetadata(array_merge($searchParams, array('name' => 'actionableMethodLongParams'))); $actionableMethodShortParamsMetadata = $this->_manifestRepository->getMetadata(array_merge($searchParams, array('name' => 'actionableMethodShortParams'))); $paramNameShortValues = $actionableMethodShortParamsMetadata->getValue(); $getoptOptions = array(); $wordArguments = array(); $longParamCanonicalNames = array(); $actionableMethodLongParamsMetadataReference = $actionableMethodLongParamsMetadata->getReference(); foreach ($actionableMethodLongParamsMetadata->getValue() as $parameterNameLong => $consoleParameterNameLong) { $optionConfig = $consoleParameterNameLong . '|'; $parameterInfo = $actionableMethodLongParamsMetadataReference['parameterInfo'][$parameterNameLong]; // process ParameterInfo into array for command line option matching if ($parameterInfo['type'] == 'string' || $parameterInfo['type'] == 'bool') { $optionConfig .= $paramNameShortValues[$parameterNameLong] . ($parameterInfo['optional'] ? '-' : '=') . 's'; } elseif (in_array($parameterInfo['type'], array('int', 'integer', 'float'))) { $optionConfig .= $paramNameShortValues[$parameterNameLong] . ($parameterInfo['optional'] ? '-' : '=') . 'i'; } else { $optionConfig .= $paramNameShortValues[$parameterNameLong] . '-s'; } $getoptOptions[$optionConfig] = $parameterInfo['description'] != '' ? $parameterInfo['description'] : 'No description available.'; // process ParameterInfo into array for command line WORD (argument) matching $wordArguments[$parameterInfo['position']]['parameterName'] = $parameterInfo['name']; $wordArguments[$parameterInfo['position']]['optional'] = $parameterInfo['optional']; $wordArguments[$parameterInfo['position']]['type'] = $parameterInfo['type']; // keep a translation of console to canonical names $longParamCanonicalNames[$consoleParameterNameLong] = $parameterNameLong; } if (!$getoptOptions) { // no options to parse here, return return; } // if non-option arguments exist, attempt to process them before processing options $wordStack = array(); while ($wordOnTop = array_shift($this->_argumentsWorking)) { if (substr($wordOnTop, 0, 1) != '-') { array_push($wordStack, $wordOnTop); } else { // put word back on stack and move on array_unshift($this->_argumentsWorking, $wordOnTop); break; } if (count($wordStack) == count($wordArguments)) { // when we get at most the number of arguments we are expecting // then break out. break; } } if ($wordStack && $wordArguments) { for ($wordIndex = 1; $wordIndex <= count($wordArguments); $wordIndex++) { if (!array_key_exists($wordIndex - 1, $wordStack) || !array_key_exists($wordIndex, $wordArguments)) { break; } $this->_request->setProviderParameter($wordArguments[$wordIndex]['parameterName'], $wordStack[$wordIndex - 1]); unset($wordStack[$wordIndex - 1]); } } $getoptParser = new \Zend\Console\Getopt($getoptOptions, $this->_argumentsWorking, array('parseAll' => false)); $getoptParser->parse(); foreach ($getoptParser->getOptions() as $option) { $value = $getoptParser->getOption($option); $providerParamOption = $longParamCanonicalNames[$option]; $this->_request->setProviderParameter($providerParamOption, $value); } $this->_argumentsWorking = $getoptParser->getRemainingArgs(); return; }
exit(2); } } else { // Try to load StandardAutoloader from library if (false === (include __DIR__ . '/../library/Zend/Loader/StandardAutoloader.php')) { echo "Unable to locate autoloader via library; aborting" . PHP_EOL; exit(2); } } // Setup autoloading $loader = new Zend\Loader\StandardAutoloader(); $loader->register(); $rules = array('help|h' => 'Get usage message', 'library|l-s' => 'Library to parse; if none provided, assumes current directory', 'output|o-s' => 'Where to write autoload file; if not provided, assumes "autoload_classmap.php" in library directory', 'append|a' => 'Append to autoload file if it exists', 'overwrite|w' => 'Whether or not to overwrite existing autoload file'); try { $opts = new Zend\Console\Getopt($rules); $opts->parse(); } catch (Zend\Console\Getopt\Exception $e) { echo $e->getUsageMessage(); exit(2); } if ($opts->getOption('h')) { echo $opts->getUsageMessage(); exit; } $path = $libPath; if (array_key_exists('PWD', $_SERVER)) { $path = $_SERVER['PWD']; } $relativePathForClassmap = ''; if (isset($opts->l)) { $libraryPath = $opts->l;
function getConfig() { try { $opts = new Zend\Console\Getopt(array('help|h' => 'Help; this usage message', 'config|c-s' => 'Configuration file containing base (or all) configuration options', 'token|t-s' => 'GitHub API token', 'user|u-s' => 'GitHub user/organization name', 'repo|r-s' => 'GitHub repository name', 'milestone|m-i' => 'Milestone identifier')); $opts->parse(); } catch (Zend\Console\Exception\ExceptionInterface $e) { file_put_contents('php://stderr', $e->getUsageMessage()); exit(1); } if (isset($opts->h) || $opts->toArray() == array()) { file_put_contents('php://stdout', $opts->getUsageMessage()); exit(0); } $config = array('token' => '', 'user' => '', 'repo' => '', 'milestone' => 0); if (isset($opts->c)) { $userConfig = (include $opts->c); if (false === $userConfig) { file_put_contents('php://stderr', sprintf("Invalid configuration file specified ('%s')\n", $opts->c)); exit(1); } if (!is_array($userConfig)) { file_put_contents('php://stderr', sprintf("Configuration file ('%s') did not return an array of configuration\n", $opts->c)); exit(1); } $config = array_merge($config, $userConfig); } if (isset($opts->token)) { $config['token'] = $opts->token; } if (isset($opts->user)) { $config['user'] = $opts->user; } if (isset($opts->repo)) { $config['repo'] = $opts->repo; } if (isset($opts->milestone)) { $config['milestone'] = $opts->milestone; } if (empty($config['token']) || empty($config['user']) || empty($config['repo']) || empty($config['milestone'])) { file_put_contents('php://stderr', sprintf("Some configuration is missing; please make sure each of the token, user/organization, repo, and milestone are provided.\nReceived:\n%s\n", var_export($config, 1))); exit(1); } return $config; }
throw new \InvalidArgumentException('"' . $sStandardAutoloaderPath . '" does not provide "Zend\\Loader\\StandardAutoloader" class'); } //Setup autoloading $oAutoLoader = new \Zend\Loader\StandardAutoloader(array('autoregister_zf' => true)); $oAutoLoader->register(); $oConsole = \Zend\Console\Console::getInstance(); } catch (\Exception $oException) { echo 'An error occured' . PHP_EOL; if ($bVerbose) { echo $oException . PHP_EOL; } exit(2); } try { $oGetopt = new \Zend\Console\Getopt(array('help|h' => 'Get usage message', 'module|m-s' => 'Module path to deploy; if none provided, assumes current directory', 'dir|d-s' => 'Directory path where to deploy the module (ex: apache/www/my-module), the directory could be created if needed', 'modules|a-s' => '(optionnal) Additionnal module namespaces (comma separated) to be used in the application', 'zapp|z-s' => '(optionnal) ZendSkeletonApplication file path, allows locale or remote directory, allows archive (Phar, Rar, Zip) depending on PHP installed libraries', 'composer|c-s' => '(optionnal) Composer.phar file path, allows locale or remote directory', 'overwrite|w' => 'Whether or not to overwrite existing deployed ZendSkeletonApplication', 'verbose|v' => 'Whether or not to display execution trace')); $oGetopt->parse(); $bVerbose = !!$oGetopt->getOption('verbose'); } catch (\Zend\Console\Exception\RuntimeException $oException) { $oConsole->writeLine($oException->getUsageMessage()); exit(2); } //Display help if ($oGetopt->getOption('help')) { $oConsole->writeLine($oGetopt->getUsageMessage()); exit(0); } //Perform deployment process try { //Define module to deploy path if ($sModulePath = $oGetopt->getOption('module')) { if (!is_string($sModulePath)) {
require_once __DIR__ . '/../vendor/autoload.php'; /** * Print the usage message * * @param \Zend\Console\Getopt $options options to get the usage message from */ function printUsageMessage(\Zend\Console\Getopt $options) { $usage = $options->getUsageMessage(); list($firstLine, $usage) = explode(PHP_EOL, $usage, 2); echo $firstLine . ' -o outputfile.pdf character-images [..]' . PHP_EOL; echo $usage; } try { $options = new \Zend\Console\Getopt(array('d|dpi=i' => 'Image DPI (default 300)', 'f|fontsize=i' => 'Font size for character names (default 10)', 'g|gravity=s' => 'Gravity for crop and fit modes, e.g. north, northwest (default center)', 'h|help' => 'Show help message', 'o|output-file=s' => 'Output PDF file', 'r|recursive' => 'Search directories recursively', 's|resize-mode=s' => 'Image resize mode crop|fit (default crop)', 't|title=s' => 'Set title of character sheet', 'v|verbose' => 'Enable verbose output')); $options->parse(); if (isset($options->h)) { printUsageMessage($options); exit(0); } if (count($options->getRemainingArgs()) == 0) { throw new \UnexpectedValueException('No character files given'); } if (!isset($options->o)) { throw new \UnexpectedValueException('No output file specified'); } $title = isset($options->t) ? $options->t : ''; $imageDpi = isset($options->d) ? $options->d : 300; $fontSize = isset($options->f) ? $options->f : 10; if (isset($options->s)) { switch (preg_replace('/\\W/', '', strtolower($options->s))) {