Skip to content

Commit

Permalink
Added default_document_repository_class_name to document manager conf…
Browse files Browse the repository at this point in the history
…iguration
  • Loading branch information
TomHAnderson committed Apr 30, 2020
1 parent 232aa9d commit bbfe5b6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/DoctrineMongoODMModule/Options/Configuration.php
Expand Up @@ -5,6 +5,7 @@
namespace DoctrineMongoODMModule\Options;

use Doctrine\Common\Proxy\AbstractProxyFactory;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository as DefaultDocumentRepository;
use DoctrineMongoODMModule\Logging\Logger;
use Laminas\Stdlib\AbstractOptions;
use function is_bool;
Expand Down Expand Up @@ -125,6 +126,9 @@ class Configuration extends AbstractOptions
/** @var string */
protected $repositoryFactory;

/** @var string */
protected $defaultDocumentRepositoryClassName;

/**
* Number of times to attempt to connect if an exception is encountered
*
Expand Down Expand Up @@ -471,4 +475,16 @@ public function setRepositoryFactory(?string $repositoryFactory) : Configuration

return $this;
}

public function getDefaultDocumentRepositoryClassName()
{
return $this->defaultDocumentRepositoryClassName;
}

public function setDefaultDocumentRepositoryClassName(string $defaultDocumentRepositoryClassName)
{
$this->defaultDocumentRepositoryClassName = $defaultDocumentRepositoryClassName;

return $this;
}
}
5 changes: 5 additions & 0 deletions src/DoctrineMongoODMModule/Service/ConfigurationFactory.php
Expand Up @@ -98,6 +98,11 @@ public function __invoke(ContainerInterface $container, $requestedName, ?array $
}
}

$className = $options->getDefaultDocumentRepositoryClassName();
if ($className) {
$config->setDefaultDocumentRepositoryClassName($className);
}

return $config;
}

Expand Down
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace DoctrineMongoODMModuleTest\Assets;

use Doctrine\ODM\MongoDB\Repository\DocumentRepository;

class DefaultDocumentRepository extends DocumentRepository
{
public function isCustomDefaultDocumentRepository()
{
return true;
}
}
Expand Up @@ -16,6 +16,7 @@
use DoctrineMongoODMModuleTest\AbstractTest;
use DoctrineMongoODMModuleTest\Assets\CustomRepositoryFactory;
use DoctrineMongoODMModuleTest\Assets\CustomType;
use DoctrineMongoODMModuleTest\Assets\DefaultDocumentRepository as CustomDocumentRepository;
use Laminas\ServiceManager\ServiceManager;
use function assert;
use function is_callable;
Expand All @@ -39,7 +40,6 @@ public function testRetryQueryValueIsSetFromConfigurationOptions() : void
public function testCreation() : void
{
$serviceLocator = new ServiceManager();

$serviceLocator->setService('stubbed_logger', $this->getMockForAbstractClass(Logger::class));

$serviceLocator->setService(
Expand Down Expand Up @@ -97,15 +97,16 @@ public function testCreation() : void
'types' => [$typeName = 'foo_type' => $typeClassName = CustomType::class],
'classMetadataFactoryName' => 'stdClass',
'repositoryFactory' => CustomRepositoryFactory::class,
'default_document_repository_class_name' => CustomDocumentRepository::class,
],
],
],
]
);

$factory = new ConfigurationFactory('odm_test');

$config = $factory->createService($serviceLocator);

assert($config instanceof Configuration);

self::assertInstanceOf(Configuration::class, $config);
Expand All @@ -130,5 +131,7 @@ public function testCreation() : void

self::assertInstanceOf($typeClassName, Type::getType($typeName));
self::assertSame($repositoryFactory, $config->getRepositoryFactory());

self::assertSame(CustomDocumentRepository::class, $config->getDefaultDocumentRepositoryClassName());
}
}

0 comments on commit bbfe5b6

Please sign in to comment.