AuraSqlMasterModule::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule;
6
7
use Aura\Sql\ExtendedPdo;
8
use Aura\Sql\ExtendedPdoInterface;
9
use Ray\Di\AbstractModule;
10
use Ray\Di\Scope;
11
12
class AuraSqlMasterModule extends AbstractModule
13
{
14
    private string $dsn;
15
    private string $user;
16
    private string $password;
17
18
    /** @var array<string> */
19
    private array $options;
20
21
    /** @var array<string> */
22
    private array $attributes;
23
24
    /**
25
     * @phpstan-param array<string> $options
26
     * @phpstan-param array<string> $attributes
27
     */
28
    public function __construct(
29
        string $dsnKey,
30
        string $user = '',
31
        string $passwordKey = '',
32
        array $options = [],
33
        array $attributes = [],
34
        ?AbstractModule $module = null
35
    ) {
36
        $this->dsn = $dsnKey;
37
        $this->user = $user;
38
        $this->password = $passwordKey;
39
        $this->options = $options;
40
        $this->attributes = $attributes;
41
        parent::__construct($module);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function configure(): void
48
    {
49
        $this->bind(ExtendedPdoInterface::class)->toConstructor(
50
            ExtendedPdo::class,
51
            'dsn=pdo_dsn,username=pdo_user,password=pdo_pass,options=pdo_option,attributes=pdo_attributes'
52
        )->in(Scope::SINGLETON);
53
        $this->bind()->annotatedWith('pdo_dsn')->toInstance($this->dsn);
54
        $this->bind()->annotatedWith('pdo_user')->toInstance($this->user);
55
        $this->bind()->annotatedWith('pdo_pass')->toInstance($this->password);
56
        $this->bind()->annotatedWith('pdo_option')->toInstance($this->options);
57
        $this->bind()->annotatedWith('pdo_attributes')->toInstance($this->attributes);
58
    }
59
}
60