PHP code example of wayhood / hyperf-action

1. Go to this page and download the library: Download wayhood/hyperf-action library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wayhood / hyperf-action example snippets


Router::addRoute(['GET', 'POST'], "/",
    'Wayhood\HyperfAction\Controller\MainController@index',
    ['middleware' => [\Wayhood\HyperfAction\Middleware\ActionMiddleware::class]]);

Router::get('/doc',
    'Wayhood\HyperfAction\Controller\MainController@doc');



declare(strict_types=1);
namespace App\Action\Test;

use Hyperf\DB\DB;
use Wayhood\HyperfAction\Annotation\Action;
use Wayhood\HyperfAction\Annotation\Category;
use Wayhood\HyperfAction\Annotation\Description;
use Wayhood\HyperfAction\Annotation\RequestParam;
use Wayhood\HyperfAction\Annotation\ResponseParam;
use Wayhood\HyperfAction\Annotation\Usable;
use Wayhood\HyperfAction\Annotation\ErrorCode;
use Wayhood\HyperfAction\Annotation\Token;
use Wayhood\HyperfAction\Action\AbstractAction;

/**
 * @Action("test.get")
 *
 * 以下注解用于生成文档校验数据类型和过滤响应输出
 *
 * 分类
 * @Category("测试")
 *
 * 描述
 * @Description("测试请求")
 *
 * 请求参数
 * 格式:  name="名称",  type="类型", ��名称")
 * @ResponseParam(n="user.age",       t="int",      e=40,            d="返回用户年龄")
 * @ResponseParam(n="user.tel",       t="string",   e="12345789001", d="返回用户电话")
 *
 * 错误代码
 * 格式: code=错误代码, message="描述"
 * 简写: c=错误代码, m="描述"
 * @ErrorCode(code=1000, message="不知道")
 *
 * 是否可用 true可用 false不可用
 * @Usable(true)
 *
 * 是否需要Token 必须传Token false不做要求
 * @Token(false)
 */
class GetAction extends AbstractAction
{
    public function run($params, $extras, $headers) {
        return $this->successReturn([
            'user' => [
                'name' => 'syang',
                'age' => 40,
                'tel' => '1234567890'
            ]
        ]);
    }
}
shell
php bin/hyperf.php describe:actions  -d study.list
php bin/hyperf.php describe:actions
shell
php bin/hyperf.php gen:action --namespace 'App\Action\User' LoginAction
php bin/hyperf.php gen:service --namespace 'App\Service\Test' TestService