mirror of https://github.com/wallabag/wallabag.git
Use URL to configure DBAL
This commit is contained in:
parent
a6af149fa3
commit
aa7dd67131
|
@ -97,5 +97,47 @@ class AppKernel extends Kernel
|
||||||
// $container->setParameter('container.dumper.inline_class_loader', true);
|
// $container->setParameter('container.dumper.inline_class_loader', true);
|
||||||
$container->addObjectResource($this);
|
$container->addObjectResource($this);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$loader->load(function (ContainerBuilder $container) {
|
||||||
|
$this->processDatabaseParameters($container);
|
||||||
|
|
||||||
|
if ('test' === $container->getParameter('kernel.environment')) {
|
||||||
|
$this->processDatabaseParameters($container, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function processDatabaseParameters(ContainerBuilder $container, bool $isTest = false)
|
||||||
|
{
|
||||||
|
$prefix = '';
|
||||||
|
|
||||||
|
if ($isTest) {
|
||||||
|
$prefix = 'test_';
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($container->getParameter($prefix . 'database_driver')) {
|
||||||
|
case 'pdo_mysql':
|
||||||
|
$scheme = 'mysql';
|
||||||
|
break;
|
||||||
|
case 'pdo_pgsql':
|
||||||
|
$scheme = 'pgsql';
|
||||||
|
break;
|
||||||
|
case 'pdo_sqlite':
|
||||||
|
$scheme = 'sqlite';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new \RuntimeException('Unsupported database driver: ' . $container->getParameter($prefix . 'database_driver'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$container->setParameter($prefix . 'database_scheme', $scheme);
|
||||||
|
|
||||||
|
if ('sqlite' === $scheme) {
|
||||||
|
$container->setParameter($prefix . 'database_name', $container->getParameter($prefix . 'database_path'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$container->setParameter($prefix . 'database_user', (string) $container->getParameter($prefix . 'database_user'));
|
||||||
|
$container->setParameter($prefix . 'database_password', (string) $container->getParameter($prefix . 'database_password'));
|
||||||
|
$container->setParameter($prefix . 'database_port', (string) $container->getParameter($prefix . 'database_port'));
|
||||||
|
$container->setParameter($prefix . 'database_socket', (string) $container->getParameter($prefix . 'database_socket'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ parameters:
|
||||||
# Allows to use the live reload feature for changes in assets
|
# Allows to use the live reload feature for changes in assets
|
||||||
use_webpack_dev_server: false
|
use_webpack_dev_server: false
|
||||||
craue_config.cache_adapter.class: Craue\ConfigBundle\CacheAdapter\SymfonyCacheComponentAdapter
|
craue_config.cache_adapter.class: Craue\ConfigBundle\CacheAdapter\SymfonyCacheComponentAdapter
|
||||||
|
env(DATABASE_URL): '%database_scheme%://%database_user%:%database_password%@%database_host%:%database_port%/%database_name%?unix_socket=%database_socket%&charset=%database_charset%'
|
||||||
|
|
||||||
framework:
|
framework:
|
||||||
#esi: ~
|
#esi: ~
|
||||||
|
@ -48,15 +49,7 @@ twig:
|
||||||
# Doctrine Configuration
|
# Doctrine Configuration
|
||||||
doctrine:
|
doctrine:
|
||||||
dbal:
|
dbal:
|
||||||
driver: "%database_driver%"
|
url: '%env(resolve:DATABASE_URL)%'
|
||||||
host: "%database_host%"
|
|
||||||
port: "%database_port%"
|
|
||||||
dbname: "%database_name%"
|
|
||||||
user: "%database_user%"
|
|
||||||
password: "%database_password%"
|
|
||||||
charset: "%database_charset%"
|
|
||||||
path: "%database_path%"
|
|
||||||
unix_socket: "%database_socket%"
|
|
||||||
types:
|
types:
|
||||||
json_array: Wallabag\CoreBundle\Doctrine\JsonArrayType
|
json_array: Wallabag\CoreBundle\Doctrine\JsonArrayType
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ imports:
|
||||||
- { resource: services_test.yml }
|
- { resource: services_test.yml }
|
||||||
|
|
||||||
parameters:
|
parameters:
|
||||||
|
env(TEST_DATABASE_URL): '%test_database_scheme%://%test_database_user%:%test_database_password%@%test_database_host%:%test_database_port%/%test_database_name%?unix_socket=%test_database_socket%&charset=%test_database_charset%'
|
||||||
fosuser_registration: true
|
fosuser_registration: true
|
||||||
|
|
||||||
framework:
|
framework:
|
||||||
|
@ -23,15 +24,7 @@ web_profiler:
|
||||||
|
|
||||||
doctrine:
|
doctrine:
|
||||||
dbal:
|
dbal:
|
||||||
driver: "%test_database_driver%"
|
url: '%env(resolve:TEST_DATABASE_URL)%'
|
||||||
host: "%test_database_host%"
|
|
||||||
port: "%test_database_port%"
|
|
||||||
dbname: "%test_database_name%"
|
|
||||||
user: "%test_database_user%"
|
|
||||||
password: "%test_database_password%"
|
|
||||||
charset: "%test_database_charset%"
|
|
||||||
path: "%env(TEST_DATABASE_PATH)%"
|
|
||||||
unix_socket: "%test_database_socket%"
|
|
||||||
|
|
||||||
orm:
|
orm:
|
||||||
metadata_cache_driver:
|
metadata_cache_driver:
|
||||||
|
|
Loading…
Reference in New Issue