Yii Framework Console

dev-master / 3.0.x-dev 2021-09-07 20:55 UTC

This package is auto-updated.

Last update: 2021-09-07 21:01:42 UTC



Yii Framework Console

This Yii Framework package adds console into the application.

Latest Stable Version Total Downloads Build status Code Coverage Scrutinizer Quality Score Mutation testing badge static analysis type-coverage


  • PHP 7.4 or higher.


The package could be installed with composer:

composer require yiisoft/yii-console --prefer-dist

General usage

In case you use one of Yii 3 standard application templates, console could be accessed as ./yii <command>.

If not create an entry script yourself:

#!/usr/bin/env php


use Psr\Container\ContainerInterface;
use Yiisoft\Config\Config;
use Yiisoft\Di\Container;
use Yiisoft\Yii\Console\Application;
use Yiisoft\Yii\Console\Output\ConsoleBufferedOutput;

define('YII_ENV', getenv('env') ?: 'production');

require_once 'vendor/autoload.php';

$config = new Config(

$container = new Container(

/** @var ContainerInterface $container */
$container = $container->get(ContainerInterface::class);

$application = $container->get(Application::class);
$exitCode = 1;

try {
    $exitCode = $application->run(null, new ConsoleBufferedOutput());
} catch (\Error $error) {
    $application->renderThrowable($error, new ConsoleBufferedOutput());
} finally {

To start Console Application composer.json should contain minimal configuration for Yiisoft\Config\Config

    "extra": {
        "config-plugin-options": {
            "source-directory": "config",
            "output-directory": "config/packages"
        "config-plugin": {
            "console": [

Since the package is based on Symfony Console component, refer to its documentation for details on how to use the binary and create your own commands.


Unit testing

The package is tested with PHPUnit. To run tests:


Mutation testing

The package tests are checked with Infection mutation framework with Infection Static Analysis Plugin. To run it:


Static analysis

The code is statically analyzed with Psalm. To run static analysis:



The Yii Framework Console is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack