PdoSessionModule::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ray\SymfonySessionModule;
4
5
use Ray\Di\AbstractModule;
6
use Ray\Di\Scope;
7
use Ray\SymfonySessionModule\Annotation\SessionOptions;
8
use Ray\SymfonySessionModule\Annotation\SessionStorage;
9
use Symfony\Component\HttpFoundation\Session\SessionInterface;
10
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
11
12
class PdoSessionModule extends AbstractModule
13
{
14
    /**
15
     * @var \PDO
16
     */
17
    private $pdo;
18
19
    /**
20
     * @var array
21
     */
22
    private $options;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param \PDO  $pdo
28
     * @param array $options
29
     */
30 1
    public function __construct(\PDO $pdo, array $options = [])
31
    {
32 1
        $this->pdo = $pdo;
33 1
        $this->options = $options;
34 1
        parent::__construct();
35 1
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    protected function configure()
41
    {
42 1
        $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
43 1
        $this->bind()->annotatedWith(SessionStorage::class)->toInstance($this->pdo);
44 1
        $this->bind(\SessionHandlerInterface::class)->toConstructor(PdoSessionHandler::class, 'pdoOrDsn=' . SessionStorage::class);
45
46 1
        $this->bind()->annotatedWith(SessionOptions::class)->toInstance($this->options);
47
48 1
        $this->bind(SessionInterface::class)->toProvider(SessionProvider::class)->in(Scope::SINGLETON);
49 1
    }
50
}
51