Skip to content

Commit b73067f

Browse files
authored
Cleanup and docs (#31)
1 parent 0fef45c commit b73067f

19 files changed

Lines changed: 150 additions & 144 deletions

File tree

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
YII_ENV=
1+
# Dev environment variables for Codeception.
2+
YII_ENV=dev
23
YII_DEBUG=true

.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
# Test environment variables for Codeception.
12
YII_ENV=test
23
YII_DEBUG=true

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
# Ignore some meta files when creating an archive of this repository
2525
/.github export-ignore
2626
/.gitattributes export-ignore
27-
/.scrutinizer.yml export-ignore
2827
/.styleci.yml export-ignore
2928
/CHANGELOG.md export-ignore
3029

.github/workflows/build.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
- 'README.md'
66
- 'CHANGELOG.md'
77
- '.gitignore'
8-
- '.env.example'
98
- '.gitattributes'
109
- 'infection.json.dist'
1110
- 'psalm.xml'
@@ -16,9 +15,7 @@ on:
1615
- 'README.md'
1716
- 'CHANGELOG.md'
1817
- '.gitignore'
19-
- '.env.example'
2018
- '.gitattributes'
21-
- 'infection.json.dist'
2219
- 'psalm.xml'
2320

2421
schedule:

.github/workflows/static.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ on:
66
- 'CHANGELOG.md'
77
- '.gitignore'
88
- '.gitattributes'
9-
- 'infection.json.dist'
10-
- 'phpunit.xml.dist'
119

1210
push:
1311
paths-ignore:
@@ -16,8 +14,6 @@ on:
1614
- 'CHANGELOG.md'
1715
- '.gitignore'
1816
- '.gitattributes'
19-
- 'infection.json.dist'
20-
- 'phpunit.xml.dist'
2117

2218
name: static analysis
2319

.scrutinizer.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

README.md

Lines changed: 131 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@
99
[![Latest Stable Version](https://poser.pugx.org/yiisoft/app-console/v/stable.png)](https://packagist.org/packages/yiisoft/app-console)
1010
[![Total Downloads](https://poser.pugx.org/yiisoft/app-console/downloads.png)](https://packagist.org/packages/yiisoft/app-console)
1111
[![Build status](https://github.com/yiisoft/app-console/workflows/build/badge.svg)](https://github.com/yiisoft/app-console/actions?query=workflow%3Abuild)
12-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/app-console/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/app-console/?branch=master)
13-
[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/app-console/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/app-console/?branch=master)
1412
[![static analysis](https://github.com/yiisoft/app-console/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/app-console/actions?query=workflow%3A%22static+analysis%22)
1513
[![type-coverage](https://shepherd.dev/github/yiisoft/app-console/coverage.svg)](https://shepherd.dev/github/yiisoft/app-console)
1614

17-
The package is a console application that can be used to perform common tasks in a Yii application.
15+
The package is a **console only** application template that can be used to perform common tasks in a Yii application.
16+
If you need classic web or API please start with corresponding templates:
17+
18+
- [Classic web application template](https://github.com/yiisoft/app)
19+
- [API application template](https://github.com/yiisoft/app-api)
20+
21+
It is based on [Yii console runner](https://github.com/yiisoft/yii-runner-console) that is used in the entry
22+
command script, `./yii`. You are free to adjust any part of this template including the entry command script
23+
to suit your needs.
1824

1925
## Requirements
2026

@@ -25,33 +31,119 @@ The package is a console application that can be used to perform common tasks in
2531
The package could be installed with [Composer](https://getcomposer.org):
2632

2733
```shell
28-
composer create-project --stability=dev yiisoft/app-console <your project>
34+
composer create-project yiisoft/app-console <your project>
2935
```
3036

3137
## General usage
3238

33-
### Create command console
39+
Console is available as `./yii` from the root directory of the application:
40+
41+
```shell
42+
$ ./yii
43+
44+
Yii Console 1.0
45+
46+
Usage:
47+
command [options] [arguments]
48+
49+
Options:
50+
-h, --help Display help for the given command. When no command is given display help for the list command
51+
-q, --quiet Do not output any message
52+
-V, --version Display this application version
53+
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
54+
-n, --no-interaction Do not ask any interactive question
55+
--config=CONFIG Set alternative configuration name
56+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
57+
58+
Available commands:
59+
completion Dump the shell completion script
60+
echo An example command that echoes exactly what it is told to.
61+
help Display help for a command
62+
list List commands
63+
serve Runs PHP built-in web server
64+
```
65+
66+
Help for specific command could be displayed by adding `--help` to the command itself:
67+
68+
```shell
69+
$ ./yii echo --help
70+
71+
Description:
72+
An example command that echoes exactly what it is told to.
73+
74+
Usage:
75+
echo [<sentence>]
76+
77+
Arguments:
78+
sentence Sentence to say. [default: "Hello!"]
79+
80+
Options:
81+
-h, --help Display help for the given command. When no command is given display help for the list command
82+
-q, --quiet Do not output any message
83+
-V, --version Display this application version
84+
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
85+
-n, --no-interaction Do not ask any interactive question
86+
--config=CONFIG Set alternative configuration name
87+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
88+
```
89+
90+
Using the command is like the following:
91+
92+
```shell
93+
$ ./yii echo
94+
You said: Hello!
95+
96+
$ ./yii echo 'Code something'
97+
You said: Code something
98+
```
99+
100+
## Environments
101+
102+
Out of the box, three environments are available:
103+
104+
- dev — for development.
105+
- prod — for production.
106+
- test — for running tests.
107+
108+
Config files for these are in `config/environments`.
109+
110+
Environment could be chosen by setting `YII_ENV`:
111+
112+
```shell
113+
YII_ENV=prod ./yii
114+
```
115+
116+
## Extra debugging
117+
118+
To enable validation of container and events, set `YII_DEBUG` environment variable:
119+
120+
```shell
121+
YII_DEBUG=1 ./yii
122+
```
123+
124+
## Creating your own command
125+
126+
Commands are placed into `src/Command`. Let's see how `hello` command is implemented in `src/Command/HelloCommand.php`:
34127

35128
```php
129+
namespace App\Command;
130+
131+
use Symfony\Component\Console\Attribute\AsCommand;
36132
use Symfony\Component\Console\Command\Command;
37133
use Symfony\Component\Console\Input\InputArgument;
38134
use Symfony\Component\Console\Input\InputDefinition;
39135
use Symfony\Component\Console\Input\InputInterface;
40136
use Symfony\Component\Console\Output\OutputInterface;
41137
use Yiisoft\Yii\Console\ExitCode;
42138

43-
final class Hello extends Command
139+
#[AsCommand(
140+
name: 'echo',
141+
description: 'An example command that echoes exactly what it is told to.'
142+
)]
143+
final class EchoCommand extends Command
44144
{
45-
protected static $defaultName = 'hello';
46-
protected static $defaultDescription = 'An example command';
47-
48145
private string $sentence = 'sentence';
49146

50-
public function __construct()
51-
{
52-
parent::__construct();
53-
}
54-
55147
protected function configure(): void
56148
{
57149
$this->setDefinition(
@@ -70,50 +162,41 @@ final class Hello extends Command
70162
}
71163
```
72164

73-
### Using command console
165+
To register the command, add it to `config/commands.php`:
74166

75-
```shell
76-
$ ./yii
77-
Yii Console 1.0
167+
```php
168+
use App\Command\EchoCommand;
78169

79-
Usage:
80-
command [options] [arguments]
170+
return [
171+
'echo' => EchoCommand::class,
172+
];
173+
```
81174

82-
Options:
83-
-h, --help Display help for the given command. When no command is given display help for the list command
84-
-q, --quiet Do not output any message
85-
-V, --version Display this application version
86-
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
87-
-n, --no-interaction Do not ask any interactive question
88-
--config=CONFIG Set alternative configuration name
89-
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
175+
> Info: Yii console is based on Symfony console so for additional usage documentation, please follow
176+
> [Yii console](https://github.com/yiisoft/yii-console) and
177+
> [Symfony console guide](https://symfony.com/doc/current/console.html).
90178
91-
Available commands:
92-
completion Dump the shell completion script
93-
hello An example command
94-
help Display help for a command
95-
list List commands
96-
serve Runs PHP built-in web server
97-
debug
98-
debug:container Show information about container
99-
debug:events Show information about events and listeners
100-
debug:reset Clear debug data
101-
```
179+
## Events
102180

103-
```shell
104-
$ ./yii hello
105-
You said: Hello!
181+
The application raises `ApplicationStartup` before and `ApplicationShutdown` after running a command.
106182

107-
$ ./yii hello 'Code something'
108-
You said: Code something
183+
## Tests
184+
185+
The template comes with ready to use [Codeception](https://codeception.com/) configuration.
186+
In order to execute tests run:
187+
188+
```shell
189+
composer run serve > ./runtime/yii.log 2>&1 &
190+
vendor/bin/codecept run
109191
```
110192

111-
## Documentation
193+
## Static analysis
112194

113-
- [Internals](docs/internals.md)
195+
The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:
114196

115-
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
116-
You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).
197+
```shell
198+
./vendor/bin/psalm
199+
```
117200

118201
## License
119202

codeception.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ coverage:
2020
include:
2121
- src/*
2222
params:
23-
- .env
2423
- .env.test

composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
}
5858
},
5959
"extra": {
60-
"branch-alias": {
61-
"dev-master": "1.0.x-dev"
62-
},
6360
"config-plugin-file": "configuration.php"
6461
},
6562
"config": {

config/commands.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
declare(strict_types=1);
44

5-
use App\Command\HelloCommand;
5+
use App\Command\EchoCommand;
66

77
return [
8-
HelloCommand::$defaultName => HelloCommand::class,
8+
'echo' => EchoCommand::class,
99
];

0 commit comments

Comments
 (0)