php8 依赖注入问题

ric

问题描述

使用了下PD的依赖注入,IDE显示正常,但实际运行报错

程序代码

<?php

namespace app\toadmin\controller;
use common\api\Auth;
use Respect\Validation\Validator as v;
use support\Request;
use DI\Attribute\Inject;

class Log
{
    #[Inject]
    private Auth $auth;

    function getList(Request $request){
        $data = v::input(
            $request->all(),[
                'size' => v::intVal()->length(1, 100)->setName('分页大小'),
                'page' => v::intVal()->length(1, 90000)->setName('当前页'),
                'keywords' => v::optional(v::StringType())->setName('关键字'),
                'start_time' => v::optional(v::dateTime())->setName('开始时间'),
                'end_time' => v::optional(v::dateTime())->setName('结束时间'),
            ]
        );
        dump($this->auth);
        return toTrue($this->auth->getLogList($data));
    }
}

报错信息

#[Inject] found on property app\\toadmin\\controller\\Log::auth but unable to guess what to inject, the type of the property does not look like a valid class or interface name

截图报错信息里报错文件相关代码

截图

操作系统及workerman/webman等框架组件具体版本

php8.2
"php-di/php-di": "^7.0",

1156 1 0
1个回答

ric

我的错,已解决,
use common\api\Auth; 应该为 use app\common\api\Auth;
ide创建的时候,省略了app\

  • 暂无评论
年代过于久远,无法发表回答
×
🔝