winmillwill / settings_compile
Requires
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-10 02:56:49 UTC
README
动机
您应该能够将settings.php中表示的Drupal配置视为一个可以被序列化的简单字典,因为settings.php实际上就是这样。这使得更改设置变得简单,即使不知道php,甚至无需登录服务器或进行任何git提交。您会希望允许这样做,因为您的应用程序可能需要在历史中的任意提交的多个不同环境中存在。
另一种策略是版本化一个settings.php,该文件使用getenv()
获取的环境变量设置配置变量。如果您控制运行php进程对环境变量的可见性,那么这种方法是首选的。
如何操作
使用composer安装此项目。
查看examples/config.yml
,并见证以下命令调用时的结果settings.php
vendor/bin/settings_compile vendor/winmillwill/settings_compile/examples/config.yml settings.php
或者您甚至可以这样做
vendor/bin/settings_compile https://raw.githubusercontent.com/winmillwill/settings_compile/master/examples/config.yml settings.php
该命令仅接受正确格式的yaml文件的路径以及要写入结果的settings.php文件的路径。
模式
您可以在Drupal\Settings\Schema中清楚地看到这一点,但核心思想是您可以通过使用settings键来处理settings.php中可修改的全局变量,因此您的数据库哈希将像这样开始
drupal: ... settings: databases: ...
在settings下可以设置的键限于以下列表
数据库
cookie_domain
conf
installed_profile
update_free_access
db_url
db_prefix
drupal_hash_salt
is_https
base_secure_url
base_insecure_url
您可以通过这种方式指定composer自动加载器(或任何其他php文件)(对于2.0.x)
drupal:
...
include:
require:
- $DRUPAL_ROOT/relative/path/to/vendor/autoload.php
这是因为2.0.x中的所有值都是天真地引用的。
您还可以指定完整的路径,而无需使用DRUPAL_ROOT
宏,但这将要求编辑yaml文件的人知道服务器上Drupal应用程序的完整路径。
您还可以通过这种方式影响ini设置
drupal:
...
ini:
xdebug.show_exception_trace: 1
从2.1.1版本开始,您可以通过在值前加一个%
来禁用引号,这给您提供了对php的完全访问权限
drupal:
...
include:
require:
- %DRUPAL_ROOT . '/relative/path/to/vendor/autoload.php'
同样,任何以$
开头的值也被天真地未处理。
使用环境变量的替代策略
您还可以使用%
转义来创建一个可以轻松地将配置建模为对环境有所了解的yaml文件
drupal:
...
settings:
db_url: %getenv('DRUPAL_DB_URL')
这使得为您的PAAS设置变得简单,但它也提出了一个疑问,即使用yaml而不是仅仅版本化php文件,让另一个系统管理设置环境变量,是否真的有什么好处,如上所述在动机中所述。