Completed
Push — master ( 83a9fe...bdaaf9 )
by Tobias
07:57
created

Activator::activate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[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 Translation\Bundle\EditInPlace;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Session\Session;
16
17
/**
18
 * Default Activator implementation.
19
 *
20
 * @author Damien Alexandre <[email protected]>
21
 */
22
class Activator implements ActivatorInterface
23
{
24
    const KEY = 'translation_bundle.edit_in_place.enabled';
25
26
    /**
27
     * @var Session
28
     */
29
    private $session;
30
31
    public function __construct(Session $session)
32
    {
33
        $this->session = $session;
34
    }
35
36
    /**
37
     * Enable the Edit In Place mode.
38
     */
39
    public function activate()
40
    {
41
        $this->session->set(self::KEY, true);
42
    }
43
44
    /**
45
     * Disable the Edit In Place mode.
46
     */
47
    public function deactivate()
48
    {
49
        $this->session->remove(self::KEY);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     *
55
     * @todo Cache this call result for performance?
56
     */
57
    public function checkRequest(Request $request = null)
58
    {
59
        if (!$this->session->has(self::KEY)) {
60
            return false;
61
        }
62
63
        return $this->session->has(self::KEY);
64
    }
65
}
66