Beispiel #1
0
    $optionHandler->process(array('example_input.php', '-h'));
} catch (ezcConsoleOptionException $e) {
    echo $e->getMessage();
    exit(1);
}
// Process a single parameter
$file = $optionHandler->getOption('f');
if ($file->value === false) {
    echo "Parameter -{$file->short}/--{$file->long} was not submitted.\n";
} elseif ($file->value === true) {
    echo "Parameter -{$file->short}/--{$file->long} was submitted without value.\n";
} else {
    echo "Parameter -{$file->short}/--{$file->long} was submitted with value <" . var_export($file->value, true) . ">.\n";
}
// Process all parameters at once:
foreach ($optionHandler->getOptionValues() as $paramShort => $val) {
    switch (true) {
        case $val === false:
            echo "Parameter {$paramShort} was not submitted.\n";
            break;
        case $val === true:
            echo "Parameter {$paramShort} was submitted without a value.\n";
            break;
        case is_array($val):
            echo "Parameter {$paramShort} was submitted multiple times with value: <" . implode(', ', $val) . ">.\n";
            break;
        default:
            echo "Parameter {$paramShort} was submitted with value: <{$val}>.\n";
            break;
    }
}