|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* HiPanel core package |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://hipanel.com/ |
|
6
|
|
|
* @package hipanel-core |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hipanel\widgets; |
|
12
|
|
|
|
|
13
|
|
|
use Yii; |
|
14
|
|
|
use yii\helpers\Html; |
|
15
|
|
|
|
|
16
|
|
|
class HiBox extends Box |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Buttons render. |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function initBoxTools() |
|
22
|
|
|
{ |
|
23
|
|
|
parent::initBoxTools(); |
|
|
|
|
|
|
24
|
|
View Code Duplication |
if (!isset($this->boxTools['collapse'])) { |
|
|
|
|
|
|
25
|
|
|
$this->boxTools['collapse'] = [ |
|
|
|
|
|
|
26
|
|
|
'icon' => 'fa-minus', |
|
27
|
|
|
'options' => [ |
|
28
|
|
|
'class' => 'btn-default', |
|
29
|
|
|
'title' => Yii::t('hipanel', 'collapse'), |
|
30
|
|
|
'data-widget' => 'collapse', |
|
31
|
|
|
], |
|
32
|
|
|
]; |
|
33
|
|
|
} |
|
34
|
|
View Code Duplication |
if (!isset($this->boxTools['remove'])) { |
|
|
|
|
|
|
35
|
|
|
$this->boxTools['remove'] = [ |
|
|
|
|
|
|
36
|
|
|
'icon' => 'fa-times', |
|
37
|
|
|
'options' => [ |
|
38
|
|
|
'class' => 'btn-default', |
|
39
|
|
|
'title' => Yii::t('hipanel', 'remove'), |
|
40
|
|
|
'data-widget' => 'remove', |
|
41
|
|
|
], |
|
42
|
|
|
]; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Render widget tools button. |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function renderButtons() |
|
50
|
|
|
{ |
|
51
|
|
|
// Box tools |
|
52
|
|
|
if ($this->buttonsTemplate !== null && !empty($this->boxTools)) { |
|
|
|
|
|
|
53
|
|
|
// Begin box tools |
|
54
|
|
|
echo Html::beginTag('div', ['class' => 'box-tools pull-right']); |
|
55
|
|
|
echo preg_replace_callback('/\\{([\w\-\/]+)\\}/', function ($matches) { |
|
56
|
|
|
$name = $matches[1]; |
|
57
|
|
|
if (isset($this->boxTools[$name])) { |
|
|
|
|
|
|
58
|
|
|
$label = isset($this->boxTools[$name]['label']) ? $this->boxTools[$name]['label'] : ''; |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$icon = isset($this->boxTools[$name]['icon']) ? Html::tag('i', '', ['class' => 'fa ' . $this->boxTools[$name]['icon']]) : ''; |
|
|
|
|
|
|
61
|
|
|
$label = $icon . ' ' . $label; |
|
62
|
|
|
$this->boxTools[$name]['options']['class'] = isset($this->boxTools[$name]['options']['class']) ? 'btn btn-sm ' . $this->boxTools[$name]['options']['class'] : 'btn btn-sm'; |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
return Html::button($label, $this->boxTools[$name]['options']); |
|
|
|
|
|
|
65
|
|
|
} else { |
|
66
|
|
|
return ''; |
|
67
|
|
|
} |
|
68
|
|
|
}, $this->buttonsTemplate); |
|
|
|
|
|
|
69
|
|
|
// End box tools |
|
70
|
|
|
echo Html::endTag('div'); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: