Passed
Pull Request — master (#77)
by Romain
03:38
created

EventDefinition::getPropertiesDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
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
     * @validate Romm.ConfigurationObject:ClassImplements(interface=CuyZ\Notiz\Core\Event\Event)
51
     */
52
    protected $className;
53
54
    /**
55
     * @var \CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\Configuration\EventConfiguration
56
     */
57
    protected $configuration;
58
59
    /**
60
     * @var \CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\Connection\Connection
61
     *
62
     * @validate NotEmpty
63
     *
64
     * @mixedTypesResolver \CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\Connection\ConnectionResolver
65
     */
66
    protected $connection;
67
68
    /**
69
     * @param string $identifier
70
     * @param string $className
71
     */
72
    public function __construct($identifier, $className)
73
    {
74
        $this->identifier = $identifier;
75
        $this->className = $className;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getIdentifier()
82
    {
83
        return $this->identifier;
84
    }
85
86
    /**
87
     * Returns a full version of the identifier, containing both the event group
88
     * identifier and the event identifier, separated by a dot.
89
     *
90
     * @return string
91
     */
92
    public function getFullIdentifier()
93
    {
94
        return $this->getGroup()->getIdentifier() . '.' . $this->identifier;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getLabel()
101
    {
102
        return LocalizationService::localize($this->label);
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function getClassName()
109
    {
110
        return $this->className;
111
    }
112
113
    /**
114
     * @return EventConfiguration
115
     */
116
    public function getConfiguration()
117
    {
118
        return $this->configuration;
119
    }
120
121
    /**
122
     * @return Connection
123
     */
124
    public function getConnection()
125
    {
126
        return $this->connection;
127
    }
128
129
    /**
130
     * @return EventGroup
131
     */
132
    public function getGroup()
133
    {
134
        /** @var EventGroup $eventGroup */
135
        $eventGroup = $this->getFirstParent(EventGroup::class);
136
137
        return $eventGroup;
138
    }
139
140
    /**
141
     * @param string $propertyClassName
142
     * @param Notification $notification
143
     * @return PropertyDefinition
144
     */
145
    public function getPropertyDefinition($propertyClassName, Notification $notification)
146
    {
147
        return PropertyFactory::get()->getPropertyDefinition($propertyClassName, $this, $notification);
148
    }
149
150
    /**
151
     * @param DataPreProcessor $processor
152
     */
153
    public static function dataPreProcessor(DataPreProcessor $processor)
154
    {
155
        $data = $processor->getData();
156
157
        // Configuration must always be set.
158
        if (!is_array($data['configuration'])) {
159
            $data['configuration'] = [];
160
        }
161
162
        $processor->setData($data);
163
    }
164
}
165