Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ public static function getDB(ConfigRepository $config)
*/
public static function check(ConfigRepository $config)
{
if ( ! isset($config[self::ODM_CONFIG_NAME])) {
if (! isset($config[self::ODM_CONFIG_NAME])) {
throw new Exception('Doctrine ODM configuration not registered.');
}

if ( ! isset($config[self::ODM_DB_CONFIG_NAME])) {
if (! isset($config[self::ODM_DB_CONFIG_NAME])) {
throw new Exception('Database configuration not registered.');
}
}
Expand Down Expand Up @@ -238,12 +238,18 @@ public static function normalizeConnectionConfig()
$config = self::$liveConfig->get(self::ODM_DB_CONFIG_NAME);
$dbConfig = $config['connections'][$config['default']];

$server = $dbConfig['host'] . ':' . $dbConfig['port'] ?? self::DEFAULT_MONGODB_PORT;
$options = array_merge(
[
'username' => $dbConfig['username'],
'password' => $dbConfig['password']
],
$dbConfig['options'] ?? []
);

return [
'host' => $dbConfig['host'],
'port' => ! empty($dbConfig['port']) ? $dbConfig['port'] : self::DEFAULT_MONGODB_PORT,
'user' => $dbConfig['username'],
'password' => $dbConfig['password'],
'server' => $server,
'options' => $options
];
}
}

30 changes: 20 additions & 10 deletions src/DoctrineServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,21 @@ protected function createDocumentManager(ConfigRepository $config)
$simpleAnnotations = array_get($doctrineConfig, 'simple_annotations', false);
$cache = $this->configureCache($doctrineConfig);

$metadataConfiguration = $this->createMetadataConfiguration($type, $paths, $debug, $proxyDir, $cache,
$simpleAnnotations);
$metadataConfiguration = $this->createMetadataConfiguration(
$type,
$paths,
$debug,
$proxyDir,
$cache,
$simpleAnnotations
);

$this->configureMetadataConfiguration($metadataConfiguration, $doctrineConfig, $databaseConfig);

$eventManager = new EventManager;

$this->configureEventManager($doctrineConfig, $eventManager);
$connection = new Connection($connectionConfig['host'], [], $metadataConfiguration);
$connection = new Connection($connectionConfig['server'], $connectionConfig['options'], $metadataConfiguration);

$documentManager = DocumentManager::create($connection, $metadataConfiguration, $eventManager);

Expand Down Expand Up @@ -147,8 +153,13 @@ protected function createMetadataConfiguration(
) {
switch ($type) {
case self::METADATA_ANNOTATIONS:
return Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, $proxyDir, $cache,
$useSimpleAnnotationReader);
return Setup::createAnnotationMetadataConfiguration(
$paths,
$isDevMode,
$proxyDir,
$cache,
$useSimpleAnnotationReader
);
case self::METADATA_XML:
return Setup::createXMLMetadataConfiguration($paths, $isDevMode, $proxyDir, $cache);
case self::METADATA_YAML:
Expand Down Expand Up @@ -189,7 +200,7 @@ protected function configureMetadataConfiguration(
}
}

if ( ! empty($doctrineConfig['repository'])) {
if (! empty($doctrineConfig['repository'])) {
$configuration->setDefaultRepositoryClassName($doctrineConfig['repository']);
}

Expand All @@ -205,10 +216,9 @@ protected function configureMetadataConfiguration(
$configuration->setAutoGenerateHydratorClasses($doctrineConfig['hydrator']['auto_generate']);
}
}
if ( ! empty($databaseConfig['connections'][$databaseConfig['default']]['database'])) {
if (! empty($databaseConfig['connections'][$databaseConfig['default']]['database'])) {
$configuration->setDefaultDB($databaseConfig['connections'][$databaseConfig['default']]['database']);
}

}

/**
Expand Down Expand Up @@ -236,7 +246,7 @@ protected function configureDocumentManager(array $doctrineConfig, DocumentManag
{
if (isset($doctrineConfig['filters'])) {
foreach ($doctrineConfig['filters'] as $name => $filter) {
if ( ! array_get($filter, 'enabled', false)) {
if (! array_get($filter, 'enabled', false)) {
continue;
}
$documentManager->getFilterCollection()->enable($name);
Expand All @@ -246,7 +256,7 @@ protected function configureDocumentManager(array $doctrineConfig, DocumentManag
// @see http://doctrine-mongodb-odm.readthedocs.org/en/latest/reference/basic-mapping.html#custom-mapping-types
if (isset($doctrineConfig['types'])) {
foreach ($doctrineConfig['types'] as $name => $className) {
if ( ! Type::hasType($name)) {
if (! Type::hasType($name)) {
Type::addType($name, $className);
} else {
Type::overrideType($name, $className);
Expand Down