1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (C) 2017 |
5
|
|
|
* Nathan Boiron <[email protected]> |
6
|
|
|
* Romain Canon <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This file is part of the TYPO3 NotiZ project. |
9
|
|
|
* It is free software; you can redistribute it and/or modify it |
10
|
|
|
* under the terms of the GNU General Public License, either |
11
|
|
|
* version 3 of the License, or any later version. |
12
|
|
|
* |
13
|
|
|
* For the full copyright and license information, see: |
14
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace CuyZ\Notiz\Definition\Tree\EventGroup\Event; |
18
|
|
|
|
19
|
|
|
use CuyZ\Notiz\Definition\Tree\AbstractDefinitionComponent; |
20
|
|
|
use CuyZ\Notiz\Definition\Tree\EventGroup\Event\Configuration\EventConfiguration; |
21
|
|
|
use CuyZ\Notiz\Definition\Tree\EventGroup\Event\Connection\Connection; |
22
|
|
|
use CuyZ\Notiz\Definition\Tree\EventGroup\EventGroup; |
23
|
|
|
use CuyZ\Notiz\Property\Factory\PropertyFactory; |
24
|
|
|
use CuyZ\Notiz\Property\PropertyEntry; |
25
|
|
|
use CuyZ\Notiz\Service\LocalizationService; |
26
|
|
|
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessor; |
27
|
|
|
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessorInterface; |
28
|
|
|
use Romm\ConfigurationObject\Service\Items\Parents\ParentsTrait; |
29
|
|
|
|
30
|
|
|
class EventDefinition extends AbstractDefinitionComponent implements DataPreProcessorInterface |
31
|
|
|
{ |
32
|
|
|
use ParentsTrait; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
* |
37
|
|
|
* @validate NotEmpty |
38
|
|
|
*/ |
39
|
|
|
protected $identifier; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $label; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
* |
49
|
|
|
* @validate Romm.ConfigurationObject:ClassImplements(interface=CuyZ\Notiz\Event\Event) |
50
|
|
|
*/ |
51
|
|
|
protected $className; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var \CuyZ\Notiz\Definition\Tree\EventGroup\Event\Configuration\EventConfiguration |
55
|
|
|
*/ |
56
|
|
|
protected $configuration; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var \CuyZ\Notiz\Definition\Tree\EventGroup\Event\Connection\Connection |
60
|
|
|
* |
61
|
|
|
* @validate NotEmpty |
62
|
|
|
* |
63
|
|
|
* @mixedTypesResolver \CuyZ\Notiz\Definition\Tree\EventGroup\Event\Connection\ConnectionResolver |
64
|
|
|
*/ |
65
|
|
|
protected $connection; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $identifier |
69
|
|
|
* @param string $className |
70
|
|
|
*/ |
71
|
|
|
public function __construct($identifier, $className) |
72
|
|
|
{ |
73
|
|
|
$this->identifier = $identifier; |
74
|
|
|
$this->className = $className; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function getIdentifier() |
81
|
|
|
{ |
82
|
|
|
return $this->identifier; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns a full version of the identifier, containing both the event group |
87
|
|
|
* identifier and the event identifier, separated by a dot. |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getFullIdentifier() |
92
|
|
|
{ |
93
|
|
|
return $this->getGroup()->getIdentifier() . '.' . $this->identifier; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getLabel() |
100
|
|
|
{ |
101
|
|
|
return LocalizationService::localize($this->label); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
|
|
public function getClassName() |
108
|
|
|
{ |
109
|
|
|
return $this->className; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return EventConfiguration |
114
|
|
|
*/ |
115
|
|
|
public function getConfiguration() |
116
|
|
|
{ |
117
|
|
|
return $this->configuration; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return Connection |
122
|
|
|
*/ |
123
|
|
|
public function getConnection() |
124
|
|
|
{ |
125
|
|
|
return $this->connection; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return EventGroup |
130
|
|
|
*/ |
131
|
|
|
public function getGroup() |
132
|
|
|
{ |
133
|
|
|
/** @var EventGroup $eventGroup */ |
134
|
|
|
$eventGroup = $this->getFirstParent(EventGroup::class); |
135
|
|
|
|
136
|
|
|
return $eventGroup; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param string $propertyClassName |
141
|
|
|
* @return PropertyEntry[] |
142
|
|
|
*/ |
143
|
|
|
public function getPropertiesDefinition($propertyClassName) |
144
|
|
|
{ |
145
|
|
|
return PropertyFactory::get()->getPropertiesDefinition($propertyClassName, $this); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param DataPreProcessor $processor |
150
|
|
|
*/ |
151
|
|
|
public static function dataPreProcessor(DataPreProcessor $processor) |
152
|
|
|
{ |
153
|
|
|
$data = $processor->getData(); |
154
|
|
|
|
155
|
|
|
// Configuration must always be set. |
156
|
|
|
if (!is_array($data['configuration'])) { |
157
|
|
|
$data['configuration'] = []; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
$processor->setData($data); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|