1. Go to this page and download the library: Download 7csn/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/ */
7csn / console example snippets
#!/usr/bin/env php
use app\console\DemoCommand;
use chaser\console\Application;
(class_exists(DemoCommand::class)) {
$app->add(new DemoCommand());
}
$code = $app->run(); # 0 ~ 255
exit($code);
namespace app\console;
use chaser\console\argument\Option;
use chaser\console\argument\Parameter;
use chaser\console\command\Command;
use chaser\console\input\InputInterface;
use chaser\console\output\OutputInterface;
class DemoCommand extends Command
{
/**
* 返回命令默认名称
*
* @return string
*/
public static function getDefaultName(): string
{
return 'demo';
}
/**
* 返回命令默认描述
*
* @return string
*/
public static function getDefaultDescription(): string
{
return 'This is a demo command';
}
/**
* 返回命令输入定义参数组
*
* @return <Parameter|Option>[]
*/
public function getArguments(): array
{
return [];
}
/**
* 运行命令
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
public function run(InputInterface $input, OutputInterface $output): int
{
return 0;
}
}
public function __construct(string $name, int $mode = 0, string $description = '', string ...$defaults){}
public function __construct(string $name, ?string $shortcut = null, int $mode = 0, string $description = '', string ...$defaults){}
public function run(InputInterface $input, OutputInterface $output): int{}