黄p网站_在线看中文字幕_亚洲电影免费观看_成人激情视频_欧美成视频_中国av在线

成員屬性注解

我們直接看以下示例:

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 參數(shù),我們可以在框架的全局 onRequest 事件中進(jìn)行注入,如下:

<?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 參數(shù)
            Di::getInstance()->set('param2Key', UserService::class); // param2 參數(shù)也可在 bootstrap、initialize、mainServerCreate 等事件中提前注冊。

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

            return true;
        });
    }

    public static function mainServerCreate(EventRegister $register)
    {

    }
}

Context 注解

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

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

Di 注解

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

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

Inject 注解

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

$this->param1 = new \App\Service\UserService(...$args)
主站蜘蛛池模板: 欧美 亚洲 一区 | 久久久久久免费视频 | 中文字幕第33页 | 激情视频在线观看 | 亚洲三级视频 | 久久成人国产精品 | 日韩av成人 | 国产精品99久久久久久动医院 | 涩涩综合 | 免费看的黄色网 | 亚洲免费视频一区 | 91精品久久久久久久久中文字幕 | 亚洲人成人一区二区在线观看 | 日本一区二区三区在线视频 | 亚州中文字幕 | 91精品国产91久久久久久蜜臀 | 欧美日韩国产一区二区在线观看 | 久热中文字幕 | 日日精品 | 国产精品久久久久久亚洲调教 | 一区二区三区回区在观看免费视频 | 九九r热| 中文字幕国产视频 | 亚洲一区二区在线播放 | 国产成人久久 | 久久精品免费观看 | 久久精品国产精品青草 | 国产成人jvid在线播放 | 一级电影在线观看 | 国产免费自拍视频 | 精品久久久久久久久久久下田 | 亚洲色图一区二区三区 | 国产精品永久 | av超碰| 日韩大片免费播放 | 91视频免费看 | 日本久久久一区二区三区 | 国产xxx在线观看 | 中文字幕在线免费看 | 好看毛片 | 日本精品一区二区三区在线观看视频 |