1. Go to this page and download the library: Download yiisoft/app-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/ */
yiisoft / app-console example snippets
namespace App\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Yiisoft\Yii\Console\ExitCode;
#[AsCommand(
name: 'echo',
description: 'An example command that echoes exactly what it is told to.'
)]
final class EchoCommand extends Command
{
private string $sentence = 'sentence';
protected function configure(): void
{
$this->setDefinition(
new InputDefinition([
new InputArgument($this->sentence, InputArgument::OPTIONAL, 'Sentence to say.', 'Hello!'),
])
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln("You said: {$input->getArgument('sentence')}");
return ExitCode::OK;
}
}
use App\Command\EchoCommand;
return [
'echo' => EchoCommand::class,
];
shell
$ ./yii echo
You said: Hello!
$ ./yii echo 'Code something'
You said: Code something
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.