Passed
Push — master ( 706de3...ffa1cb )
by Romain
03:56
created

EventDefinition::dataPreProcessor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (C) 2018
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\Core\Definition\Tree\EventGroup\Event;
18
19
use CuyZ\Notiz\Core\Definition\Tree\AbstractDefinitionComponent;
20
use CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\Configuration\EventConfiguration;
21
use CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\Connection\Connection;
22
use CuyZ\Notiz\Core\Definition\Tree\EventGroup\EventGroup;
23
use CuyZ\Notiz\Core\Notification\Notification;
24
use CuyZ\Notiz\Core\Property\Factory\PropertyDefinition;
25
use CuyZ\Notiz\Core\Property\Factory\PropertyFactory;
26
use CuyZ\Notiz\Service\LocalizationService;
27
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessor;
28
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessorInterface;
29
use Romm\ConfigurationObject\Service\Items\Parents\ParentsTrait;
30
31
class EventDefinition extends AbstractDefinitionComponent implements DataPreProcessorInterface
32
{
33
    use ParentsTrait;
34
35
    /**
36
     * @var string
37
     *
38
     * @validate NotEmpty
39
     */
40
    protected $identifier;
41
42
    /**
43
     * @var string
44
     */
45
    protected $label;
46
47
    /**
48
     * @var string
49
     */
50
    protected $description;
51
52
    /**
53
     * @var string
54
     *
55
     * @validate Romm.ConfigurationObject:ClassImplements(interface=CuyZ\Notiz\Core\Event\Event)
56
     */
57
    protected $className;
58
59
    /**
60
     * @var \CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\Configuration\EventConfiguration
61
     */
62
    protected $configuration;
63
64
    /**
65
     * @var \CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\Connection\Connection
66
     *
67
     * @validate NotEmpty
68
     *
69
     * @mixedTypesResolver \CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\Connection\ConnectionResolver
70
     */
71
    protected $connection;
72
73
    /**
74
     * @param string $identifier
75
     * @param string $className
76
     */
77
    public function __construct($identifier, $className)
78
    {
79
        $this->identifier = $identifier;
80
        $this->className = $className;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getIdentifier()
87
    {
88
        return $this->identifier;
89
    }
90
91
    /**
92
     * Returns a full version of the identifier, containing both the event group
93
     * identifier and the event identifier, separated by a dot.
94
     *
95
     * @return string
96
     */
97
    public function getFullIdentifier()
98
    {
99
        return $this->getGroup()->getIdentifier() . '.' . $this->identifier;
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function getLabel()
106
    {
107
        return LocalizationService::localize($this->label);
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getDescription()
114
    {
115
        return LocalizationService::localize($this->description);
116
    }
117
118
    /**
119
     * @return string
120
     */
121
    public function getClassName()
122
    {
123
        return $this->className;
124
    }
125
126
    /**
127
     * @return EventConfiguration
128
     */
129
    public function getConfiguration()
130
    {
131
        return $this->configuration;
132
    }
133
134
    /**
135
     * @return Connection
136
     */
137
    public function getConnection()
138
    {
139
        return $this->connection;
140
    }
141
142
    /**
143
     * @return EventGroup
144
     */
145
    public function getGroup()
146
    {
147
        /** @var EventGroup $eventGroup */
148
        $eventGroup = $this->getFirstParent(EventGroup::class);
149
150
        return $eventGroup;
151
    }
152
153
    /**
154
     * @param string $propertyClassName
155
     * @param Notification $notification
156
     * @return PropertyDefinition
157
     */
158
    public function getPropertyDefinition($propertyClassName, Notification $notification)
159
    {
160
        return PropertyFactory::get()->getPropertyDefinition($propertyClassName, $this, $notification);
161
    }
162
163
    /**
164
     * @param DataPreProcessor $processor
165
     */
166
    public static function dataPreProcessor(DataPreProcessor $processor)
167
    {
168
        $data = $processor->getData();
169
170
        // Configuration must always be set.
171
        if (!is_array($data['configuration'])) {
172
            $data['configuration'] = [];
173
        }
174
175
        $processor->setData($data);
176
    }
177
}
178