forked from acquia/blt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultConfig.php
146 lines (128 loc) · 3.8 KB
/
DefaultConfig.php
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace Acquia\Blt\Robo\Config;
use Robo\Config\YamlConfigLoader;
use Symfony\Component\Finder\Finder;
/**
* Default configuration for BLT.
*/
class DefaultConfig extends BltConfig {
/**
* Constructor.
*/
public function __construct() {
parent::__construct();
$repo_root = $this->getRepoRoot();
$this->set('repo.root', $repo_root);
$this->set('docroot', $repo_root . '/docroot');
$this->set('blt.root', $this->getBltRoot());
$this->set('composer.bin', $repo_root . '/vendor/bin');
}
/**
* Gets the repository root.
*
* @return string
* The filepath for the repository root.
*
* @throws \Exception
*/
protected function getRepoRoot() {
$possible_repo_roots = [
$_SERVER['PWD'],
realpath($_SERVER['PWD'] . '/..'),
getcwd(),
];
foreach ($possible_repo_roots as $possible_repo_root) {
if (file_exists("$possible_repo_root/vendor/acquia/blt")
||file_exists("$possible_repo_root/blt/project.yml")) {
return $possible_repo_root;
}
}
throw new BltException('Could not find repository root directory!');
}
/**
* Gets the BLT root directory. E.g., /vendor/acquia/blt.
*
* @return string
* THe filepath for the Drupal docroot.
*
* @throws \Exception
*/
protected function getBltRoot() {
$possible_blt_roots = [
dirname(dirname(dirname(dirname(__FILE__)))),
dirname(dirname(dirname(__FILE__))),
];
foreach ($possible_blt_roots as $possible_blt_root) {
if (file_exists("$possible_blt_root/template")) {
return $possible_blt_root;
}
}
throw new BltException('Could not find the Drupal docroot directory');
}
/**
* Populates configuration settings not available during construction.
*/
public function populateHelperConfig() {
$defaultAlias = $this->get('drush.default_alias');
$alias = $defaultAlias == 'self' ? '' : $defaultAlias;
$this->set('drush.alias', $alias);
if (!$this->get('multisites')) {
$this->set('multisites', $this->getSiteDirs());
}
}
/**
* Sets multisite context by settings site-specific config values.
*
* @param string $site_name
* The name of a multisite. E.g., if docroot/sites/example.com is the site,
* $site_name would be example.com.
*/
public function setSiteConfig($site_name) {
$this->config->set('site', $site_name);
$this->config->set('drush.uri', $site_name);
// After having set site, this should now return the multisite
// specific config.
$site_config_file = $this->get('blt.config-files.multisite');
$this->importYamlFile($site_config_file);
}
/**
* Sets multisite context by settings site-specific config values.
*
* @param string $file_path
* The file path to the config yaml file.
*/
public function importYamlFile($file_path) {
$loader = new YamlConfigLoader();
$processor = new YamlConfigProcessor();
$processor->add($this->config->export());
$processor->extend($loader->load($file_path));
$this->config->import($processor->export());
}
/**
* Gets an array of sites for the Drupal application.
*
* I.e., sites under docroot/sites, not including acsf 'g' pseudo-site.
*
* @return array
* An array of sites.
*/
protected function getSiteDirs() {
$sites_dir = $this->get('docroot') . '/sites';
$sites = [];
// If BLT's template has not yet been rsynced into the project root, it is
// possible that docroot/sites does not exist.
if (!file_exists($sites_dir)) {
return $sites;
}
$finder = new Finder();
$dirs = $finder
->in($sites_dir)
->directories()
->depth('< 1')
->exclude(['g']);
foreach ($dirs->getIterator() as $dir) {
$sites[] = $dir->getRelativePathname();
}
return $sites;
}
}