-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathConfigFile.php
More file actions
88 lines (79 loc) · 2.05 KB
/
Copy pathConfigFile.php
File metadata and controls
88 lines (79 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
declare(strict_types=1);
/*
* PHP version 7.1
*
* @copyright Copyright (c) 2012-2017 EELLY Inc. (https://www.eelly.com)
* @link https://api.eelly.com
* @license 衣联网版权所有
*/
namespace Eelly\DevTools\BuildFile;
class ConfigFile extends File
{
/**
* 配置文件目录.
*
* @var array
*/
protected $configDir = [
'dev' => 'var/config/dev/',
'test' => 'var/config/test/',
'local' => 'var/config/local/',
'prod' => 'var/config/prod/',
];
/**
* 需生成的配置文件.
*
* @var array
*/
protected $configFile = [
'annotations.php',
'cache.php',
'easemob.php',
'fastdfs.php',
'mongodb.php',
'mysql.php',
];
/**
* 模块配置构建.
*
* @param string $moduleName
*
* @return array
*/
public function run(string $moduleName): void
{
$moduleName = strtolower($moduleName);
foreach ($this->configDir as $dir) {
$filePath = $dir.$moduleName.$this->fileExt;
$this->buildModuleFile($filePath);
$configDir = $dir . $moduleName;
!is_dir($configDir) && mkdir($configDir, 0755, true);
foreach ($this->configFile as $file) {
$configFilePath = $configDir.'/'.$file;
!file_exists($configFilePath) && file_put_contents($configFilePath, $this->getConfigFileCode(strstr($file, '.', true)));
}
}
}
/**
* 生成模块配置入口文件.
*
* @param string $filePath
*/
private function buildModuleFile(string $filePath): void
{
!file_exists($filePath) && file_put_contents($filePath, $this->getTemplateFile('ModuleConfig'));
}
/**
* 获取配置文件内容.
*
* @param string $fileName
*
* @return string
*/
private function getConfigFileCode(string $fileName): string
{
$fileName = ucfirst($fileName).'Config';
return $this->getTemplateFile($fileName);
}
}