kerasai / lamp-env
此包最新版本(1.0.0-beta1)没有提供许可证信息。
环境检测实用工具。
1.0.0-beta1
2024-09-13 18:25 UTC
This package is auto-updated.
Last update: 2024-09-13 18:26:59 UTC
README
环境检测库。
用法
添加 Composer PSR-4 自动加载器
"autoload": {
"psr-4": {
"MyProject\\": "src/"
}
}
创建一个 Env
类
示例 Lando Env 类 src/Env/Env.php
<?php
namespace MyProject\Env;
use kerasai\LampEnv\Env as BaseEnv;
use kerasai\LampEnv\Hosts\GithubActionsEnvTrait;
use kerasai\LampEnv\Hosts\LandoEnvTrait;
/**
* Detect the environment.
*/
class Env extends BaseEnv {
use GithubActionsEnvTrait;
use LandoEnvTrait;
/**
* {@inheritdoc}
*/
protected function detectInfo(): array {
if ($lando = $this->detectLando()) {
return $lando;
}
return $this->detectGithubActions() ?: parent::detectInfo();
}
}
Drupal 设置文件
<?php
$env = \MyProject\Env\Env::create();
foreach ($env->getIncludes() as $include) {
$filename = __DIR__ . '/' . $include;
if (file_exists($filename)) {
include $filename;
}
}
// Local settings overrides.
if (file_exists(__DIR__ . '/settings.local.php')) {
include __DIR__ . '/settings.local.php';
}
特定设置文件
settings.default.php
:适用于所有环境的设置settings.[mode].php
:适用于环境类型(开发/测试/生产)的设置settings.[host].php
:适用于特定主机(Lando、Pantheon 等)的设置settings.[host].[mode].php
:适用于特定主机上环境类型的设置