1. Go to this page and download the library: Download iviphp/console 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/ */
iviphp / console example snippets
declare(strict_types=1);
use Ivi\Console\Console;
use Ivi\Console\ConsoleManager;
$manager = new ConsoleManager(
applicationName: 'My Application',
applicationVersion: '1.0.0'
);
$console = new Console($manager);
declare(strict_types=1);
use Ivi\Console\Contracts\InputInterface;
use Ivi\Console\Contracts\OutputInterface;
$console->command(
name: 'hello',
handler: static function (
InputInterface $input,
OutputInterface $output
): int {
$output->writeln('Hello from IviPHP.');
return 0;
},
description: 'Display a greeting.'
);
use Ivi\Console\ConsoleManager;
ConsoleManager::SUCCESS;
ConsoleManager::FAILURE;
ConsoleManager::INVALID;
$console->command(
name: 'project:check',
handler: static function (
InputInterface $input,
OutputInterface $output
): int {
$output->success('Project configuration is valid.');
return ConsoleManager::SUCCESS;
}
);
declare(strict_types=1);
use Ivi\Console\Contracts\CommandInterface;
use Ivi\Console\Contracts\InputInterface;
use Ivi\Console\Contracts\OutputInterface;
final class AboutCommand implements CommandInterface
{
public function name(): string
{
return 'about';
}
public function description(): string
{
return 'Display application information.';
}
public function aliases(): array
{
return [];
}
public function usage(): string
{
return 'about';
}
public function isHidden(): bool
{
return false;
}
public function execute(
InputInterface $input,
OutputInterface $output
): int {
$output->writeln(
'Built with IviPHP.'
);
return 0;
}
}
$console->register(
new AboutCommand()
);
$console->registerMany([
new AboutCommand(),
new StatusCommand(),
new CacheClearCommand(),
]);
public function script(): string;
public function command(): ?string;
public function arguments(): array;
public function hasArgument(int $index): bool;
public function argument(
int $index,
mixed $default = null
): mixed;
public function options(): array;
public function hasOption(string $name): bool;
public function option(
string $name,
mixed $default = null
): mixed;
public function tokens(): array;
Ivi\Console\Contracts\OutputInterface
public function write(
string $message,
bool $newline = false
): void;
public function writeln(
string $message = ''
): void;
public function info(string $message): void;
public function success(string $message): void;
public function warning(string $message): void;
public function error(string $message): void;
public function isDecorated(): bool;
public function setDecorated(
bool $decorated
): void;