中文在线一区二区_欧美在线综合_久久久久久综合_欧美一区二区三区视频_国产免费看_国产福利精品一区

成員屬性注解

我們直接看以下示例:

UserService

<?php
namespace App\Service;

class UserService
{
    public function info()
    {
        var_dump("this is user info");
    }
}

Index 控制器類

<?php
namespace App\HttpController;

use App\Service\UserService;
use EasySwoole\HttpAnnotation\AnnotationController;
use EasySwoole\HttpAnnotation\Attributes\Property\Context;
use EasySwoole\HttpAnnotation\Attributes\Property\Di;
use EasySwoole\HttpAnnotation\Attributes\Property\Inject;

class Index12 extends AnnotationController
{
    #[Inject(object: new UserService())]
    protected ?UserService $param1;

    #[Di(key: 'param2Key')]
    protected ?UserService $param2;

    #[Context(key: 'param3Key')]
    protected ?UserService $param3;

    protected function onRequest(?string $action): ?bool
    {
        return parent::onRequest($action);
    }

    public function test()
    {
        $this->param1->info();
        $this->param2->info();
        $this->param3->info();
    }
}

如果想正常注入 param2param3 參數,我們可以在框架的全局 onRequest 事件中進行注入,如下:

<?php

namespace EasySwoole\EasySwoole;

use App\Service\UserService;
use EasySwoole\Component\Context\ContextManager;
use EasySwoole\Component\Di;
use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\EasySwoole\Swoole\EventRegister;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;

class EasySwooleEvent implements Event
{
    public static function initialize()
    {
        date_default_timezone_set('Asia/Shanghai');

        Di::getInstance()->set(SysConst::HTTP_GLOBAL_ON_REQUEST, function (Request $request, Response $response): bool {
            // 提前使用 Di 注冊 param2 參數
            Di::getInstance()->set('param2Key', UserService::class); // param2 參數也可在 bootstrap、initialize、mainServerCreate 等事件中提前注冊。

            // 提前使用 ContextManager 注冊 param3 參數
            ContextManager::getInstance()->set('param3Key', new UserService()); // param3 參數只可在全局 onRequest 事件中提前注冊。

            return true;
        });
    }

    public static function mainServerCreate(EventRegister $register)
    {

    }
}

Context 注解

Context 注解,完整命名空間是 \EasySwoole\HttpAnnotation\Attributes\Property\Context,用于在每次請求進來的時候,從上下文管理器中取數據,并賦值到對應的屬性中,以上等價于:

$this->param3 = \EasySwoole\Component\ContextManager::getInstance()->get('param3Key');

Di 注解

Di 注解,完整命名空間是 \EasySwoole\HttpAnnotation\Attributes\Property\Di,用于在每次請求進來的時候,從 IOC 中取數據,并賦值到對應的屬性中,以上等價于:

$this->param2 = \EasySwoole\Component\Di::getInstance()->get('param2Key');

Inject 注解

Inject注解,完整命令空間是 \EasySwoole\HttpAnnotation\Attributes\Property\Inject,可注入類并且傳入構造函數參數,以上等價于:

$this->param1 = new \App\Service\UserService(...$args)
主站蜘蛛池模板: 国产淫片| 免费黄色大片 | 精品天堂 | 亚洲一区二区三区在线播放 | 午夜免费福利视频 | 夜久久| 国产精品99久久免费观看 | 欧美日韩免费一区二区三区 | 亚洲午夜精品 | 日韩精品在线一区 | 一区二区三区视频 | 欧美午夜一区 | 91在线视频观看 | 国产中文字幕亚洲 | 日韩欧美国产一区二区三区 | 久久久www | 成年人激情视频 | 久久久激情 | 成人在线免费观看 | 欧美一区二区三区在线观看 | 欧美视频三区 | 欧美一区二区三区四区五区 | 亚洲第一成人在线视频 | 亚洲视频二区 | 日韩一区二区电影 | 亚洲精品视频一区二区三区 | 国产精品久久久久久吹潮 | 天堂中文网 | www.国产.com | 一区二区在线影院 | 成人av高清在线观看 | 51ⅴ精品国产91久久久久久 | 成人免费视频视频 | 日日色视频 | 成人区精品一区二区婷婷 | 国产精品免费在线 | 欧美日韩在线一区 | 欧美一区二区三区在线观看视频 | 久久艹天天艹 | 激情五月激情综合网 | 这里只有精品视频 |