-
Notifications
You must be signed in to change notification settings - Fork 231
/
ServiceDocumentRepository.php
43 lines (38 loc) · 1.44 KB
/
ServiceDocumentRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Doctrine\Bundle\MongoDBBundle\Repository;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\DocumentRepository;
use LogicException;
/**
* Optional DocumentRepository base class with a simplified constructor (for autowiring).
*
* To use in your class, inject the "registry" service and call
* the parent constructor. For example:
*
* class YourDocumentRepository extends ServiceDocumentRepository
* {
* public function __construct(RegistryInterface $registry)
* {
* parent::__construct($registry, YourDocument::class);
* }
* }
*/
class ServiceDocumentRepository extends DocumentRepository implements ServiceDocumentRepositoryInterface
{
/**
* @param string $documentClass The class name of the entity this repository manages
*/
public function __construct(ManagerRegistry $registry, $documentClass)
{
/** @var DocumentManager $manager */
$manager = $registry->getManagerForClass($documentClass);
if ($manager === null) {
throw new LogicException(sprintf(
'Could not find the document manager for class "%s". Check your Doctrine configuration to make sure it is configured to load this document’s metadata.',
$documentClass
));
}
parent::__construct($manager, $manager->getUnitOfWork(), $manager->getClassMetadata($documentClass));
}
}