| 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\Aop\MethodInterceptor; |
||
| 10 | use Ray\Aop\MethodInvocation; |
||
| 11 | use ReflectionProperty; |
||
| 12 | |||
| 13 | final readonly class AuraSqlMasterDbInterceptor implements MethodInterceptor |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 14 | { |
||
| 15 | public const string PROP = 'pdo'; |
||
| 16 | |||
| 17 | public function __construct(private ConnectionLocatorInterface $connectionLocator) |
||
| 18 | { |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * {@inheritDoc} |
||
| 23 | */ |
||
| 24 | #[Override] |
||
| 25 | public function invoke(MethodInvocation $invocation) |
||
| 26 | { |
||
| 27 | $object = $invocation->getThis(); |
||
| 28 | $ref = new ReflectionProperty($object, self::PROP); |
||
| 29 | $connection = $this->connectionLocator->getWrite(); |
||
| 30 | $ref->setValue($object, $connection); |
||
| 31 | |||
| 32 | return $invocation->proceed(); |
||
| 33 | } |
||
| 34 | } |
||
| 35 |