gpt4 book ai didi

php - TYPO3:使用构造函数将服务类注入(inject) AuthServiceClass

转载 作者:行者123 更新时间:2023-12-04 10:41:55 25 4
gpt4 key购买 nike

我正在使用 TYPO3 10.2 并尝试将我创建的一些服务类注入(inject)到我的身份验证服务中。

class AuthService extends \TYPO3\CMS\Core\Authentication\AuthenticationService

AuthService 中的构造函数:
    /**
* Contains the configuration of the current extension
* @var ConfigurationService
*/
protected $configurationService;

/**
* @var RestClientService
*/
protected $restClientService;

/**
* @var ConnectionPool
*/
protected $connectionPool;

/**
*
* @param ConfigurationService $configurationService
* @param RestClientService $restClientService
* @param ConnectionPool $connectionPool
*/
public function __construct(ConfigurationService $configurationService, RestClientService $restClientService, ConnectionPool $connectionPool)
{
$this->configurationService = $configurationService;

$this->restClientService = $restClientService;

$this->connectionPool = $connectionPool;
}

我收到以下错误:

Too few arguments to function Vendor\MyExt\Service\AuthService::__construct(), 0 passed in C:\xampp\htdocs\myproject\typo3\sysext\core\Classes\Utility\GeneralUtility.php on line 3461 and exactly 3 expected



有什么建议吗?

我在 ControllerClass 中使用了相同的构造函数,并且在那里一切正常。

到目前为止感谢!

最佳答案

看起来像您的 AuthenticationServiceGeneralUtility::makeInstance() 内部实例化.对于您在某些时候注册的许多类都是如此,然后 TYPO3 负责创建类(想想用户函数、插件 Controller 、模块 Controller 、身份验证服务、 Hook 等)。
GeneralUtility::makeInstance()需要将类从 DI 容器中取出以使 DI 工作,但这仅适用于创建的类 public在容器编译期间。

因此,您的问题的解决方案应该是声明类 AuthService在您的 Configuration/Services.yaml 中公开:

services:
_defaults:
autowire: true
autoconfigure: true
public: false

Vendor\MyExt\:
resource: '../Classes/*'

Vendor\MyExt\Service\AuthService:
public: true

您可以在 official docs 中找到解释。或在我的 blog post关于那个话题。

关于php - TYPO3:使用构造函数将服务类注入(inject) AuthServiceClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59893349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com