Symfony 4 recipe cannot be installed on project because of dotenv issue

411 Views Asked by At

I've been trying to install the cache/cache-bundle recipe into my symfony4 flex-configured project, but to no avail. I execute:

composer require cache/cache-bundle

And this is what I got on the shell:

Capture of recipe cache-bundle install result on shell

Installing the cache-bundle generates a cache.yml file under config/packages/cache.yml, and its default content is:

cache:
    session:
       enabled: "%env(bool:SESSION_CACHE_ENABLED)%"
       service_id: "cache.provider.default"
       use_tagging: true
       ttl: 7200
    router:
       enabled: "%env(bool:ROUTER_CACHE_ENABLED)%"
       service_id: "cache.provider.default"
       ttl: 86400
    logging:
       enabled: "%env(bool:APP_DEBUG)%"
       logger: "logger"
       level: "info"

The problematic line is the first "enabled" one. For some reason, Symfony or composer doesn't like that %env(bool:SESSION_CACHE_ENABLED)% and returns that error message:

Invalid type for path "cache.session.enabled". Expected boolean, but got string.

SESSION_CACHE_ENABLED is a value introduced in the .env file of the project by composer in a block like this.

###> cache/cache-bundle ###
SESSION_CACHE_ENABLED=true
ROUTER_CACHE_ENABLED=false
###< cache/cache-bundle ###

Then, the question is if someone else has "suffered" this problem and found a fix or workaround to make this config work. My objective is to use this dependency in my mock project to cache arrays in memory to use them as a fake DB system.

I thought to open an issue about this, but since I'm not sure if this is a Simfony issue or just a problem in the recipe I preferred to ask here first.

And for the sake of completion, here's the list of current dependencies already in my project.

"require": {
    "php": "^7.1.3",
    "easycorp/easy-log-handler": "^1.0",
    "friendsofsymfony/rest-bundle": "^2.3",
    "hermes/bridge/common": "dev-master",
    "hermes/common": "dev-master",
    "jms/serializer": "^1.10",
    "jms/serializer-bundle": "^2.3",
    "ramsey/uuid": "^3.7",
    "sensio/framework-extra-bundle": "^5.1",
    "symfony/cache": "^4.0",
    "symfony/console": "^4.0",
    "symfony/framework-bundle": "^4.0",
    "symfony/http-foundation": "^4.0",
    "symfony/monolog-bundle": "^3.1",
    "symfony/stopwatch": "^4.0",
    "symfony/web-server-bundle": "^4.0",
    "symfony/yaml": "^4.0"
},
"require-dev": {
    "symfony/flex": "^1.0",
    "symfony/dotenv": "^4.0"
}

I've seen questions about issues regarding booleans in dotenv files, but nothing conclusive for this question, I'm afraid.

1

There are 1 best solutions below

3
On

Have you tried to get rid off the quotes around "%env(bool:SESSION_CACHE_ENABLED)%"?