Passed
Push — 1.x ( 9a36fe...980d56 )
by Akihito
02:01 queued 14s
created

AuraSqlEnvModule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule;
6
7
use Ray\AuraSqlModule\Annotation\EnvAuth;
8
use Ray\Di\AbstractModule;
9
10
class AuraSqlEnvModule extends AbstractModule
11
{
12
    private string $dsn;
13
    private string $user;
14
    private string $password;
15
    private string $slave;
16
17
    /** @var array<mixed> */
18
    private array $options;
19
20
    /**
21
     * @param string       $dsn      Data Source Name (DSN)
22
     * @param string       $user     User name for the DSN string
23
     * @param string       $password Password for the DSN string
24
     * @param string       $slave    Comma separated slave host list
25
     * @param array<mixed> $options  A key=>value array of driver-specific connection options
26
     */
27
    public function __construct(string $dsn, string $user = '', string $password = '', string $slave = '', array $options = [])
28
    {
29
        $this->dsn = $dsn;
30
        $this->user = $user;
31
        $this->password = $password;
32
        $this->slave = $slave;
33
        $this->options = $options;
34
        parent::__construct();
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function configure(): void
41
    {
42
        $this->bind()->annotatedWith(EnvAuth::class)->toInstance(
43
            [
44
                'dsn' => $this->dsn,
45
                'user' => $this->user,
46
                'password' => $this->password,
47
            ]
48
        );
49
        $this->bind()->annotatedWith('pdo_dsn')->toProvider(EnvAuthProvider::class, 'dsn');
50
        $this->bind()->annotatedWith('pdo_user')->toProvider(EnvAuthProvider::class, 'user');
51
        $this->bind()->annotatedWith('pdo_pass')->toProvider(EnvAuthProvider::class, 'password');
52
        $this->install(new AuraSqlModule('', '', '', $this->slave, $this->options));
53
    }
54
}
55