コード例 #1
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);
}
コード例 #2
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;
}