我有一个配置文件,它是一个名为 config.php 的 php 数组。
return array(
'template_dir' => __DIR__ '/configs/templates.php'
)
然后每当我想使用这个配置文件时,我只需要包含 config.php。用这种方式编写配置文件也很容易。
file_put_contents($config, 'return ' . var_export($data, true));
但是我希望能够在不扩展的情况下将魔术常量DIR写入配置文件。到目前为止,我还没有想出一种方法来做到这一点。我已经尝试了一切来编写一个 recursiveArrayReplace 方法来删除整个路径并尝试将其替换为
__DIR__
但它总是出现
'__DIR__ . /configs/template.php'
在这种情况下,它在运行时不会扩展。
我该怎么写
__DIR__ to an array in a file or how ever else without the quotes so that it looks like,
array('template_dir' => __DIR__ . '/configs/templates.php');