Very simple wrapper for getopt()
function.
This is only a wrapper, therefore the output from mini-getopt
is going to be
the same as getopt()
function.
First you have to configure options you want to use. To do so use the following methods:
- \Jawira\MiniGetopt\MiniGetopt::addRequired
- \Jawira\MiniGetopt\MiniGetopt::addOptional
- \Jawira\MiniGetopt\MiniGetopt::addNoValue
To retrieve values you have to call one of the following method:
- \Jawira\MiniGetopt\MiniGetopt::getopt
returns the same as getopt()
- \Jawira\MiniGetopt\MiniGetopt::getOption
to get only one value
PHP code:
// Preparing options
$mg = new \Jawira\MiniGetopt\MiniGetopt();
$mg->addRequired('f', 'format'); // value is required
$mg->addOptional('r', 'retry'); // value is optional
$mg->addOptional('q', ''); // only short option
$mg->addNoValue('v', 'verbose'); // no value
$mg->addNoValue('', 'version'); // only long option
// Calling getopt
var_export($mg->getopt());
Executing code:
$ php resources/example.php
array (
)
$ php resources/example.php -f=xml
array (
'f' => 'xml',
)
$ php resources/example.php --format=xml -r -v
array (
'format' => 'xml',
'r' => false,
'v' => false,
)
$ php resources/example.php -f=json -r=yes -v
array (
'f' => 'json',
'r' => 'yes',
'v' => false,
)
$ php resources/example.php --retry -vvv
array (
'retry' => false,
'v' =>
array (
0 => false,
1 => false,
2 => false,
),
)
$ php resources/example.php --version=banana --invalid
array (
'version' => false,
)
$ composer install jawira/mini-getopt
If you liked this project, ? star it on [GitHub][].
This library is licensed under the MIT license.
*
<dl>
<dt><a href="https://packagist.org/packages/jawira/emoji-catalog">jawira/emoji-catalog</a> (library)</dt> <dd>Get access to +3000 emojis as class constants.</dd>
<dt><a href="https://packagist.org/packages/jawira/plantuml">jawira/plantuml</a> (library)</dt> <dd>Provides PlantUML integration: plantuml executable and plantuml.jar</dd>
<dt><a href="https://packagist.org/packages/jawira/plantuml-encoding">jawira/plantuml-encoding</a> (library)</dt> <dd>PlantUML encoding functions.</dd>
<dt><a href="https://packagist.org/packages/jawira/">more...</a></dt> </dl>
[Github]: https://github.com/jawira/mini-getopt
Classes of jawira | > | Mini PHP Getopt | > | Download .zip .tar.gz | > | Support forum | > | Blog | > | Latest changes |
|
|
Groups | Applications | Files |
Groups |
PHP 5 | Classes using PHP 5 specific features | View top rated classes |
Console | Command line and console utilities | View top rated classes |
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
Files |
File | Role | Description | ||
---|---|---|---|---|
.idea (1 file, 1 directory) | ||||
resources (1 file) | ||||
src (7 files) | ||||
.editorconfig | Data | Auxiliary data | ||
build.xml | Data | Auxiliary data | ||
CHANGELOG.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
CONTRIBUTING.md | Data | Auxiliary data | ||
LICENSE.md | Lic. | License text | ||
README.md | Doc. | Documentation |
Files | / | src |
File | Role | Description |
---|---|---|
MiniGetopt.php | Class | Class source |
MiniGetoptException.php | Class | Class source |
NoValue.php | Class | Class source |
OptionalValue.php | Class | Class source |
RequiredValue.php | Class | Class source |
Validator.php | Class | Class source |
Value.php | Class | Class source |
Download all files: mini-getopt.tar.gz mini-getopt.zip NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|