From 270dbc60285dacf4202c9549e5b5f8ee4c750bcd Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 6 Aug 2016 12:40:31 +0200 Subject: [PATCH] Created new entity_manager configuration, dropping old database first level config key --- config/autoload/database.global.php | 15 -------------- config/autoload/entity-manager.global.php | 20 +++++++++++++++++++ .../src/Factory/EntityManagerFactory.php | 10 ++++++---- .../test/Factory/EntityManagerFactoryTest.php | 6 ++++-- module/Core/config/entity-manager.config.php | 12 +++++++++++ 5 files changed, 42 insertions(+), 21 deletions(-) delete mode 100644 config/autoload/database.global.php create mode 100644 config/autoload/entity-manager.global.php create mode 100644 module/Core/config/entity-manager.config.php diff --git a/config/autoload/database.global.php b/config/autoload/database.global.php deleted file mode 100644 index 4d05ea36..00000000 --- a/config/autoload/database.global.php +++ /dev/null @@ -1,15 +0,0 @@ - [ - 'driver' => 'pdo_mysql', - 'user' => env('DB_USER'), - 'password' => env('DB_PASSWORD'), - 'dbname' => env('DB_NAME', 'shlink'), - 'charset' => 'utf8', - 'driverOptions' => [ - PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' - ], - ], - -]; diff --git a/config/autoload/entity-manager.global.php b/config/autoload/entity-manager.global.php new file mode 100644 index 00000000..87f99215 --- /dev/null +++ b/config/autoload/entity-manager.global.php @@ -0,0 +1,20 @@ + [ + 'orm' => [ + 'proxies_dir' => 'data/proxies', + ], + 'connection' => [ + 'driver' => 'pdo_mysql', + 'user' => env('DB_USER'), + 'password' => env('DB_PASSWORD'), + 'dbname' => env('DB_NAME', 'shlink'), + 'charset' => 'utf8', + 'driverOptions' => [ + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', + ], + ], + ], + +]; diff --git a/module/Common/src/Factory/EntityManagerFactory.php b/module/Common/src/Factory/EntityManagerFactory.php index e42abb40..533aa322 100644 --- a/module/Common/src/Factory/EntityManagerFactory.php +++ b/module/Common/src/Factory/EntityManagerFactory.php @@ -30,12 +30,14 @@ class EntityManagerFactory implements FactoryInterface $globalConfig = $container->get('config'); $isDevMode = isset($globalConfig['debug']) ? ((bool) $globalConfig['debug']) : false; $cache = $container->has(Cache::class) ? $container->get(Cache::class) : new ArrayCache(); - $dbConfig = isset($globalConfig['database']) ? $globalConfig['database'] : []; + $emConfig = isset($globalConfig['entity_manager']) ? $globalConfig['entity_manager'] : []; + $connecitonConfig = isset($emConfig['connection']) ? $emConfig['connection'] : []; + $ormConfig = isset($emConfig['orm']) ? $emConfig['orm'] : []; - return EntityManager::create($dbConfig, Setup::createAnnotationMetadataConfiguration( - ['module/Core/src/Entity'], + return EntityManager::create($connecitonConfig, Setup::createAnnotationMetadataConfiguration( + isset($ormConfig['entities_paths']) ? $ormConfig['entities_paths'] : [], $isDevMode, - 'data/proxies', + isset($ormConfig['proxies_dir']) ? $ormConfig['proxies_dir'] : null, $cache, false )); diff --git a/module/Common/test/Factory/EntityManagerFactoryTest.php b/module/Common/test/Factory/EntityManagerFactoryTest.php index 53c839ed..2bad3c38 100644 --- a/module/Common/test/Factory/EntityManagerFactoryTest.php +++ b/module/Common/test/Factory/EntityManagerFactoryTest.php @@ -26,8 +26,10 @@ class EntityManagerFactoryTest extends TestCase $sm = new ServiceManager(['services' => [ 'config' => [ 'debug' => true, - 'database' => [ - 'driver' => 'pdo_sqlite', + 'entity_manager' => [ + 'connection' => [ + 'driver' => 'pdo_sqlite', + ], ], ], ]]); diff --git a/module/Core/config/entity-manager.config.php b/module/Core/config/entity-manager.config.php new file mode 100644 index 00000000..e9359519 --- /dev/null +++ b/module/Core/config/entity-manager.config.php @@ -0,0 +1,12 @@ + [ + 'orm' => [ + 'entities_paths' => [ + __DIR__ . '/../src/Entity', + ], + ], + ], + +];