• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nextras / orm / 43632413080

14 Nov 2026 07:30PM UTC coverage: 92.038% (-0.2%) from 92.222%
43632413080

Pull #852

github

web-flow
Merge f17a16229 into 07ee8e7ce
Pull Request #852: Add model rollback and transaction callbacks

153 of 177 new or added lines in 9 files covered. (86.44%)

4601 of 4999 relevant lines covered (92.04%)

6.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.67
/src/Model/SimpleRepositoryLoader.php
1
<?php declare(strict_types = 1);
2

3
namespace Nextras\Orm\Model;
4

5

6
use Nextras\Orm\Entity\IEntity;
7
use Nextras\Orm\Repository\IRepository;
8
use function array_values;
9

10

11
/**
12
 * Loads repositories from a static list of already instantiated repositories.
13
 * All repositories are considered initialized right away.
14
 */
15
class SimpleRepositoryLoader implements IRepositoryLoader
16
{
17
        /** @var array<class-string<IRepository<*>>, IRepository<*>> */
18
        private array $repositories = [];
19

20
        /** @var array<string, class-string<IRepository<*>>> */
21
        private array $nameToClassNameMap = [];
22

23

24
        /**
25
         * @param array<string, IRepository<*>> $repositories Map of a repository simple name and its instance. The name
26
         * is used for accessing the repository by name in contrast to accessing it by its class-string.
27
         */
28
        public function __construct(
5 ✔
29
                array $repositories,
30
                /**
31
                 * @var array<class-string<IEntity>, class-string<IRepository<*>>> Map of an
32
                 * entity class name to the class name of the repository that manages it.
33
                 */
34
                private readonly array $entityClassNameToClassNameMap = [],
2 ✔
35
        )
36
        {
37
                foreach ($repositories as $name => $repository) {
7 ✔
38
                        $className = $repository::class;
7 ✔
39
                        $this->repositories[$className] = $repository;
7 ✔
40
                        $this->nameToClassNameMap[$name] = $className;
7 ✔
41
                }
42
        }
7 ✔
43

44

45
        #[\Override]
46
        #[\NoDiscard]
47
        public function hasRepository(string $className): bool
48
        {
49
                return isset($this->repositories[$className]);
7 ✔
50
        }
51

52

53
        #[\Override]
54
        #[\NoDiscard]
55
        public function hasRepositoryByName(string $name): bool
56
        {
57
                return isset($this->nameToClassNameMap[$name]);
×
58
        }
59

60

61
        /**
62
         * @template T of IRepository<*>
63
         * @param class-string<T> $className
64
         * @return T|null
65
         */
66
        #[\Override]
67
        #[\NoDiscard]
68
        public function getRepository(string $className): IRepository|null
69
        {
70
                /** @var T|null */
71
                return $this->repositories[$className] ?? null;
7 ✔
72
        }
73

74

75
        #[\Override]
76
        #[\NoDiscard]
77
        public function getRepositoryByName(string $name): IRepository|null
78
        {
79
                $className = $this->nameToClassNameMap[$name] ?? null;
7 ✔
80
                return $className !== null ? $this->repositories[$className] : null;
7 ✔
81
        }
82

83

84
        /**
85
         * @template E of IEntity
86
         * @param class-string<E> $entityClassName
87
         * @return class-string<IRepository<E>>|null
88
         */
89
        #[\Override]
90
        #[\NoDiscard]
91
        public function getRepositoryClassNameForEntity(string $entityClassName): string|null
92
        {
93
                /** @var class-string<IRepository<E>>|null */
94
                return $this->entityClassNameToClassNameMap[$entityClassName] ?? null;
7 ✔
95
        }
96

97

98
        #[\Override]
99
        #[\NoDiscard]
100
        public function getRepositories(): array
101
        {
NEW
102
                return array_values($this->repositories);
×
103
        }
104

105

106
        #[\Override]
107
        #[\NoDiscard]
108
        public function getInitializedRepositories(): array
109
        {
110
                return array_values($this->repositories);
7 ✔
111
        }
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc