【问题标题】:Class does not exist by migrate the cacheManager to constructor injection通过将 cacheManager 迁移到构造函数注入,类不存在
【发布时间】:2021-08-14 17:02:41
【问题描述】:

我的 cacheManager 实例迁移到 TYPO3 10 时遇到问题。根据 TYPO3 10 文档,缓存应该通过构造函数而不是“cacheManager”实例注入。
我按照文档进行操作,yaml 配置也正确,并且在前端收到错误消息。

"Class TYPO3\CMS\Core\Cache\Frontend\Frontend does not exist. Reflection failed."

据我所知,这个类根本不存在。
这个错误有解决办法吗?

EXT:my_ext/Configuration/Services.yaml

services:
  cache.my_ext:
    class: TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
    factory: ['@TYPO3\CMS\Core\Cache\CacheManager', 'getCache']
    arguments: ['my_ext']
  MyVendor\MyExt\Connection\Http:
    arguments:
      $cache: '@cache.my_ext'

EXT:my_ext/Classes/Connection/Http.php

    /**
     * @var FrontendInterface
     */
    private $cache;
    public function __construct(FrontendInterface $cache)
    {
        $this->cache = $cache;
    }
    public function initializeObject() {
        $className = explode('\\', get_class($this));
        $this->extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($className[1]);
    }
    public function getDataFromUrl($url, $cachingTags = array()) {
        $cacheIdentifier = sha1($url);
        $remoteData = $this->getUrl($url . "&" . time());
        if (($this->cache->get($cacheIdentifier)) === false) {
            $this->cache->set($cacheIdentifier, $remoteData, $cachingTags,36000);
        }
        return $remoteData;
    }

我按照这里的文档:

https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/CachingFramework/Developer/Index.html

【问题讨论】:

  • 您能否提供更多信息?哪个文档?您在 yaml 文件中配置了什么?如果您已经知道,您所做的一切都与文档相对应并且所有配置都是正确的,那么猜测出了什么问题是很困难的。如果是这样,就不应该有错误;-)
  • 我遇到了同样的问题并调查了它,关于这个 \TYPO3\CMS\Core\Cache\Frontend\Frontend 类的来源。在\TYPO3\CMS\Extbase\Object\Container\Container->getImplementationClassName 中,\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface 类在类名末尾剥离了它的接口。因此它变成了TYPO3\CMS\Core\Cache\Frontend\Frontend...但它甚至不应该首先加载接口,而是配置的指定缓存...我也没有让它工作。我们缺少什么?你有任何进展吗?

标签: caching typo3 extbase typo3-10.x


【解决方案1】:

我的解决方案: Services.yaml 文件的内容

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

  WimRoukema\WrCollection\:
    resource: '../Classes/*'

  cache.wr_collection:
    class: TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
    factory: ['@TYPO3\CMS\Core\Cache\CacheManager', 'getCache']
    arguments: ['wr_collection']

  WimRoukema\WrCollection\Controller\IndexController:
    public: true
    arguments:
      - '@cache.wr_collection'

【讨论】:

  • Eap!当心。您没有格式化您的代码——这在您粘贴 YAML 文件的内容时尤其重要,因为缩进非常重要。我已经更新了您的答案,但请查看以了解将来如何格式化您自己的帖子。此外,在提供答案时,请务必在发布前查看其格式,并在必要时进行修改。
【解决方案2】:

我的解决方案是不在 localconf.php 中使用不同的键。 根据命名文档,您应该在不同的地方使用 myext_mycachemy_cache。当我只使用 my_cache 时,它起作用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    • 1970-01-01
    • 2017-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多