This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
forked from mautic/docker-mautic
-
Notifications
You must be signed in to change notification settings - Fork 4
/
makeconfig.php
124 lines (105 loc) · 2.18 KB
/
makeconfig.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
<?php
// Args: 0 => makedb.php, 1 => "$MAUTIC_DB_HOST", 2 => "$MAUTIC_DB_USER", 3 => "$MAUTIC_DB_PASSWORD", 4 => "$MAUTIC_DB_NAME"
$stderr = fopen('php://stderr', 'w');
fwrite($stderr, "\nWriting initial Mautic config\n");
// Figure out if we have a port in the database host string
if (strpos($argv[1], ':') !== false)
{
list($host, $port) = explode(':', $argv[1], 2);
}
else
{
$host = $argv[1];
$port = 3306;
}
$parameters = array(
'db_driver' => 'pdo_mysql',
'db_host' => $host,
'db_port' => $port,
'db_name' => $argv[4],
'db_user' => $argv[2],
'db_password' => $argv[3],
'install_source' => 'Docker'
);
$path = '/var/www/html/app/config/local.php';
$rendered = render($parameters);
$status = file_put_contents($path, $rendered);
if ($status === false) {
fwrite($stderr, "\nCould not write configuration file to $path, you can create this file with the following contents:\n\n$rendered\n");
}
/**
* Renders parameters as a string.
*
* @param array $parameters
*
* @return string
*/
function render(array $parameters)
{
$string = "<?php\n";
$string .= "\$parameters = array(\n";
foreach ($parameters as $key => $value)
{
if ($value !== '')
{
if (is_string($value))
{
$value = "'" . addslashes($value) . "'";
}
elseif (is_bool($value))
{
$value = ($value) ? 'true' : 'false';
}
elseif (is_null($value))
{
$value = 'null';
}
elseif (is_array($value))
{
$value = renderArray($value);
}
$string .= "\t'$key' => $value,\n";
}
}
$string .= ");\n";
return $string;
}
/**
* Renders an array of parameters as a string.
*
* @param array $array
* @param bool $addClosingComma
*
* @return string
*/
function renderArray(array $array, $addClosingComma = false)
{
$string = "array(";
$first = true;
foreach ($array as $key => $value)
{
if (!$first)
{
$string .= ',';
}
if (is_string($key))
{
$string .= '"' . $key . '" => ';
}
if (is_array($value))
{
$string .= $this->renderArray($value, true);
}
else
{
$string .= '"' . addslashes($value) . '"';
}
$first = false;
}
$string .= ")";
if ($addClosingComma)
{
$string .= ',';
}
return $string;
}