PHP code example of yiisoft / yii-console

1. Go to this page and download the library: Download yiisoft/yii-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 / yii-console example snippets


#!/usr/bin/env php


declare(strict_types=1);

use Yiisoft\Di\Container;
use Yiisoft\Di\ContainerConfig;
use Yiisoft\Yii\Console\Application;
use Yiisoft\Yii\Console\CommandLoader;

:create()),
    // An array with command names as keys and service IDs as values:
    ['my/custom' => MyCustomCommand::class],
));

$app->run();

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Yiisoft\Yii\Console\ExitCode;


#[AsCommand(
    name: 'my:custom',
    description: 'Description of my custom command.'
)]
final class MyCustomCommand extends Command
{    
    protected function configure(): void
    {
        // ...
    }
    
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        // ...
        return ExitCode::OK;
    }
}

'yiisoft/yii-console' => [
    'commands' => [
        'hello' => Hello::class, // name: 'hello', aliases: [], hidden: false
        'start|run|s|r' => Run::class, // name: 'start', aliases: ['run', 's', 'r'], hidden: false
        '|hack|h' => Hack::class, // name: 'hack', aliases: ['h'], hidden: true
    ],
],

'yiisoft/yii-console' => [
    'serve' => [
        'appRootPath' => null,
        'options' => [
            'address' => '127.0.0.1',
            'port' => '8080',
            'docroot' => 'public',
            'router' => 'public/index.php',
        ],
    ],
],