1 Star 0 Fork 16

IS5416/QueryPHP

forked from hunzhiwange/QueryPHP 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
phinx.php 3.25 KB
一键复制 编辑 原始数据 按行查看 历史
小牛New 提交于 2021-01-01 17:58 . chore: Fix phinx path
<?php
declare(strict_types=1);
use Dotenv\Dotenv;
use Leevel\Di\Container;
use Leevel\Kernel\App;
use Leevel\Kernel\IApp;
use Symfony\Component\Console\Input\ArgvInput;
use Leevel\Option\Env;
// 加载 Composer
require __DIR__.'/vendor/autoload.php';
// 创建应用
$container = Container::singletons();
$app = new App($container, realpath(__DIR__));
// 载入环境
$input = new ArgvInput();
if ($input->hasParameterOption('-e')) {
$env = $input->getParameterOption('-e');
} elseif ($input->hasParameterOption('--environment')) {
$env = $input->getParameterOption('--environment');
} else {
$env = 'env';
}
putenv('RUNTIME_ENVIRONMENT='.$env);
/**
* 载入配置.
*/
class PhinxLoad
{
use Env;
/**
* 执行入口.
*/
public function handle(IApp $app): array
{
$this->checkRuntimeEnv($app);
return $this->loadEnvData($app);
}
/**
* 载入环境变量数据.
*/
private function loadEnvData(IApp $app): array
{
$dotenv = Dotenv::createMutable($app->envPath(), $app->envFile());
$this->setEnvVars($envVars = $dotenv->load());
return $envVars;
}
/**
* 载入运行时环境变量.
*
* @throws \RuntimeException
*/
private function checkRuntimeEnv(IApp $app)
{
if (!getenv('RUNTIME_ENVIRONMENT')) {
return;
}
$file = '.'.getenv('RUNTIME_ENVIRONMENT');
if (!is_file($fullFile = $app->envPath().'/'.$file)) {
$e = sprintf('Env file `%s` was not found.', $fullFile);
throw new RuntimeException($e);
}
$app->setEnvFile($file);
}
}
// 读取配置
(new PhinxLoad())->handle($app);
return [
'paths' => [
'migrations' => 'assets/database/migrations',
'seeds' => 'assets/database/seeds',
],
'environments' => [
'defaut_migration_table' => 'phinxlog',
'default_database' => 'development',
'production' => [
'adapter' => 'mysql',
'host' => Leevel::env('DATABASE_HOST', 'localhost'),
'name' => Leevel::env('DATABASE_NAME', ''),
'user' => Leevel::env('DATABASE_USER', 'root'),
'pass' => Leevel::env('DATABASE_PASSWORD', ''),
'port' => Leevel::env('DATABASE_PORT', 3306),
'charset' => 'utf8',
],
'development' => [
'adapter' => 'mysql',
'host' => Leevel::env('DATABASE_HOST', 'localhost'),
'name' => Leevel::env('DATABASE_NAME', ''),
'user' => Leevel::env('DATABASE_USER', 'root'),
'pass' => Leevel::env('DATABASE_PASSWORD', ''),
'port' => Leevel::env('DATABASE_PORT', 3306),
'charset' => 'utf8',
],
'env.phpunit' => [
'adapter' => 'mysql',
'host' => Leevel::env('DATABASE_HOST', 'localhost'),
'name' => Leevel::env('DATABASE_NAME', ''),
'user' => Leevel::env('DATABASE_USER', 'root'),
'pass' => Leevel::env('DATABASE_PASSWORD', ''),
'port' => Leevel::env('DATABASE_PORT', 3306),
'charset' => 'utf8',
],
],
];
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/IS5416/queryphp.git
git@gitee.com:IS5416/queryphp.git
IS5416
queryphp
QueryPHP
master

搜索帮助