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\Domain\Model\DataObject; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Exceptions\EntryNotFoundException; |
17
|
|
|
use TYPO3\CMS\Core\Type\TypeInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Store and retrieve arbitrary data using the setter/getter functions. |
21
|
|
|
*/ |
22
|
|
|
class FormMetadataObject implements TypeInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $data = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $key |
31
|
|
|
* @return mixed |
32
|
|
|
* @throws EntryNotFoundException |
33
|
|
|
*/ |
34
|
|
|
public function get($key) |
35
|
|
|
{ |
36
|
|
|
if (false === $this->has($key)) { |
37
|
|
|
throw EntryNotFoundException::metadataNotFound($key); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $this->data[$key]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $key |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
|
|
public function has($key) |
48
|
|
|
{ |
49
|
|
|
return isset($this->data[$key]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $key |
54
|
|
|
* @param mixed $value |
55
|
|
|
*/ |
56
|
|
|
public function set($key, $value) |
57
|
|
|
{ |
58
|
|
|
$this->data[$key] = $value; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $key |
63
|
|
|
*/ |
64
|
|
|
public function remove($key) |
65
|
|
|
{ |
66
|
|
|
if (isset($this->data[$key])) { |
67
|
|
|
unset($this->data[$key]); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function getData() |
75
|
|
|
{ |
76
|
|
|
return $this->data; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function __toString() |
83
|
|
|
{ |
84
|
|
|
return serialize($this); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|