Saeghe is a difficult name to pronounce. Therefore, Saeghe project has been renamed to phpkg.
This website no longer receives updates.
Please visit phpkg website at phpkg.com
This document describes included functions in the Saeghe\Cli\IO\Read
library.
function argument(int $number, ?string $default = null): ?string
Returns the number
th argument passed to the PHP file from CLI.
Default passed value or null
will be returned if the given nth
argument is not passed.
use function Saeghe\Cli\IO\Read\argument;
$name = argument(1);
$email = argument(2, 'my-email@example.com');
use Saeghe\Cli\IO\Read;
$name = Read\argument(1);
$email = Read\argument(2, 'my-email@example.com');
php my-file.php // argument(1) => `null`
php my-file.php command add // argument(1) => `command`
php my-file.php command add // argument(2) => `add`
php my-file.php command -f add // argument(2) => `add`
php my-file.php command -f --parameter=anything add // argument(2) => `add`
php my-file.php command -f --parameter=anything add // argument(3) => `null`
function command(): ?string
Returns the first command passed to the PHP file. It will return null if the first argument start with -
or --
.
This is a shorthand for argument(1, null)
.
use function Saeghe\Cli\IO\Read\command;
$command = command();
use Saeghe\Cli\IO\Read;
$command = Read\command();
php my-file.php -v // command() => `null`
php my-file.php --version // command() => `null`
php my-file.php add anything // command() => `add`
php my-file.php help // command() => `help`
php my-file.php -version help // command() => `null`
function parameter(string $name, ?string $default = null): ?string
Returns the name
parameter passed to the PHP file.
If name
not passed, then it returns null
or passed default value.
use function Saeghe\Cli\IO\Read\command;
$name = parameter('name');
$email = parameter('email', 'john@example.com');
use Saeghe\Cli\IO\Read;
$name = Read\parameter('name');
$email = Read\parameter('email', 'john@example.com');
php my-file.php -v // parameter('name') => `null`
php my-file.php -v name // parameter('name') => `null`
php my-file.php -v -name // parameter('name') => `null`
php my-file.php -v --name=John // parameter('name') => `John`
php my-file.php -v --name="John Doe" // parameter('name') => `John Doe`
function option(string $name): bool
Returns boolean to detect if the given name
option passed to the PHP file.
use function Saeghe\Cli\IO\Read\command;
$versionPassed = option('version');
use Saeghe\Cli\IO\Read;
$versionPassed = Read\option('version');
php my-file.php // option('version') => `false`
php my-file.php -v // option('version') => `false`
php my-file.php -version // option('version') => `true`
php my-file.php --version // option('version') => `true`
php my-file.php --version= // option('version') => `true`
php my-file.php --version=false // option('version') => `true`