yiisoft/yii-console

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


README

68747470733a2f2f796969736f66742e6769746875622e696f2f646f63732f696d616765732f7969695f6c6f676f2e737667

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

Requirements

  • PHP 7.4 or higher.

Installation

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
<?php

declare(strict_types=1);

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(
    __DIR__,
    '/config/packages',
);

$container = new Container(
    $config->get('console'),
    $config->get('providers-console')
);

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

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

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

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": [
                "$common",
                "console.php"
            ]
        }
    }

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.

Testing

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Mutation testing

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

./vendor/bin/roave-infection-static-analysis-plugin

Static analysis

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

./vendor/bin/psalm

License

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