1. Go to this page and download the library: Download corneltek/getoptionkit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
corneltek / getoptionkit example snippets
use GetOptionKit\OptionCollection;
use GetOptionKit\OptionParser;
use GetOptionKit\OptionPrinter\ConsoleOptionPrinter;
$specs = new OptionCollection;
$specs->add('f|foo:', 'option l address constraint' )
->isa('Email');
$specs->add('z|zoo?', 'option with optional value.' )
->isa('Boolean');
$specs->add('file:', 'option value should be a file.' )
->isa('File');
$specs->add('v|verbose', 'verbose message.' );
$specs->add('d|debug', 'debug message.' );
$specs->add('long', 'long option name only.' );
$specs->add('s', 'short option name only.' );
$printer = new ConsoleOptionPrinter();
echo $printer->render($specs);
$parser = new OptionParser($specs);
echo "Enabled options: \n";
try {
$result = $parser->parse( $argv );
foreach ($result->keys as $key => $spec) {
print_r($spec);
}
$opt = $result->keys['foo']; // return the option object.
$str = $result->keys['foo']->value; // return the option value
print_r($opt);
var_dump($str);
} catch( Exception $e ) {
echo $e->getMessage();
}
$opt->add( 'f|foo:' , 'with string type value' )
->isa('string');
$opt->add( 'b|bar+' , 'with number type value' )
->isa('number');
$opt->add( 'z|zoo?' , 'with boolean type value' )
->isa('boolean');
$opt->add( 'file:' , 'with file type value' )
->isa('file');
$opt->add( 'date:' , 'with date type value' )
->isa('date');
$opt->add( 'url:' , 'with url type value' )
->isa('url');
$opt->add( 'email:' , 'with email type value' )
->isa('email');
$opt->add( 'ip:' , 'with ip(v4/v6) type value' )
->isa('ip');
$opt->add( 'ipv4:' , 'with ipv4 type value' )
->isa('ipv4');
$opt->add( 'ipv6:' , 'with ipv6 type value' )
->isa('ipv6');
$specs->add('r|regex:', 'with custom regex type value')
->isa('Regex', '/^([a-z]+)$/');