|
12 | 12 | */
|
13 | 13 | function mapPlatformShEnvironment() : void
|
14 | 14 | {
|
| 15 | + // Set the application secret if it's not already set. |
| 16 | + if (!isset($_SERVER['APP_SECRET']) && isset($_SERVER['PLATFORM_PROJECT_ENTROPY'])) { |
| 17 | + $_SERVER['APP_SECRET'] = $_SERVER['PLATFORM_PROJECT_ENTROPY']; |
| 18 | + } |
| 19 | + |
| 20 | + // Default to production. You can override this value by setting |
| 21 | + // `env:APP_ENV` as a project variable, or by adding it to the |
| 22 | + // .platform.app.yaml variables block. |
| 23 | + if (!isset($_SERVER['APP_ENV'])) { |
| 24 | + $_SERVER['APP_ENV'] = 'prod'; |
| 25 | + } |
| 26 | + |
| 27 | + if (isset($_SERVER['DATABASE_URL'])) { |
| 28 | + return; |
| 29 | + } |
15 | 30 |
|
16 |
| - $dbRelationshipName = 'database'; |
17 | 31 | // Set the DATABASE_URL for Doctrine, if necessary.
|
18 |
| - if (!getenv('DATABASE_URL')) { |
19 |
| - # "mysql://[email protected]:3306/symfony?charset=utf8mb4&serverVersion=5.7"; |
20 |
| - if (isset($_ENV['PLATFORM_RELATIONSHIPS'])) { |
21 |
| - $relationships = json_decode(base64_decode(getenv('PLATFORM_RELATIONSHIPS')),true); |
22 |
| - foreach ($relationships[$dbRelationshipName] as $endpoint) { |
23 |
| - $dbUrl = ''; |
24 |
| - if (!empty($endpoint['query']['is_master'])) { |
25 |
| - $dbUrl = sprintf("%s://%s:%s@%s:%s/%s?charset=utf8mb4&serverVersion=10.2", |
26 |
| - $endpoint['scheme'], $endpoint['username'], $endpoint['password'], |
27 |
| - $endpoint['host'], $endpoint['port'], |
28 |
| - $endpoint['path']); |
29 |
| - putenv('DATABASE_URL=' . $dbUrl); |
| 32 | + # "mysql://[email protected]:3306/symfony?charset=utf8mb4&serverVersion=5.7"; |
| 33 | + if (isset($_SERVER['PLATFORM_RELATIONSHIPS'])) { |
| 34 | + $relationships = json_decode(base64_decode($_SERVER['PLATFORM_RELATIONSHIPS']), true); |
| 35 | + foreach ($relationships['database'] as $endpoint) { |
| 36 | + if (empty($endpoint['query']['is_master'])) { |
| 37 | + continue; |
| 38 | + } |
| 39 | + |
| 40 | + $dbUrl = sprintf( |
| 41 | + '%s://%s:%s@%s:%d/%s', |
| 42 | + $endpoint['scheme'], |
| 43 | + $endpoint['username'], |
| 44 | + $endpoint['password'], |
| 45 | + $endpoint['host'], |
| 46 | + $endpoint['port'], |
| 47 | + $endpoint['path'] |
| 48 | + ); |
| 49 | + |
| 50 | + switch ($endpoint['scheme']) { |
| 51 | + case 'mysql': |
| 52 | + // Defaults to the latest MariaDB version |
| 53 | + $dbUrl .= '?serverVersion=10.2&charset=utf8mb4'; |
30 | 54 | break;
|
31 |
| - } |
| 55 | + |
| 56 | + case 'pgsql': |
| 57 | + // Postgres 9.6 is the latest supported version on Platform.sh |
| 58 | + $dbUrl .= '?serverVersion=9.6'; |
32 | 59 | }
|
| 60 | + |
| 61 | + $_SERVER['DATABASE_URL'] = $dbUrl; |
| 62 | + |
| 63 | + return; |
33 | 64 | }
|
34 |
| - else { |
35 |
| - // Hack the Doctrine URL to be syntactically valid in a build hook, even |
36 |
| - // though it shouldn't be used. |
37 |
| - $dbUrl = sprintf("%s://%s:%s@%s:%s/%s?charset=utf8mb4&serverVersion=10.2", |
38 |
| - 'mysql', '', '', |
39 |
| - 'localhost', 3306, |
40 |
| - ''); |
41 |
| - $_ENV['DATABASE_URL'] = $dbUrl; |
42 |
| - } |
43 |
| - } |
44 | 65 |
|
45 |
| - // Set the application secret if it's not already set. |
46 |
| - if (!getenv('APP_SECRET') && getenv('PLATFORM_PROJECT_ENTROPY')) { |
47 |
| - putenv('APP_SECRET=' . getenv('PLATFORM_PROJECT_ENTROPY')); |
| 66 | + return; |
48 | 67 | }
|
49 | 68 |
|
50 |
| - // Default to production. You can override this value by setting |
51 |
| - // `env:APP_ENV` as a project variable, or by adding it to the |
52 |
| - // .platform.app.yaml variables block. |
53 |
| - if (!getenv('APP_ENV')) { |
54 |
| - putenv('APP_ENV=prod'); |
55 |
| - } |
| 69 | + // Hack the Doctrine URL to be syntactically valid in a build hook, even |
| 70 | + // though it shouldn't be used. |
| 71 | + $dbUrl = sprintf( |
| 72 | + '%s://%s:%s@%s:%s/%s?charset=utf8mb4&serverVersion=10.2', |
| 73 | + 'mysql', |
| 74 | + '', |
| 75 | + '', |
| 76 | + 'localhost', |
| 77 | + 3306, |
| 78 | + '' |
| 79 | + ); |
| 80 | + |
| 81 | + $_SERVER['DATABASE_URL'] = $dbUrl; |
56 | 82 | }
|
0 commit comments