コード例 #1
0
ファイル: functions.php プロジェクト: jamayka/db-patcher
/**
 * @param array $defaultStrategies
 * @param array $strategyMap
 * @param \FusePump\Cli\Inputs $inputs
 * @param array $arguments
 * @return callable
 */
function strategyFactory($defaultStrategies, $strategyMap = array(), $inputs = null, $arguments = array())
{
    $strategyList = array(function () {
        return false;
    });
    $addStrategy = function ($strategy) use(&$strategyList, $arguments) {
        $args = array();
        $reflection = new \ReflectionFunction($strategy);
        foreach ($reflection->getParameters() as $param) {
            if ($param->getName() === 'patchFile') {
                continue;
            } elseif ($param->getName() === 'superStrategy') {
                $args[] = end($strategyList);
            } elseif (array_key_exists($param->getName(), $arguments)) {
                $args[] = $arguments[$param->getName()];
            } else {
                $args[] = null;
            }
        }
        $strategyList[] = function ($patchFile) use($strategy, $args) {
            return call_user_func_array($strategy, array_merge(array($patchFile), $args));
        };
    };
    foreach ($strategyMap as $option => $strategy) {
        if ($inputs->get($option)) {
            $addStrategy($strategy);
        }
    }
    if (count($strategyList) < 2) {
        foreach ($defaultStrategies as $strategy) {
            $addStrategy($strategy);
        }
    }
    return end($strategyList);
}
コード例 #2
0
ファイル: sandwich.php プロジェクト: sblmasta/cli.php
<?php

/**
 * Sandwich maker
 */
require dirname(__FILE__) . '/../lib/FusePump/Cli/Inputs.php';
use FusePump\Cli\Inputs;
$cli = new Inputs($argv);
$cli->option('-h, --ham', 'Add ham');
$cli->option('-m, --mayo', 'Add mayonaise');
$cli->option('-c, --cheese [type]', 'Add a cheese');
$cli->option('-b, --bread [type]', 'Type of bread', true);
// required input
$cli->param('when', 'When do you want the sandwhich (now, tomorrow or never)', true);
if (!$cli->parse()) {
    exit(1);
}
echo "You ordered a sandwich " . $cli->get('when') . " with: \n";
if ($cli->get('-h')) {
    echo " - Ham \n";
}
if ($cli->get('-m')) {
    echo " - Mayonaise \n";
}
if ($cli->get('--cheese')) {
    echo ' - ' . $cli->get('--cheese') . " cheese \n";
}
echo 'On ' . $cli->get('-b') . " bread \n";
コード例 #3
0
ファイル: prompt.php プロジェクト: sblmasta/cli.php
<?php

/**
 * Prompt for info
 */
require dirname(__FILE__) . '/../lib/FusePump/Cli/Inputs.php';
use FusePump\Cli\Inputs;
$cli = new Inputs($argv);
if (!$cli->parse()) {
    exit(1);
}
$username = $cli->prompt('Username: '******'Got ' . $username . "\n";
$password = $cli->prompt('Password (not a real one): ', true);
echo 'Got ' . $password . "\n";
$confirm = $cli->confirm('Confirm? (y/n) ');
echo var_dump($confirm);
コード例 #4
0
ファイル: functions.php プロジェクト: jamayka/db-patcher
/**
 * @param \FusePump\Cli\Inputs $inputs
 * @return \FusePump\Cli\Inputs
 */
function getConfiguredOptions($inputs)
{
    $inputs->option('-q, --quite', 'Run in quite mode (answer Yes to all questions)');
    $inputs->option('-l, --list', 'Just output list of patches');
    $inputs->option('-n, --new', 'Install new patches');
    $inputs->option('-c, --changed', 'Install changed patches');
    $inputs->option('-e, --error', 'Install error patches');
    $inputs->option('-a, --all', 'Install all patches (installed, errors, changed, new)');
    $inputs->option('-i, --interactive', 'Interactive mode');
    $inputs->option('-m, --mark-installed', 'Do not actually apply patch just mark as installed');
    $inputs->option('-s, --stop-on-error', 'Stop patches on error');
    $inputs->option('-cf, --config [filename]', 'Config json filename');
    $inputs->param('masks', 'Filename masks of patches to apply whitespace delimited');
    return $inputs;
}