|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Ray\AuraSqlModule; |
|
6
|
|
|
|
|
7
|
|
|
use Aura\Sql\ConnectionLocatorInterface; |
|
8
|
|
|
use Override; |
|
9
|
|
|
use Ray\AuraSqlModule\Annotation\AuraSql; |
|
10
|
|
|
use Ray\AuraSqlModule\Annotation\Read; |
|
11
|
|
|
use Ray\AuraSqlModule\Annotation\ReadOnlyConnection; |
|
12
|
|
|
use Ray\AuraSqlModule\Annotation\Write; |
|
13
|
|
|
use Ray\AuraSqlModule\Annotation\WriteConnection; |
|
14
|
|
|
use Ray\Di\AbstractModule; |
|
15
|
|
|
|
|
16
|
|
|
use function array_merge; |
|
17
|
|
|
|
|
18
|
|
|
final class AuraSqlLocatorModule extends AbstractModule |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @phpstan-param array<string> $readMethods |
|
22
|
|
|
* @phpstan-param array<string> $writeMethods |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct( |
|
25
|
|
|
private readonly ConnectionLocatorInterface $connectionLocator, |
|
26
|
|
|
/** @var string[] */ |
|
27
|
|
|
private readonly array $readMethods = [], |
|
28
|
|
|
/** @var string[] */ |
|
29
|
|
|
private readonly array $writeMethods = [], |
|
30
|
|
|
?AbstractModule $module = null |
|
31
|
|
|
) { |
|
32
|
|
|
parent::__construct($module); |
|
33
|
|
|
} |
|
34
|
3 |
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritDoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
#[Override] |
|
39
|
|
|
protected function configure(): void |
|
40
|
3 |
|
{ |
|
41
|
3 |
|
if ((bool) $this->readMethods && (bool) $this->writeMethods) { |
|
42
|
3 |
|
$this->bind()->annotatedWith(Read::class)->toInstance($this->readMethods); |
|
43
|
3 |
|
/** @psalm-suppress MissingDependency */ |
|
44
|
3 |
|
$this->bind()->annotatedWith(Write::class)->toInstance($this->writeMethods); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$this->bind(ConnectionLocatorInterface::class)->toInstance($this->connectionLocator); |
|
48
|
|
|
$methods = array_merge($this->readMethods, $this->writeMethods); |
|
49
|
3 |
|
// @AuraSql |
|
50
|
|
|
$this->installLocatorDb($methods); |
|
51
|
3 |
|
// @ReadOnlyConnection @WriteConnection |
|
52
|
3 |
|
$this->installReadWriteConnection(); |
|
53
|
3 |
|
// @Transactional |
|
54
|
|
|
$this->install(new TransactionalModule()); |
|
55
|
3 |
|
} |
|
56
|
3 |
|
|
|
57
|
|
|
protected function installReadWriteConnection(): void |
|
58
|
3 |
|
{ |
|
59
|
|
|
// @ReadOnlyConnection |
|
60
|
3 |
|
$this->bindInterceptor( |
|
61
|
|
|
$this->matcher->any(), |
|
62
|
3 |
|
$this->matcher->annotatedWith(ReadOnlyConnection::class), |
|
63
|
|
|
[AuraSqlSlaveDbInterceptor::class], |
|
|
|
|
|
|
64
|
3 |
|
); |
|
65
|
3 |
|
// @WriteConnection |
|
66
|
|
|
$this->bindInterceptor( |
|
67
|
3 |
|
$this->matcher->any(), |
|
68
|
|
|
$this->matcher->annotatedWith(WriteConnection::class), |
|
69
|
|
|
[AuraSqlMasterDbInterceptor::class], |
|
|
|
|
|
|
70
|
3 |
|
); |
|
71
|
3 |
|
} |
|
72
|
3 |
|
|
|
73
|
3 |
|
/** @param string[] $methods */ |
|
74
|
|
|
private function installLocatorDb(array $methods): void |
|
75
|
|
|
{ |
|
76
|
3 |
|
// locator db |
|
77
|
3 |
|
$this->bindInterceptor( |
|
78
|
3 |
|
$this->matcher->annotatedWith(AuraSql::class), // @AuraSql in class |
|
79
|
3 |
|
$this->matcher->logicalAnd( |
|
80
|
|
|
new IsInMethodMatcher($methods), |
|
81
|
3 |
|
$this->matcher->logicalNot( |
|
82
|
|
|
$this->matcher->annotatedWith(ReadOnlyConnection::class), |
|
83
|
|
|
), |
|
84
|
|
|
$this->matcher->logicalNot( |
|
85
|
|
|
$this->matcher->annotatedWith(Connection::class), |
|
86
|
3 |
|
), |
|
87
|
|
|
), |
|
88
|
|
|
[AuraSqlConnectionInterceptor::class], |
|
|
|
|
|
|
89
|
3 |
|
); |
|
90
|
3 |
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
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