コード例 #1
0
        echo "Unable to locate autoloader via include_path; aborting" . PHP_EOL;
        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)) {
コード例 #2
0
ファイル: ArgumentParser.php プロジェクト: alab1001101/zf2
 /**
  * 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;
 }
コード例 #3
0
<?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)
{
コード例 #4
0
ファイル: pluginmap_generator.php プロジェクト: rickogden/zf2
}

// 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 plugin map file; if not provided, assumes "plugin_classmap.php" in library directory',
    'append|a'      => 'Append to plugin map 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'];
}
コード例 #5
0
ファイル: zfals.php プロジェクト: hjr3/zf2
    echo "Unable to find Zend Framework library; aborting" . PHP_EOL;
    exit(2);
}
$libPath = realpath($libPath);
// Add ZF to the include_path, if it isn't already
$incPath = get_include_path();
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;
コード例 #6
0
    if (!class_exists('Zend\\Loader\\StandardAutoloader')) {
        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')) {
コード例 #7
0
ファイル: classmap_generator.php プロジェクト: rkeplin/zf2
    }
}

// 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 ".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'];
}
コード例 #8
0
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
    require_once __DIR__ . '/vendor/autoload.php';
} else {
    if (file_exists(__DIR__ . '/../../autoload.php')) {
        require_once __DIR__ . '/../../autoload.php';
    } else {
        file_put_contents('php://stderr', 'Failed to load dependencies. Did you run composer install/update?');
    }
}
use Zend\Console\Console;
use Zend\Crypt\Password\Bcrypt;
use Zend\Console\ColorInterface as Color;
$console = Console::getInstance();
// Obtain console params (inspired by https://github.com/weierophinney/changelog_generator/blob/master/changelog_generator.php)
try {
    $opts = new Zend\Console\Getopt(array('help|h' => 'Help', 'text|t-s' => 'Text to hash'));
    $opts->parse();
} catch (Zend\Console\Exception\ExceptionInterface $e) {
    file_put_contents('php://stderr', $e->getUsageMessage());
    exit(1);
}
// Print help message if asked or nothing is asked
if (isset($opts->h) || $opts->toArray() == array()) {
    file_put_contents('php://stdout', $opts->getUsageMessage());
    exit(0);
}
$bcrypt = new Bcrypt();
if (isset($opts->t)) {
    $console->writeLine($bcrypt->create($opts->t), Color::GREEN);
}
コード例 #9
0
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;
}
コード例 #10
0
ファイル: run-tests.php プロジェクト: hschletz/braintacle
    // required for color output and terminal size detection.
    if ($handle = proc_open(implode(' ', $cmd), array(STDIN, STDOUT, STDERR), $pipes)) {
        $exitCode = proc_close($handle);
        if ($exitCode) {
            printf("\n\nUnit tests for module '%s' failed with status %d. Aborting.\n", $module, $exitCode);
            exit(1);
        } else {
            print "\n";
        }
    } else {
        print "Could not invoke PHPUnit. Aborting.\n";
        exit(1);
    }
}
try {
    $opts = new \Zend\Console\Getopt(array('modules|m=s' => 'comma-separated list of modules to test (case insensitive), test all modules if not set', 'filter|f=s' => 'run only tests whose names match given regex', 'database|d-s' => 'comma-separated list of INI sections with database config (use all sections if empty)', 'coverage|c' => 'generate code coverage report (slow, requires Xdebug extension)'));
    $opts->parse();
    if ($opts->getRemainingArgs()) {
        throw new \Zend\Console\Exception\RuntimeException('Non-option arguments not allowed', $opts->getUsageMessage());
    }
} catch (\Zend\Console\Exception\RuntimeException $e) {
    print $e->getUsageMessage();
    exit(1);
}
// Generate list of available modules.
// The following basic modules are tested first. Other modules are added
// dynamically.
$modulesAvailable = array('Library', 'Database', 'Model');
foreach (new \FilesystemIterator(__DIR__ . '/../module') as $entry) {
    if ($entry->isDir() and !in_array($entry->getFilename(), $modulesAvailable)) {
        $modulesAvailable[] = $entry->getFilename();
コード例 #11
0
ファイル: guesswho.php プロジェクト: robbertkl/guesswho
 */
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)) {