AbstractAction::getValidationFunction()   A
last analyzed

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 0
1
<?php
2
/**
3
 * @company MTE Telecom, Ltd.
4
 * @author Roman Malashin <[email protected]>
5
 */
6
7
namespace Nnx\DataGrid\Column\Action;
8
9
use Zend\View\Helper\Url;
10
11
/**
12
 * Class AbstractAction
13
 * @package Nnx\DataGrid\Column\Action
14
 */
15
abstract class AbstractAction implements ActionInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $name;
21
22
    /**
23
     * Заголовок действия
24
     * @var string
25
     */
26
    protected $title;
27
28
    /**
29
     * @var array
30
     */
31
    protected $attributes = [];
32
33
    /**
34
     * Роут для построения линки
35
     * @var array
36
     */
37
    protected $route;
38
39
    /**
40
     * UrlHelper для построения линки
41
     * @var Url
42
     */
43
    protected $urlHelper;
44
45
    /**
46
     * Опции для действия
47
     * @var array
48
     */
49
    protected $options;
50
51
    /**
52
     * Функция валидирующая необходимость отображения действия
53
     * @var callback | array
54
     */
55
    protected $validationFunction;
56
57
58
    /**
59
     * Конструктор класса
60
     * @param array $options
61
     * @throws Exception\NameNotDefinedException
62
     */
63
    public function __construct(array $options = [])
64
    {
65
        if (!array_key_exists('name', $options)) {
66
            throw new Exception\NameNotDefinedException(
67
                'Для корректной работы действий необходимо задать имя действия'
68
            );
69
        } else {
70
            $this->setName($options['name']);
71
        }
72
        if (array_key_exists('title', $options)) {
73
            $this->setTitle($options['title']);
74
        }
75
        if (array_key_exists('route', $options)) {
76
            $this->setRoute($options['route']);
77
        }
78
        if (array_key_exists('urlHelper', $options)) {
79
            $this->setUrlHelper($options['urlHelper']);
80
        }
81
    }
82
83
    /**
84
     * Возвращает заголовок действия
85
     * @return string
86
     */
87
    public function getTitle()
88
    {
89
        return $this->title;
90
    }
91
92
    /**
93
     * Устнаваливает заголовок действия
94
     * @param string $title
95
     * @return $this
96
     */
97
    public function setTitle($title)
98
    {
99
        $this->title = $title;
100
        return $this;
101
    }
102
103
    /**
104
     * Возвращает готовую ссылку на которую ведет действие
105
     * @return string
106
     */
107
    public function getUrl()
108
    {
109
        $urlHelper = $this->getUrlHelper();
110
        $route = $this->getRoute();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
111
        return $urlHelper($route['routeName'], $route['routeParams'], $route['routeOptions']);
112
    }
113
114
    /**
115
     * Возвращает роут для действия
116
     * @return array
117
     */
118
    public function getRoute()
119
    {
120
        return $this->route;
121
    }
122
123
    /**
124
     * Устанавливает route для действия
125
     * @param array $route
126
     * @return $this
127
     */
128
    public function setRoute($route)
129
    {
130
        $this->route = $route;
131
        return $this;
132
    }
133
134
    /**
135
     * Возвращает хелпер который преобразует route в url
136
     * @return Url
137
     */
138
    public function getUrlHelper()
139
    {
140
        return $this->urlHelper;
141
    }
142
143
    /**
144
     * Устанавливает хелпер который преобразует route в url
145
     * @param Url $urlHelper
146
     * @return $this
147
     */
148
    public function setUrlHelper($urlHelper)
149
    {
150
        $this->urlHelper = $urlHelper;
151
        return $this;
152
    }
153
154
    /**
155
     * Функция непосредственно валидирующая необходимость отображения действия
156
     * @return bool
157
     */
158
    abstract public function validate();
159
160
    /**
161
     * Возвращает имя действия
162
     * @return string
163
     */
164
    public function getName()
165
    {
166
        return $this->name;
167
    }
168
169
    /**
170
     * Устанавливает имя действия
171
     * @param string $name
172
     * @return $this
173
     */
174
    public function setName($name)
175
    {
176
        $this->name = $name;
177
        return $this;
178
    }
179
180
    /**
181
     * Возвращает набор опций для действия
182
     * @return array
183
     */
184
    public function getOptions()
185
    {
186
        return $this->options;
187
    }
188
189
    /**
190
     * Устнаваливает набор опций для действия
191
     * @param array $options
192
     * @return $this
193
     */
194
    public function setOptions($options)
195
    {
196
        $this->options = $options;
197
        return $this;
198
    }
199
200
    /**
201
     * Возвращает набор атрибутов действия
202
     * @return array
203
     */
204
    public function getAttributes()
205
    {
206
        return $this->attributes;
207
    }
208
209
    /**
210
     * Устанавливаем атрибуты для действия
211
     * @param array $attributes
212
     * @return $this
213
     */
214
    public function setAttributes(array $attributes)
215
    {
216
        $this->attributes = $attributes;
217
        return $this;
218
    }
219
220
    /**
221
     * Возвращает функцию которая сообщает отображать или не отображать действие.
222
     * @return array|callable
223
     */
224
    public function getValidationFunction()
225
    {
226
        return $this->validationFunction;
227
    }
228
229
    /**
230
     * Устнаваливает функцию которая сообщает отображать или не отображать действие.
231
     * @param array|callable $validationFunction
232
     * @return $this
233
     */
234
    public function setValidationFunction($validationFunction)
235
    {
236
        $this->validationFunction = $validationFunction;
237
        return $this;
238
    }
239
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
240