亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

TYPO3:使用構造函數將服務類注入 AuthServiceClass

TYPO3:使用構造函數將服務類注入 AuthServiceClass

PHP
尚方寶劍之說 2022-07-29 16:14:39
我正在使用 TYPO3 10.2 并嘗試將我創建的一些服務類注入到我的身份驗證服務中。class AuthService extends \TYPO3\CMS\Core\Authentication\AuthenticationServiceAuthService 中的構造函數:    /**     * 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;    }我收到以下錯誤:函數 Vendor\MyExt\Service\AuthService::__construct() 的參數太少,第 3461 行的 C:\xampp\htdocs\myproject\typo3\sysext\core\Classes\Utility\GeneralUtility.php 中傳遞了 0,而預期為 3有什么建議嗎?我在 ControllerClass 中使用了相同的構造函數,并且在那里一切正常。到目前為止感謝!
查看完整描述

1 回答

?
波斯汪

TA貢獻1811條經驗 獲得超4個贊

看起來您AuthenticationService的內部實例化為GeneralUtility::makeInstance(). 對于您在某些時候注冊的許多類都是如此,然后 TYPO3 負責創建類(想想用戶函數、插件控制器、模塊控制器、身份驗證服務、掛鉤等)。


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

您可以在官方文檔或我關于該主題的博客文章中找到解釋。



查看完整回答
反對 回復 2022-07-29
  • 1 回答
  • 0 關注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號