/
BedrockInstaller.php
64 lines (54 loc) · 1.72 KB
/
BedrockInstaller.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
<?php
namespace WP_CLI_Valet\Installer;
use WP_CLI_Valet\Composer;
use WP_CLI_Valet\ValetCommand as Command;
class BedrockInstaller extends WordPressInstaller
{
use ComposerRequireSqliteIntegration;
protected $contentDir = 'web/app';
/**
* Download project files.
*/
public function download()
{
Command::debug('Installing Bedrock via Composer');
if (! is_dir($full_path = $this->props->projectRoot())) {
mkdir($full_path, 0755, true);
}
Composer::createProject('roots/bedrock', $this->props->site_name, [
'working-dir' => $this->props->parentDirectory(),
'no-interaction' => true,
]);
}
/**
* Configure the .env
*/
public function configure()
{
Command::debug('Configuring .env');
$env_contents = str_replace(
[
'database_name',
'database_user',
'database_password',
'database_host',
'http://example.com',
],
[
$this->props->databaseName(),
$this->props->option('dbuser'),
$this->props->databasePassword(),
$this->props->option('dbhost', 'localhost'),
$this->props->fullUrl(),
],
file_get_contents($this->props->fullPath('.env.example'))
);
// DB_PREFIX value is quoted in newer versions, not in older.
$env_contents = preg_replace(
'/# DB_PREFIX=.*/',
sprintf('DB_PREFIX=\'%s\'', $this->props->option('dbprefix')),
$env_contents
);
file_put_contents($this->props->fullPath('.env'), $env_contents);
}
}