1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace carono\exchange1c\components; |
4
|
|
|
|
5
|
|
|
use carono\exchange1c\models\Article; |
6
|
|
|
use yii\base\Action; |
7
|
|
|
use yii\helpers\ArrayHelper; |
8
|
|
|
use yii\helpers\Html; |
9
|
|
|
use yii\helpers\Inflector; |
10
|
|
|
use yii\helpers\Url; |
11
|
|
|
|
12
|
|
|
class Breadcrumbs |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param Action $action |
16
|
|
|
* @param $params |
17
|
|
|
*/ |
18
|
|
|
public static function formCrumbs($action, $params) |
19
|
|
|
{ |
20
|
|
|
$name = 'crumb' . Inflector::camelize($action->controller->id . '-' . $action->id); |
21
|
|
|
$class = get_called_class(); |
22
|
|
|
if (method_exists($class, $name)) { |
23
|
|
|
$reflectionMethod = new \ReflectionMethod($class, $name); |
24
|
|
|
$data = []; |
25
|
|
|
foreach ($reflectionMethod->getParameters() as $p) { |
26
|
|
|
$data[] = isset($params[$p->getName()]) ? $params[$p->getName()] : null; |
27
|
|
|
} |
28
|
|
|
$action->controller->getView()->params['breadcrumbs'] = call_user_func_array([$class, "$name"], $data); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$name = 'button' . Inflector::camelize($action->controller->id . '-' . $action->id); |
32
|
|
|
$class = get_called_class(); |
33
|
|
|
if (method_exists($class, $name)) { |
34
|
|
|
$reflectionMethod = new \ReflectionMethod($class, $name); |
35
|
|
|
$data = []; |
36
|
|
|
foreach ($reflectionMethod->getParameters() as $p) { |
37
|
|
|
$data[] = isset($params[$p->getName()]) ? $params[$p->getName()] : null; |
38
|
|
|
} |
39
|
|
|
foreach ($buttons = call_user_func_array([$class, "$name"], $data) as &$button) { |
|
|
|
|
40
|
|
|
Html::addCssClass($button['options'], 'btn-xs'); |
41
|
|
|
$button['options']['href'] = Url::to(ArrayHelper::remove($button, 'url')); |
42
|
|
|
$button['options']['tag'] = 'a'; |
43
|
|
|
} |
44
|
|
|
$action->controller->getView()->params['buttons'] = $buttons; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public static function buttonArticleIndex() |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
|
|
[ |
52
|
|
|
'label' => 'Добавить статью', |
53
|
|
|
'url' => ['article/create'], |
54
|
|
|
'options' => ['class' => 'btn btn-primary', 'tag' => 'a'] |
55
|
|
|
] |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param Article $article |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public static function buttonArticleView($article) |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
|
|
[ |
67
|
|
|
'label' => 'Редактировать', |
68
|
|
|
'url' => ['article/update', 'id' => $article->id], |
69
|
|
|
'options' => ['class' => 'btn btn-primary'] |
70
|
|
|
], |
71
|
|
|
[ |
72
|
|
|
'label' => 'Добавить подстатью', |
73
|
|
|
'url' => ['article/create', 'parent' => $article->id], |
74
|
|
|
'options' => ['class' => 'btn btn-primary'] |
75
|
|
|
], |
76
|
|
|
[ |
77
|
|
|
'label' => 'Удалить', |
78
|
|
|
'url' => ['article/delete', 'id' => $article->id], |
79
|
|
|
'options' => ['class' => 'btn btn-danger', 'data-confirm' => 'Удалить статью?'] |
80
|
|
|
] |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
############################################################################# |
85
|
|
|
|
86
|
|
|
public static function crumbTestingIndex() |
87
|
|
|
{ |
88
|
|
|
return [ |
89
|
|
|
'Тестирование модуля', |
90
|
|
|
]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param Article $article |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
public static function crumbArticleView($article) |
98
|
|
|
{ |
99
|
|
|
$items = [ |
100
|
|
|
['label' => 'Старт', 'url' => ['article/index']] |
101
|
|
|
]; |
102
|
|
|
$parent = $article; |
103
|
|
|
while ($parent = $parent->parent) { |
104
|
|
|
$items[] = ['label' => $parent->name, 'url' => ['article/view', 'id' => $parent->id]]; |
105
|
|
|
} |
106
|
|
|
$items[] = $article->name; |
107
|
|
|
return $items; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public static function crumbArticleUpdate($article) |
111
|
|
|
{ |
112
|
|
|
$items = [ |
113
|
|
|
['label' => 'Старт', 'url' => ['article/index']] |
114
|
|
|
]; |
115
|
|
|
$parent = $article; |
116
|
|
|
while ($parent = $parent->parent) { |
117
|
|
|
$items[] = ['label' => $parent->name, 'url' => ['article/view', 'id' => $parent->id]]; |
118
|
|
|
} |
119
|
|
|
$items[] = ['label' => $article->name, 'url' => ['article/view', 'id' => $article->id]]; |
120
|
|
|
$items [] = 'Редактирование'; |
121
|
|
|
return $items; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
public static function crumbInterfaceCheck($variable, $class, $interfaceTest) |
126
|
|
|
{ |
127
|
|
|
return [ |
128
|
|
|
['label' => 'Интерфейсы', 'url' => ['default/interfaces']], |
129
|
|
|
$class, |
130
|
|
|
]; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public static function crumbDefaultInterfaces() |
134
|
|
|
{ |
135
|
|
|
return [ |
136
|
|
|
'Интерфейсы', |
137
|
|
|
]; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public static function crumbDefaultFiles() |
141
|
|
|
{ |
142
|
|
|
return [ |
143
|
|
|
'Временные файлы', |
144
|
|
|
]; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public static function crumbDefaultSettings() |
148
|
|
|
{ |
149
|
|
|
return [ |
150
|
|
|
'Настройки модуля', |
151
|
|
|
]; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public static function crumbDefaultDocumentation() |
155
|
|
|
{ |
156
|
|
|
return [ |
157
|
|
|
'Документация по CommerceML', |
158
|
|
|
]; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public static function crumbDefaultExport() |
162
|
|
|
{ |
163
|
|
|
return [ |
164
|
|
|
'Экспорт', |
165
|
|
|
]; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
public static function crumbDefaultImport() |
170
|
|
|
{ |
171
|
|
|
return [ |
172
|
|
|
'Импорт', |
173
|
|
|
]; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public static function crumbArticleIndex() |
177
|
|
|
{ |
178
|
|
|
return [ |
179
|
|
|
'Старт', |
180
|
|
|
]; |
181
|
|
|
} |
182
|
|
|
} |
Let?s assume that you have the following
foreach
statement:$itemValue
is assigned by reference. This is possible because the expression (in the example$array
) can be used as a reference target.However, if we were to replace
$array
with something different like the result of a function call as inthen assigning by reference is not possible anymore as there is no target that could be modified.
Available Fixes
1. Do not assign by reference
2. Assign to a local variable first
3. Return a reference