|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Cycle\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use Closure; |
|
8
|
|
|
use Cycle\ORM\ORMInterface; |
|
9
|
|
|
use Cycle\ORM\RepositoryInterface; |
|
10
|
|
|
use Cycle\ORM\SchemaInterface; |
|
11
|
|
|
use Psr\Container\ContainerInterface; |
|
12
|
|
|
use Yiisoft\Di\Container; |
|
|
|
|
|
|
13
|
|
|
use Yiisoft\Di\CompositeContainer; |
|
|
|
|
|
|
14
|
|
|
use Yiisoft\Di\Contracts\ServiceProviderInterface; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
use function is_string; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* This provider provides factories to the container for creating Cycle entity repositories. |
|
20
|
|
|
* Repository list is compiled based on data from the database schema. |
|
21
|
|
|
*/ |
|
22
|
|
|
final class RepositoryProvider implements ServiceProviderInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public function getDefinitions(): array |
|
25
|
|
|
{ |
|
26
|
|
|
return []; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return array<Closure> |
|
31
|
|
|
*/ |
|
32
|
|
|
public function getExtensions(): array |
|
33
|
|
|
{ |
|
34
|
|
|
return [ |
|
35
|
|
|
ContainerInterface::class => function (ContainerInterface $container, ContainerInterface $extended) { |
|
36
|
|
|
/** @var ORMInterface */ |
|
37
|
|
|
$orm = $extended->get(ORMInterface::class); |
|
38
|
|
|
/** @psalm-suppress InaccessibleMethod */ |
|
39
|
|
|
$repositoryContainer = new Container($this->getRepositoryFactories($orm)); |
|
40
|
|
|
$compositeContainer = new CompositeContainer(); |
|
41
|
|
|
$compositeContainer->attach($repositoryContainer); |
|
42
|
|
|
$compositeContainer->attach($extended); |
|
43
|
|
|
|
|
44
|
|
|
return $compositeContainer; |
|
45
|
|
|
} |
|
46
|
|
|
]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return array<string, Closure> Repository name as key and factory as value |
|
51
|
|
|
*/ |
|
52
|
|
|
private function getRepositoryFactories(ORMInterface $orm): array |
|
53
|
|
|
{ |
|
54
|
|
|
$schema = $orm->getSchema(); |
|
55
|
|
|
$result = []; |
|
56
|
|
|
$roles = []; |
|
57
|
|
|
foreach ($schema->getRoles() as $role) { |
|
58
|
|
|
$repository = $schema->define($role, SchemaInterface::REPOSITORY); |
|
59
|
|
|
if (is_string($repository)) { |
|
60
|
|
|
$roles[$repository][] = $role; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
foreach ($roles as $repo => $role) { |
|
64
|
|
|
if (count($role) === 1) { |
|
65
|
|
|
$result[$repo] = $this->makeRepositoryFactory($orm, current($role)); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
return $result; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @psalm-pure |
|
73
|
|
|
*/ |
|
74
|
|
|
private function makeRepositoryFactory(ORMInterface $orm, string $role): Closure |
|
75
|
|
|
{ |
|
76
|
|
|
return static fn(): RepositoryInterface => $orm->getRepository($role); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths