forked from lombax85/docker-apache-mysql-php-mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
composer_install.php
47 lines (39 loc) · 1.47 KB
/
composer_install.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
<?php
/** TODO
* Permit to remove the "extra" section in the composer.json. Add a script that copies
* from vendor/lombax85/docker to the root directory
*/
// CONFIG
$env_source_filename = "./docker/.env.composer";
$env_dest_filename = "./docker/.env";
$env_backup_file = "./.env.docker.backup";
/**
* Create a default .env file with an unique project name
*/
if (!file_exists($env_dest_filename))
{
if (file_exists($env_backup_file))
{
// a backup exists, use that file
$read = file_get_contents($env_backup_file);
// write the file
file_put_contents($env_dest_filename, $read);
echo "Created .env file in $env_dest_filename using your backup copy at $env_backup_file \n";
} else {
// no backup exists, copy the example file
$read = file_get_contents($env_source_filename);
// replace the project name
// timestamp
$date = new DateTime();
$ts = $date->getTimestamp();
//replace the project name with a unique one
$read = str_replace("COMPOSE_PROJECT_NAME=docker", "COMPOSE_PROJECT_NAME=docker_".$ts, $read);
// since the user doesn't have a backup file, create one
file_put_contents($env_backup_file, $read);
// write the file
file_put_contents($env_dest_filename, $read);
echo "Created a new $env_dest_filename file and added a backup copy to $env_backup_file \n";
}
} else {
echo ".env file already present, not touched \n";
}