Skip to content

Commit

Permalink
Cleanup (#137)
Browse files Browse the repository at this point in the history
* Raise minimum stability
* Minor cleanup
* Update readme
  • Loading branch information
samdark committed Nov 1, 2021
1 parent 02808bc commit 10b0a1a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 55 deletions.
46 changes: 3 additions & 43 deletions README.md
Expand Up @@ -15,7 +15,7 @@
[![static analysis](https://github.com/yiisoft/yii-console/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/yii-console/actions?query=workflow%3A%22static+analysis%22)
[![type-coverage](https://shepherd.dev/github/yiisoft/yii-console/coverage.svg)](https://shepherd.dev/github/yiisoft/yii-console)

This Yii Framework package adds console into the application.
This Yii Framework package provides a console that could be added to an application.

## Requirements

Expand All @@ -33,48 +33,8 @@ composer require yiisoft/yii-console --prefer-dist

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:

```php
#!/usr/bin/env php
<?php

declare(strict_types=1);

use Psr\Container\ContainerInterface;
use Yiisoft\Config\Config;
use Yiisoft\Config\ConfigPaths;
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(new ConfigPaths(__DIR__, 'config'));

$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);
}
```
If not, require [yiisoft/yii-runner-console](https://github.com/yiisoft/yii-runner-console) and create an entry script
as described in that package readme.

To start Console Application `composer.json` should contain minimal configuration
for [Yiisoft\Config\Config](https://github.com/yiisoft/config):
Expand Down
2 changes: 0 additions & 2 deletions composer.json
Expand Up @@ -26,8 +26,6 @@
"url": "https://github.com/sponsors/yiisoft"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.4|^8.0",
"psr/container": "^1.0|^2.0",
Expand Down
5 changes: 3 additions & 2 deletions src/Application.php
Expand Up @@ -17,10 +17,10 @@
use function explode;
use function implode;

class Application extends \Symfony\Component\Console\Application
final class Application extends \Symfony\Component\Console\Application
{
public const NAME = 'Yii Console';
public const VERSION = '1.0.0-dev';
public const VERSION = '1.0';

private ?EventDispatcherInterface $dispatcher = null;

Expand Down Expand Up @@ -59,6 +59,7 @@ public function renderThrowable(Throwable $e, OutputInterface $output): void
protected function doRenderThrowable(Throwable $e, OutputInterface $output): void
{
parent::doRenderThrowable($e, $output);

// Friendly Exception support
if ($e instanceof FriendlyExceptionInterface) {
if ($output instanceof StyleInterface) {
Expand Down
3 changes: 0 additions & 3 deletions src/Output/ConsoleBufferedOutput.php
Expand Up @@ -6,9 +6,6 @@

use Symfony\Component\Console\Output\ConsoleOutput;

/**
* @author Jean-François Simon <contact@jfsimon.fr>
*/
final class ConsoleBufferedOutput extends ConsoleOutput
{
private string $buffer = '';
Expand Down
2 changes: 1 addition & 1 deletion src/SymfonyEventDispatcher.php
Expand Up @@ -7,7 +7,7 @@
use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

class SymfonyEventDispatcher implements EventDispatcherInterface
final class SymfonyEventDispatcher implements EventDispatcherInterface
{
private PsrEventDispatcherInterface $dispatcher;

Expand Down
6 changes: 2 additions & 4 deletions tests/ApplicationTest.php
Expand Up @@ -15,8 +15,7 @@ public function testDispatcherEventApplicationStartup(): void
{
$event = new ApplicationStartup();

$dispatcher = $this->getInaccessibleProperty($this->application(), 'dispatcher');
$result = $dispatcher->dispatch($event);
$result = $this->getInaccessibleProperty($this->application(), 'dispatcher')->dispatch($event);

$this->assertSame($event, $result);
}
Expand All @@ -25,8 +24,7 @@ public function testDispatcherEventApplicationShutdown(): void
{
$event = new ApplicationShutdown(ExitCode::OK);

$dispatcher = $this->getInaccessibleProperty($this->application(), 'dispatcher');
$result = $dispatcher->dispatch($event);
$result = $this->getInaccessibleProperty($this->application(), 'dispatcher')->dispatch($event);

$this->assertSame($event, $result);
$this->assertEquals(ExitCode::OK, $event->getExitCode());
Expand Down

0 comments on commit 10b0a1a

Please sign in to comment.