| 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 | |||
| 35 | /** |
||
| 36 | * {@inheritDoc} |
||
| 37 | */ |
||
| 38 | #[Override] |
||
| 39 | protected function configure(): void |
||
| 40 | { |
||
| 41 | if ((bool) $this->readMethods && (bool) $this->writeMethods) { |
||
| 42 | $this->bind()->annotatedWith(Read::class)->toInstance($this->readMethods); |
||
| 43 | /** @psalm-suppress MissingDependency */ |
||
| 44 | $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 | // @AuraSql |
||
| 50 | $this->installLocatorDb($methods); |
||
| 51 | // @ReadOnlyConnection @WriteConnection |
||
| 52 | $this->installReadWriteConnection(); |
||
| 53 | // @Transactional |
||
| 54 | $this->install(new TransactionalModule()); |
||
| 55 | } |
||
| 56 | |||
| 57 | protected function installReadWriteConnection(): void |
||
| 58 | { |
||
| 59 | // @ReadOnlyConnection |
||
| 60 | $this->bindInterceptor( |
||
| 61 | $this->matcher->any(), |
||
| 62 | $this->matcher->annotatedWith(ReadOnlyConnection::class), |
||
| 63 | [AuraSqlSlaveDbInterceptor::class], |
||
|
0 ignored issues
–
show
|
|||
| 64 | ); |
||
| 65 | // @WriteConnection |
||
| 66 | $this->bindInterceptor( |
||
| 67 | $this->matcher->any(), |
||
| 68 | $this->matcher->annotatedWith(WriteConnection::class), |
||
| 69 | [AuraSqlMasterDbInterceptor::class], |
||
|
0 ignored issues
–
show
The type
Ray\AuraSqlModule\AuraSqlMasterDbInterceptor was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 70 | ); |
||
| 71 | } |
||
| 72 | |||
| 73 | /** @param string[] $methods */ |
||
| 74 | private function installLocatorDb(array $methods): void |
||
| 75 | { |
||
| 76 | // locator db |
||
| 77 | $this->bindInterceptor( |
||
| 78 | $this->matcher->annotatedWith(AuraSql::class), // @AuraSql in class |
||
| 79 | $this->matcher->logicalAnd( |
||
| 80 | new IsInMethodMatcher($methods), |
||
| 81 | $this->matcher->logicalNot( |
||
| 82 | $this->matcher->annotatedWith(ReadOnlyConnection::class), |
||
| 83 | ), |
||
| 84 | $this->matcher->logicalNot( |
||
| 85 | $this->matcher->annotatedWith(Connection::class), |
||
| 86 | ), |
||
| 87 | ), |
||
| 88 | [AuraSqlConnectionInterceptor::class], |
||
|
0 ignored issues
–
show
The type
Ray\AuraSqlModule\AuraSqlConnectionInterceptor was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 89 | ); |
||
| 90 | } |
||
| 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