Completed
Pull Request — master (#38)
by Monse
03:05
created

PdoHandler::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Noxlogic\RateLimitBundle\Entity;
4
5
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
6
7
class PdoHandler extends PdoSessionHandler
8
{
9
10
    public function __construct(\PDO $pdo)
11
    {
12
13
        $table = $pdo->prepare('CREATE TABLE IF NOT EXISTS database_cache (
14
                      id VARCHAR(128) NOT NULL PRIMARY KEY,
15
                      limit INTEGER NOT NULL,
16
                      info VARCHAR(255) NOT NULL,
17
                      period INTEGER NOT NULL,
18
                      reset INTEGER NOT NULL
19
                    )');
20
21
        $pdo->exec($table);
22
23
        parent::__construct($pdo, [
24
            'db_table' => 'database_cache',
25
            'db_id_col' => 'id',
26
            'db_data_col' => 'info',
27
            'db_time_col' => 'period'
28
        ]);
29
    }
30
31
    public function fetch($key){
32
        $this->read($key);
33
    }
34
35
    public function save($key, $info){
36
        $this->write($key, $info);
37
    }
38
39
    public function delete($key){
40
        $this->destroy($key);
41
    }
42
}