Completed
Push — 3.x ( 6b78b0...2579fc )
by Grégoire
04:21
created

SessionFilterPersister   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 51
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 4 1
A set() 0 4 1
A reset() 0 4 1
A buildStorageKey() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\AdminBundle\Filter\Persister;
13
14
use Symfony\Component\HttpFoundation\Session\SessionInterface;
15
16
/**
17
 * This filter persister is storing filters in session.
18
 * This is the default behavior.
19
 *
20
 * @author Yann Eugoné <[email protected]>
21
 */
22
final class SessionFilterPersister implements FilterPersisterInterface
23
{
24
    /**
25
     * @var SessionInterface
26
     */
27
    private $session;
28
29
    /**
30
     * @param SessionInterface $session
31
     */
32
    public function __construct(SessionInterface $session)
33
    {
34
        $this->session = $session;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function get($adminCode)
41
    {
42
        return $this->session->get($this->buildStorageKey($adminCode), []);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function set($adminCode, array $filters)
49
    {
50
        $this->session->set($this->buildStorageKey($adminCode), $filters);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function reset($adminCode)
57
    {
58
        $this->session->remove($this->buildStorageKey($adminCode));
59
    }
60
61
    /**
62
     * Build the session key, under which the filter should be stored for given admin code.
63
     *
64
     * @param string $adminCode The admin code
65
     *
66
     * @return string The storage key
67
     */
68
    private function buildStorageKey($adminCode)
69
    {
70
        return $adminCode.'.filter.parameters';
71
    }
72
}
73