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; $libraryPath = str_replace('\\', '/', rtrim($libraryPath, '/\\')) . '/'; if (!is_dir($libraryPath)) { echo "Invalid library directory provided" . PHP_EOL . PHP_EOL; echo $opts->getUsageMessage(); exit(2);
/** * 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; }
<?php /** * User: ms * Date: 29.09.15 * Time: 01:04 */ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php'; try { $opts = new Zend\Console\Getopt(array('time|t' => 'show how old the record is', 'name|n' => 'show the records name', 'channels|c=s' => 'Channel ID from ThingSpeak', 'field|f=d' => 'display only this field', 'ids|i' => 'display the channel ids')); $opts->parse(); } catch (Zend\Console\Exception\RuntimeException $e) { echo $e->getUsageMessage(); exit; } if (null === $opts->getOption('c')) { echo $opts->getUsageMessage(); exit; } //Channel ID $channelId = trim($opts->getOption('c')); /** * found here http://stackoverflow.com/a/11871948 * @param $input * @param $pad_length * @param string $pad_string * @param int $pad_type * @return string */ function mb_str_pad($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT) {
} //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)) { throw new \InvalidArgumentException('Module directory path expects string, "' . gettype($sModulePath) . '" given');
if (!strstr($incPath, $libPath)) { set_include_path($libPath . PATH_SEPARATOR . $incPath); } // Setup autoloading $loader = new Zend\Loader\StandardAutoloader(); require_once 'Zend/Loader/StandardAutoloader.php'; $loader->register(); $rules = array('help|h' => 'Get usage message', 'library|l-s' => 'Library to parse; if none provided, assumes current directory', 'namespace|n-s' => 'Namespace in which to create map; by default, uses last segment of library directory name', 'output|o-s' => 'Where to write autoload file; if not provided, assumes "_autoload.php" in library directory', 'overwrite|w' => 'Whether or not to overwrite existing autoload file', 'keepdepth|k-i' => 'How many additional segments of the library path to keep in the generated classfile map', 'usedir|d' => 'Prepend filenames with __DIR__'); 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']; } if (isset($opts->l)) { $path = $opts->l; if (!is_dir($path)) { echo "Invalid library directory provided" . PHP_EOL . PHP_EOL; echo $opts->getUsageMessage(); exit(2); } $path = realpath($path);
$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 ".classmap.php" in library directory', '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']; } if (isset($opts->l)) { $path = $opts->l; if (!is_dir($path)) { echo "Invalid library directory provided" . PHP_EOL . PHP_EOL; echo $opts->getUsageMessage(); exit(2); }
$loader = new StandardAutoloader(array('autoregister_zf' => true)); $loader->register(); $rules = array('help|h' => 'Get usage message', 'class|c=s' => 'Class for which to create a docbook skeleton', 'output|o-s' => 'Where to write skeleton file; if not provided, assumes documentation/manual/en/module_specs/<class id>.xml"'); $docbookPath = __DIR__ . '/../documentation/manual/en/module_specs'; $docbookFile = false; // Parse options try { $opts = new Zend\Console\Getopt($rules); $opts->parse(); } catch (Console\Exception\RuntimeException $e) { // Error creating or parsing options; show usage message echo $e->getUsageMessage(); exit(2); } // Help requested if ($opts->getOption('h')) { echo $opts->getUsageMessage(); exit; } // Were we provided a class name? if (!isset($opts->c)) { // No class name == no execution echo "Must provide a class via the -c or --class option\n\n"; echo $opts->getUsageMessage(); exit(2); } // Valid class name? $class = $opts->c; if (!class_exists($class) && !interface_exists($class)) { // Invalid class name == no execution printf("Invalid class '%s' provided' class not found\n\n", $class);