Completed
Push — middleware-wip ( 55159c...844477 )
by Romain
02:34
created

FormObjectRequestData::setPluginName()   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 1
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Form;
15
16
use TYPO3\CMS\Extbase\Security\Cryptography\HashService;
17
18
class FormObjectRequestData
19
{
20
    /**
21
     * @var HashService
22
     */
23
    protected $hashService;
24
25
    /**
26
     * @var array
27
     */
28
    protected $data = [];
29
30
    /**
31
     * @var string
32
     */
33
    protected $contentObjectTable;
34
35
    /**
36
     * @var int
37
     */
38
    protected $contentObjectUid;
39
40
    /**
41
     * The given argument must be a string, hashed with the hash service, and
42
     * must contain an instance of this class. The data will be fetched from the
43
     * instance, and injected in the actual class.
44
     *
45
     * @param string $hash
46
     */
47
    public function fillFromHash($hash)
48
    {
49
        /** @var FormObjectRequestData $requestData */
50
        $requestData = $this->hashService->validateAndStripHmac($hash);
51
        $requestData = unserialize(base64_decode($requestData));
52
53
        foreach ($requestData as $key => $value) {
54
            $this->$key = $value;
55
        }
56
    }
57
58
    /**
59
     * @param string $key
60
     * @param mixed $value
61
     */
62
    public function addData($key, $value)
63
    {
64
        $this->data[$key] = $value;
65
    }
66
67
    /**
68
     * @return array
69
     */
70
    public function getData()
71
    {
72
        return $this->data;
73
    }
74
75
    /**
76
     * @param string $key
77
     * @return bool
78
     */
79
    public function hasData($key)
80
    {
81
        return true === isset($this->data[$key]);
82
    }
83
84
    /**
85
     * @param string $key
86
     * @return mixed
87
     */
88
    public function getDataValue($key)
89
    {
90
        if (false === $this->hasData($key)) {
91
            // @todo exception
92
        }
93
94
        return $this->data[$key];
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getContentObjectTable()
101
    {
102
        return $this->contentObjectTable;
103
    }
104
105
    /**
106
     * @param string $contentObjectTable
107
     */
108
    public function setContentObjectTable($contentObjectTable)
109
    {
110
        $this->contentObjectTable = $contentObjectTable;
111
    }
112
113
    /**
114
     * @return int
115
     */
116
    public function getContentObjectUid()
117
    {
118
        return (int)$this->contentObjectUid;
119
    }
120
121
    /**
122
     * @param int $contentObjectUid
123
     */
124
    public function setContentObjectUid($contentObjectUid)
125
    {
126
        $this->contentObjectUid = (int)$contentObjectUid;
127
    }
128
129
    /**
130
     * @param HashService $hashService
131
     */
132
    public function injectHashService(HashService $hashService)
133
    {
134
        $this->hashService = $hashService;
135
    }
136
137
    /**
138
     * @return array
139
     */
140
    public function toArray()
141
    {
142
        $result = [];
143
144
        $properties = get_object_vars($this);
145
        unset($properties['hashService']);
146
147
        foreach (array_keys($properties) as $propertyName) {
148
            $result[$propertyName] = $this->$propertyName;
149
        }
150
151
        return $result;
152
    }
153
}
154