|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2025 |
|
6
|
|
|
* @package Base |
|
7
|
|
|
* @subpackage View |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Base\View\Helper\Csrf; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* View helper class for retrieving CSRF tokens. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Base |
|
18
|
|
|
* @subpackage View |
|
19
|
|
|
*/ |
|
20
|
|
|
class Standard |
|
21
|
|
|
extends \Aimeos\Base\View\Helper\Base |
|
22
|
|
|
implements \Aimeos\Base\View\Helper\Csrf\Iface |
|
23
|
|
|
{ |
|
24
|
|
|
private string $name; |
|
25
|
|
|
private ?string $value; |
|
26
|
|
|
private string $formfield = ''; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Initializes the URL view helper. |
|
31
|
|
|
* |
|
32
|
|
|
* @param \Aimeos\Base\View\Iface $view View instance with registered view helpers |
|
33
|
|
|
* @param string $name CSRF token name |
|
34
|
|
|
* @param string|null $value CSRF token value |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct( \Aimeos\Base\View\Iface $view, string $name = '', ?string $value = null ) |
|
37
|
|
|
{ |
|
38
|
|
|
parent::__construct( $view ); |
|
39
|
|
|
|
|
40
|
|
|
$this->name = $name; |
|
41
|
|
|
$this->value = $value; |
|
42
|
|
|
|
|
43
|
|
|
if( $value ) { |
|
44
|
|
|
$this->formfield = '<input class="csrf-token" type="hidden" name="' . $this->name . '" value="' . $this->value . '">'; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns the CSRF partial object. |
|
51
|
|
|
* |
|
52
|
|
|
* @return \Aimeos\Base\View\Helper\Csrf\Iface CSRF partial object |
|
53
|
|
|
*/ |
|
54
|
|
|
public function transform() : Iface |
|
55
|
|
|
{ |
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns the CSRF token name. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string CSRF token name |
|
64
|
|
|
*/ |
|
65
|
|
|
public function name() : string |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->name; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Returns the CSRF token value. |
|
73
|
|
|
* |
|
74
|
|
|
* @return string|null CSRF token value |
|
75
|
|
|
*/ |
|
76
|
|
|
public function value() : ?string |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->value; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Returns the HTML form field for the CSRF token. |
|
84
|
|
|
* |
|
85
|
|
|
* @return string HTML form field code |
|
86
|
|
|
*/ |
|
87
|
|
|
public function formfield() : string |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->formfield; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|