dongluo3331 2018-01-26 10:53
浏览 104
已采纳

在Synfony config env()帮助程序中使用resolve运算符

This article introduces type-casting and some convenient operators which can be used inside the env() helper in the Symfony configs. Everything's clear except the resolve: operator. The article says:

The resolve: operator replaces container parameter names by their values:

What I am going to have the parameters whose names are taken from the values of the env variables? What's the point?

It's used in the doctrine bundle's config, for example:

dbal:
    # configure these for your database server
    driver: 'pdo_mysql'
    server_version: '5.7'
    charset: utf8mb4

    # With Symfony 3.3, remove the `resolve:` prefix
    url: '%env(resolve:DATABASE_URL)%'

I was googling the issue, but it's almost no info on the Internet, and it doesn't clarify anything to me.

  • 写回答

2条回答 默认 最新

  • duanhuang3074 2018-10-12 15:05
    关注

    It's pretty simple. In your example you have:

    url: '%env(resolve:DATABASE_URL)%'
    

    If DATABASE_URL value itself contains any container parameters, like Romain example:

    parameters:
        env(DATABASE_URL): 'sqlite://%kernel.project_dir%/var/data.db'
        db_dsn: '%env(resolve:DB)%'
    

    Since DATABASE_URL contains %kernel.project_dir% parameter, which would be the root directory of your project.

    By using resolve, you make this %kernel.project_dir% parameter being replaced by it's value.

    Without resolve url will be:

    url: 'sqlite://%kernel.project_dir%/var/data.db'
    

    With resolve (an example) url will be:

    url: 'sqlite:///Users/your_name/whatever/directory/var/data.db'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?