mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-30 02:37:58 +08:00
Updated the definition of command as annotation. (#5900)
Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
parent
2cba3cfc2f
commit
c2fee049f1
@ -27,7 +27,7 @@ After executing the above command, a configured `FooCommand` class will be gener
|
||||
|
||||
### Definition of Command
|
||||
|
||||
There are two forms of commands that define the command class. One is defined by the `$name` property, and the other is defined by the constructor argument. We demonstrate this through code examples, assuming we want to define the command. The class command is `foo:hello`:
|
||||
There are three forms of commands that define the command class. The first is defined by the `$name` property, the second is defined by the constructor argument, and the last is defined by annotations. We demonstrate this through code examples, assuming we want to define the command. The class command is `foo:hello`:
|
||||
|
||||
#### Define the command by `$name` property:
|
||||
|
||||
@ -75,6 +75,25 @@ class FooCommand extends HyperfCommand
|
||||
}
|
||||
```
|
||||
|
||||
#### Define the command by annotations:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
use Hyperf\Command\Annotation\Command;
|
||||
|
||||
#[Command(name: "foo:hello")]
|
||||
class FooCommand extends HyperfCommand
|
||||
{
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### Define the logic of the command
|
||||
|
||||
The logic that the command class actually runs depends on the `handle` method inside the code, which means that the `handle` method is the entry point to the command.
|
||||
|
@ -27,7 +27,7 @@ php bin/hyperf.php gen:command FooCommand
|
||||
|
||||
### 定义命令
|
||||
|
||||
定义该命令类所对应的命令有两种形式,一种是通过 `$name` 属性定义,另一种是通过构造函数传参来定义,我们通过代码示例来演示一下,假设我们希望定义该命令类的命令为 `foo:hello`:
|
||||
定义该命令类所对应的命令有三种形式,第一种是通过 `$name` 属性定义,第二种是通过构造函数传参来定义,最后一种是通过注解来定义,我们通过代码示例来演示一下,假设我们希望定义该命令类的命令为 `foo:hello`:
|
||||
|
||||
#### `$name` 属性定义:
|
||||
|
||||
@ -73,6 +73,25 @@ class FooCommand extends HyperfCommand
|
||||
}
|
||||
```
|
||||
|
||||
#### 注解定义:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
use Hyperf\Command\Annotation\Command;
|
||||
|
||||
#[Command(name: "foo:hello")]
|
||||
class FooCommand extends HyperfCommand
|
||||
{
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### 定义命令类逻辑
|
||||
|
||||
命令类实际运行的逻辑是取决于 `handle` 方法内的代码,也就意味着 `handle` 方法就是命令的入口。
|
||||
|
@ -27,7 +27,7 @@ php bin/hyperf.php gen:command FooCommand
|
||||
|
||||
### 定義命令
|
||||
|
||||
定義該命令類所對應的命令有兩種形式,一種是通過 `$name` 屬性定義,另一種是通過構造函數傳參來定義,我們通過代碼示例來演示一下,假設我們希望定義該命令類的命令為 `foo:hello`:
|
||||
定義該命令類所對應的命令有三種形式,第一種是通過 `$name` 屬性定義,第二種是通過構造函數傳參來定義,最後一種是通過註解來定義,我們通過代碼示例來演示一下,假設我們希望定義該命令類的命令為 `foo:hello`:
|
||||
|
||||
#### `$name` 屬性定義:
|
||||
|
||||
@ -73,6 +73,25 @@ class FooCommand extends HyperfCommand
|
||||
}
|
||||
```
|
||||
|
||||
#### 註解定義:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
use Hyperf\Command\Annotation\Command;
|
||||
|
||||
#[Command(name: "foo:hello")]
|
||||
class FooCommand extends HyperfCommand
|
||||
{
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### 定義命令類邏輯
|
||||
|
||||
命令類實際運行的邏輯是取決於 `handle` 方法內的代碼,也就意味着 `handle` 方法就是命令的入口。
|
||||
|
@ -27,7 +27,7 @@ php bin/hyperf.php gen:command FooCommand
|
||||
|
||||
### 定義命令
|
||||
|
||||
定義該命令類所對應的命令有兩種形式,一種是透過 `$name` 屬性定義,另一種是透過建構函式傳參來定義,我們透過程式碼示例來演示一下,假設我們希望定義該命令類的命令為 `foo:hello`:
|
||||
定義該命令類所對應的命令有三種形式,第一種是透過 `$name` 屬性定義,第二種是透過建構函式傳參來定義,最後一種是通過註解來定義,我們透過程式碼示例來演示一下,假設我們希望定義該命令類的命令為 `foo:hello`:
|
||||
|
||||
#### `$name` 屬性定義:
|
||||
|
||||
@ -73,6 +73,25 @@ class FooCommand extends HyperfCommand
|
||||
}
|
||||
```
|
||||
|
||||
#### 註解定義:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
use Hyperf\Command\Annotation\Command;
|
||||
|
||||
#[Command(name: "foo:hello")]
|
||||
class FooCommand extends HyperfCommand
|
||||
{
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### 定義命令類邏輯
|
||||
|
||||
命令類實際執行的邏輯是取決於 `handle` 方法內的程式碼,也就意味著 `handle` 方法就是命令的入口。
|
||||
|
Loading…
Reference in New Issue
Block a user