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
|
|
|
'core.di.delegates' => function (ContainerInterface $container, CompositeContainer $delegates) { |
36
|
|
|
/** @var ORMInterface */ |
37
|
|
|
$orm = $container->get(ORMInterface::class); |
38
|
|
|
/** @psalm-suppress InaccessibleMethod */ |
39
|
|
|
$delegates->attach(new Container($this->getRepositoryFactories($orm))); |
40
|
|
|
|
41
|
|
|
return $delegates; |
42
|
|
|
}, |
43
|
|
|
]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return array<string, Closure> Repository name as key and factory as value |
48
|
|
|
*/ |
49
|
|
|
private function getRepositoryFactories(ORMInterface $orm): array |
50
|
|
|
{ |
51
|
|
|
$schema = $orm->getSchema(); |
52
|
|
|
$result = []; |
53
|
|
|
$roles = []; |
54
|
|
|
foreach ($schema->getRoles() as $role) { |
55
|
|
|
$repository = $schema->define($role, SchemaInterface::REPOSITORY); |
56
|
|
|
if (is_string($repository)) { |
57
|
|
|
$roles[$repository][] = $role; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
foreach ($roles as $repo => $role) { |
61
|
|
|
if (count($role) === 1) { |
62
|
|
|
$result[$repo] = $this->makeRepositoryFactory($orm, current($role)); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
return $result; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @psalm-pure |
70
|
|
|
*/ |
71
|
|
|
private function makeRepositoryFactory(ORMInterface $orm, string $role): Closure |
72
|
|
|
{ |
73
|
|
|
return static fn (): RepositoryInterface => $orm->getRepository($role); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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