Completed
Branch master (d39ff3)
by Pierre-Henry
32:32
created

Token::isEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
<?php
2
/**
3
 * This file has been made by pH7 (Pierre-Henry SORIA).
4
 */
5
6
namespace PFBC\Element;
7
8
use PFBC\Validation\Token as ValidationToken;
9
use PH7\Framework\Mvc\Model\DbConfig;
10
use PH7\Framework\Security\CSRF\Token as SecurityToken;
11
12
class Token extends Hidden
13
{
14
15
    private $sName;
16
17
    public function __construct($sName)
18
    {
19
        if (!$this->isEnabled())
20
            return; // If it's disabled, we stop the execution of the class
21
22
        $this->sName = $sName;
23
        parent::__construct('security_token', (new SecurityToken)->generate($this->sName));
24
    }
25
26
    public function render()
27
    {
28
        if (!$this->isEnabled())
29
            return; // If it's disabled, we stop the execution of the class
30
31
        $this->validation[] = new ValidationToken($this->sName);
32
        parent::render();
33
    }
34
35
    /**
36
     * Check if the CSRF security token for forms is enabled.
37
     *
38
     * @return boolean Returns TRUE if the security token is enabled, FALSE otherwise.
39
     */
40
    private function isEnabled()
41
    {
42
        // Check if the CSRF security token for forms is enabled
43
        return DbConfig::getSetting('securityToken');
44
    }
45
46
}
47