AuraSqlMasterDbInterceptor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule;
6
7
use Aura\Sql\ConnectionLocatorInterface;
8
use Ray\Aop\MethodInterceptor;
9
use Ray\Aop\MethodInvocation;
10
use ReflectionProperty;
11
12
class AuraSqlMasterDbInterceptor implements MethodInterceptor
13
{
14
    public const PROP = 'pdo';
15
16
    private ConnectionLocatorInterface $connectionLocator;
17
18
    public function __construct(ConnectionLocatorInterface $connectionLocator)
19
    {
20
        $this->connectionLocator = $connectionLocator;
21
    }
22
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function invoke(MethodInvocation $invocation)
27
    {
28
        $object = $invocation->getThis();
29
        $ref = new ReflectionProperty($object, self::PROP);
30
        $ref->setAccessible(true);
31
        $connection = $this->connectionLocator->getWrite();
32
        $ref->setValue($object, $connection);
33
34
        return $invocation->proceed();
35
    }
36
}
37