Skip to content

Instantly share code, notes, and snippets.

@cburyta
Last active January 16, 2018 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cburyta/44d29d7fdecf6c862df7acdbfcc8796c to your computer and use it in GitHub Desktop.
Save cburyta/44d29d7fdecf6c862df7acdbfcc8796c to your computer and use it in GitHub Desktop.
Pull database configs into a Symfony app using symfony/flex on Platform.sh
# file: config/packages/doctrine.yaml
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
<?php
# file: config/parameters_platform.php
$relationships = getenv("PLATFORM_RELATIONSHIPS");
if (!$relationships) {
return;
}
$relationships = json_decode(base64_decode($relationships), TRUE);
foreach ($relationships['database'] as $endpoint) {
if (empty($endpoint['query']['is_master'])) {
continue;
}
// setup database url for environment with platform.sh env var
$database_url = "{$endpoint['scheme']}://{$endpoint['username']}:{$endpoint['password']}@{$endpoint['host']}:{$endpoint['port']}/{$endpoint['path']}";
// pass the parameter to the app
$container->setParameter('env(DATABASE_URL)', $database_url);
}
# Store session into /tmp.
ini_set('session.save_path', '/tmp/sessions');
# file: config/services.yaml
imports:
- { resource: 'parameters_platform.php', ignore_errors: true }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment