/** * {@inheritDoc} * * Overwrite mongodb config from parent in cloud case. * * @param ContainerBuilder $container instance * * @return void */ public function prepend(ContainerBuilder $container) { parent::prepend($container); /** [nue] * this is a workaround for a current symfony bug: * https://github.com/symfony/symfony/issues/7555 * * we *want* to be able to override any param with our env variables.. * so we do again, what the kernel did already here.. ;-) * * @todo move this out of file bundle as it is much more global * @todo add proper documentation on this "feature" to a README */ foreach ($_SERVER as $key => $value) { if (0 === strpos($key, 'SYMFONY__')) { $container->setParameter(strtolower(str_replace('__', '.', substr($key, 9))), $value); } } // grab mongo config directly from vcap... $services = getenv('VCAP_SERVICES'); if (!empty($services)) { $services = json_decode($services, true); $mongo = $services['mongodb-2.2'][0]['credentials']; $container->setParameter('mongodb.default.server.uri', $mongo['url']); $container->setParameter('mongodb.default.server.db', $mongo['db']); } else { $container->setParameter('mongodb.default.server.uri', $container->getParameter('graviton.mongodb.default.server.uri')); $container->setParameter('mongodb.default.server.db', $container->getParameter('graviton.mongodb.default.server.db')); } }
/** * Overwrite S3 config from cloud if available * * @param ContainerBuilder $container instance * * @return void */ public function prepend(ContainerBuilder $container) { parent::prepend($container); // populated from cf's VCAP_SERVICES variable $services = getenv('VCAP_SERVICES'); if (!empty($services)) { $services = json_decode($services, true); $creds = $services['atmoss3'][0]['credentials']; $container->setParameter('graviton.file.gaufrette.backend', 's3'); $container->setParameter('graviton.aws_s3.client.endpoint', sprintf('https://%s', $creds['accessHost'])); $container->setParameter('graviton.aws_s3.client.key', $creds['accessKey']); $container->setParameter('graviton.aws_s3.client.secret', $creds['sharedSecret']); $container->setParameter('graviton.aws_s3.bucket_name', $services['atmoss3'][0]['name']); } else { $container->setParameter('graviton.file.gaufrette.backend', $container->getParameter('graviton.file.backend')); $container->setParameter('graviton.aws_s3.client.endpoint', $container->getParameter('graviton.file.s3.endpoint')); $container->setParameter('graviton.aws_s3.client.key', $container->getParameter('graviton.file.s3.key')); $container->setParameter('graviton.aws_s3.client.secret', $container->getParameter('graviton.file.s3.secret')); $container->setParameter('graviton.aws_s3.bucket_name', $container->getParameter('graviton.file.s3.bucket_name')); } }
/** * {@inheritDoc} * * Overwrite mongodb config from parent in cloud case. * * @param ContainerBuilder $container instance * * @return void */ public function prepend(ContainerBuilder $container) { parent::prepend($container); /** [nue] * this is a workaround for a new symfony feature: * https://github.com/symfony/symfony/issues/7555 * * we *need* to be able to override any param with our env variables.. * so we do again, what the kernel did already here.. ;-) * * Since fabpot seems to have said bye to this feature we are * re-implementing it here. We are also adding some fancy json * parsing for hashes and arrays while at it. * * @todo move this out of file bundle as it is much more global * @todo add proper documentation on this "feature" to a README */ foreach ($_SERVER as $key => $value) { if (0 === strpos($key, 'SYMFONY__')) { if (substr($value, 0, 1) == '[' || substr($value, 0, 1) == '{') { $value = json_decode($value, true); if (JSON_ERROR_NONE !== json_last_error()) { throw new \RuntimeException(sprintf('error "%s" in env variable "%s"', json_last_error_msg(), $key)); } } $container->setParameter(strtolower(str_replace('__', '.', substr($key, 9))), $value); } } // grab mongo config directly from vcap... $services = getenv('VCAP_SERVICES'); if (!empty($services)) { $services = json_decode($services, true); $mongo = $services['mongodb'][0]['credentials']; $container->setParameter('mongodb.default.server.uri', $mongo['uri']); $container->setParameter('mongodb.default.server.db', $mongo['database']); } else { $container->setParameter('mongodb.default.server.uri', $container->getParameter('graviton.mongodb.default.server.uri')); $container->setParameter('mongodb.default.server.db', $container->getParameter('graviton.mongodb.default.server.db')); } }
/** * Overwrite rabbitmq config from cloud if available * * @param ContainerBuilder $container instance * * @return void */ public function prepend(ContainerBuilder $container) { parent::prepend($container); // populated from cf's VCAP_SERVICES variable $services = getenv('VCAP_SERVICES'); if (!empty($services)) { $services = json_decode($services, true); if (!isset($services['rabbitmq'][0]['credentials'])) { return false; } $creds = $services['rabbitmq'][0]['credentials']; $container->setParameter('rabbitmq.host', $creds['host']); $container->setParameter('rabbitmq.port', $creds['port']); $container->setParameter('rabbitmq.user', $creds['username']); $container->setParameter('rabbitmq.password', $creds['password']); $container->setParameter('rabbitmq.vhost', $creds['vhost']); } else { $container->setParameter('rabbitmq.host', $container->getParameter('graviton.rabbitmq.host')); $container->setParameter('rabbitmq.port', $container->getParameter('graviton.rabbitmq.port')); $container->setParameter('rabbitmq.user', $container->getParameter('graviton.rabbitmq.user')); $container->setParameter('rabbitmq.password', $container->getParameter('graviton.rabbitmq.password')); $container->setParameter('rabbitmq.vhost', $container->getParameter('graviton.rabbitmq.vhost')); } }