Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
53.12% covered (warning)
53.12%
17 / 32
53.85% covered (warning)
53.85%
7 / 13
CRAP
0.00% covered (danger)
0.00%
0 / 1
MergedRegistry
53.12% covered (warning)
53.12%
17 / 32
53.85% covered (warning)
53.85%
7 / 13
56.18
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDefaultManagerName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getManager
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getManagers
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 resetManager
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getManagerNames
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getRepository
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
5.02
 getManagerForClass
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getDefaultConnectionName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getConnection
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getConnections
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getConnectionNames
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 __call
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\ApieBundle\Doctrine;
3
4use Apie\DoctrineEntityDatalayer\OrmBuilder;
5use Doctrine\Persistence\ManagerRegistry;
6use Doctrine\Persistence\ObjectManager;
7use Doctrine\Persistence\ObjectRepository;
8
9class MergedRegistry implements ManagerRegistry
10{
11    public const APIE_MANAGER_NAME = 'apie_manager';
12    public const APIE_CONNECTION_NAME = 'apie_connection';
13
14    public function __construct(
15        private ManagerRegistry $internal,
16        private OrmBuilder $ormBuilder
17    ) {
18    }
19
20    public function getDefaultManagerName(): string
21    {
22        return $this->internal->getDefaultManagerName();
23    }
24
25    public function getManager(?string $name = null): ObjectManager
26    {
27        if ($name === self::APIE_MANAGER_NAME) {
28            return $this->ormBuilder->createEntityManager();
29        }
30        return $this->internal->getManager($name);
31    }
32
33    public function getManagers(): array
34    {
35        $internal = $this->internal->getManagers();
36        $internal[self::APIE_MANAGER_NAME] = $this->ormBuilder->createEntityManager();
37
38        return $internal;
39    }
40
41    public function resetManager(?string $name = null): ObjectManager
42    {
43        $this->ormBuilder->createEntityManager()->close();
44        return $this->internal->resetManager($name);
45    }
46
47    public function getManagerNames(): array
48    {
49        $internal = $this->internal->getManagerNames();
50        $internal[self::APIE_MANAGER_NAME] = 'doctrine.orm.apie_manager_entity_manager';
51        return $internal;
52    }
53
54    public function getRepository(
55        string $persistentObject,
56        ?string $persistentManagerName = null
57    ): ObjectRepository {
58        if ($persistentManagerName === null && str_starts_with($persistentObject, $this->ormBuilder->getGeneratedNamespace())) {
59            return $this->ormBuilder->createEntityManager()->getRepository($persistentObject);
60        }
61        if ($persistentManagerName === self::APIE_MANAGER_NAME) {
62            return $this->ormBuilder->createEntityManager()->getRepository($persistentObject);
63        }
64
65        return $this->internal->getRepository($persistentObject, $persistentManagerName);
66    }
67
68    public function getManagerForClass(string $class): ?ObjectManager
69    {
70        if (str_starts_with($class, $this->ormBuilder->getGeneratedNamespace())) {
71            return $this->ormBuilder->createEntityManager();
72        }
73
74        return $this->internal->getManagerForClass($class);
75    }
76
77    public function getDefaultConnectionName(): string
78    {
79        return $this->internal->getDefaultConnectionName();
80    }
81
82    public function getConnection(?string $name = null): object
83    {
84        if ($name === self::APIE_CONNECTION_NAME) {
85            return $this->ormBuilder->createEntityManager()->getConnection();
86        }
87        return $this->internal->getConnection($name);
88    }
89
90    public function getConnections(): array
91    {
92        $internal = $this->internal->getConnections();
93        $internal[self::APIE_CONNECTION_NAME] = $this->getConnection(self::APIE_CONNECTION_NAME);
94
95        return $internal;
96    }
97
98    public function getConnectionNames(): array
99    {
100        $internal = $this->internal->getConnectionNames();
101        $internal[self::APIE_CONNECTION_NAME] = 'doctrine.dbal.apie_connection';
102
103        return $internal;
104    }
105
106    /**
107     * @param array<int, mixed> $args
108     */
109    public function __call(string $method, array $args): mixed
110    {
111        return $this->internal->$method(...$args);
112    }
113}