forked from tarlepp/symfony-flex-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
40 lines (34 loc) · 1.33 KB
/
Copy pathbootstrap.php
File metadata and controls
40 lines (34 loc) · 1.33 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
<?php
declare(strict_types = 1);
/**
* Application bootstrap file to load specified environment variables.
*
* @see ./public/index.php
* @see ./tests/bootstrap.php
*
* @package App
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
*/
use Symfony\Component\Dotenv\Dotenv;
$environmentFile = (string)\getenv('ENVIRONMENT_FILE');
$readableChannel = (string)\getenv('ENV_TEST_CHANNEL_READABLE');
// Application is started against 'fastest' library, so we need to override database name manually
if (\strlen($readableChannel) > 0) {
// Parse current '.env.test' file
$variables = (new Dotenv())->parse(\file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . $environmentFile));
// Specify new database name for current test env
$databaseName = $variables['DATABASE_NAME'] . '_' . $readableChannel;
// Replace DATABASE_URL variable
$variables['DATABASE_URL'] = \str_replace(
'/' . $variables['DATABASE_NAME'] . '?',
'/' . $databaseName . '?',
$variables['DATABASE_URL']
);
// Replace DATABASE_NAME variable
$variables['DATABASE_NAME'] = $databaseName;
// And finally populate new variables to current environment
(new Dotenv())->populate($variables);
} else {
// Load environment variables normally
(new Dotenv())->load(__DIR__ . DIRECTORY_SEPARATOR . $environmentFile);
}