在线看片18_亚洲性吧_在线污_神马午夜达达兔_奇米色网_在线免费看污

成員屬性注解

我們直接看以下示例:

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)
主站蜘蛛池模板: 国产精品嫩草69影院 | 亚洲国产精品成人综合色在线婷婷 | 在线观看成人免费 | 91热在线 | 精品1区2区3区| 欧美色淫| 一区二区三区视频在线播放 | 婷婷色亚洲 | 日本成人不卡 | 青青操在线播放 | 日韩在线精品视频 | 精品国产精品国产偷麻豆 | 中文字幕在线观看视频网站 | 亚洲一区视频 | 亚洲最新在线 | 久久免费大片 | 精品一区二区三区四区 | 国产激情视频在线播放 | 亚洲国产精品99 | 我我色综合 | 免费天堂av | 黄色三级a| 欧美日韩在线视频观看 | √天堂中文官网8在线 | 91看片淫黄大片91 | 中文在线资源天堂 | 牛牛影视av | 成人a在线观看 | 日本美女bbw | 久久中文在线 | 国产欧美视频在线 | av综合网站| 69国产 | 天天操天天看 | 欧美在线不卡视频 | 国产亚洲精品精品精品 | 九色视频在线播放 | 欧美伊人网 | 免费观看一区二区三区 | 91亚洲国产精品 | 亚洲自拍偷拍第一页 |