参照官方注解注入方式,没生效
https://www.workerman.net/doc/webman/di.html
<?php
namespace app\admin\controller;
use app\admin\service\system\user\AdminSystemUserService;
use DI\Annotation\Inject;
use support\Request;
class AdminAuthController extends AdminAbstractController
{
/**
* @Inject
* @var AdminSystemUserService
*/
private $systemUserService;
public function __construct(AdminSystemUserService $systemUserService)
{
$this->systemUserService = $systemUserService;
}
public function menus(Request $request)
{
$user = $this->systemUserService->getInfo($this->uid());
return $this->success($user['rule']['routers']);
}
}
Error: Call to a member function getInfo() on null in /data/jenkins/chat-server/app/admin/controller/AdminAuthController.php:23
Stack trace:
#0 /data/jenkins/chat-server/vendor/workerman/webman-framework/src/App.php(388): app\admin\controller\AdminAuthController->menus()
#1 /data/jenkins/chat-server/vendor/workerman/webman-framework/src/App.php(349): Webman\App::Webman\{closure}()
#2 /data/jenkins/chat-server/app/admin/middleware/PermissionMiddleware.php(26): Webman\App::Webman\{closure}()
#3 /data/jenkins/chat-server/vendor/workerman/webman-framework/src/App.php(341): app\admin\middleware\PermissionMiddleware->process()
#4 /data/jenkins/chat-server/app/admin/middleware/AuthMiddleware.php(26): Webman\App::Webman\{closure}()
#5 /data/jenkins/chat-server/vendor/workerman/webman-framework/src/App.php(341): app\admin\middleware\AuthMiddleware->process()
#6 /data/jenkins/chat-server/vendor/webman/log/src/Middleware.php(58): Webman\App::Webman\{closure}()
#7 /data/jenkins/chat-server/vendor/workerman/webman-framework/src/App.php(341): Webman\Log\Middleware->process()
#8 /data/jenkins/chat-server/vendor/workerman/webman-framework/src/App.php(141): Webman\App::Webman\{closure}()
#9 /data/jenkins/chat-server/vendor/workerman/workerman/Connection/TcpConnection.php(646): Webman\App->onMessage()
#10 [internal function]: Workerman\Connection\TcpConnection->baseRead()
#11 /data/jenkins/chat-server/vendor/workerman/workerman/Events/Event.php(193): EventBase->loop()
#12 /data/jenkins/chat-server/vendor/workerman/workerman/Worker.php(1629): Workerman\Events\Event->loop()
#13 /data/jenkins/chat-server/vendor/workerman/workerman/Worker.php(1423): Workerman\Worker::forkOneWorkerForLinux()
#14 /data/jenkins/chat-server/vendor/workerman/workerman/Worker.php(1397): Workerman\Worker::forkWorkersForLinux()
#15 /data/jenkins/chat-server/vendor/workerman/workerman/Worker.php(560): Workerman\Worker::forkWorkers()
#16 /data/jenkins/chat-server/vendor/workerman/webman-framework/src/support/App.php(131): Workerman\Worker::runAll()
#17 /data/jenkins/chat-server/start.php(5): support\App::run()
#18 {main}
linux、php8.1
你的版本应该使用#[Inject]