【问题标题】:Dependency injection of FilesystemCache (SimpleCache) in Symfony 4.0Symfony 4.0 中 FilesystemCache (SimpleCache) 的依赖注入
【发布时间】:2018-01-28 18:50:44
【问题描述】:

我正在尝试在我的一个服务类中实现一个 SimpleCache 具体实例以也允许缓存,但是我在连接依赖项时遇到了一些问题。

config/services.yml

services:
    Psr\SimpleCache\CacheInterface: '@Symfony\Component\Cache\Simple\FilesystemCache'

src/Services/Shouter/Sources/Twitter.php

<?php

namespace App\Services\Shouter\Sources;

use Psr\SimpleCache\CacheInterface;

class Twitter
{
    /**
     * Cache instance
     * @var Psr\SimpleCache\CacheInterface
     */
    protected $cache;

    public function __construct(CacheInterface $cache)
    {
        $this->cache = $cache;
    }
}

这是我得到的错误:

你请求了一个不存在的服务“Symfony\Component\Cache\Simple\FilesystemCache”。

【问题讨论】:

    标签: php symfony symfony4


    【解决方案1】:

    已通过在 services.yaml 中添加 Symfony\Component\Cache\Simple\FilesystemCache: 进行修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-05
      • 2014-09-23
      • 1970-01-01
      • 2018-03-02
      • 1970-01-01
      • 2012-07-13
      • 2017-01-23
      • 2012-04-23
      相关资源
      最近更新 更多