1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\elements; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemCollection; |
6
|
|
|
use Ajax\service\JArray; |
7
|
|
|
use Ajax\JsUtils; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Semantic Icons group component |
11
|
|
|
* @see http://phpmv-ui.kobject.net/index/direct/main/72 |
12
|
|
|
* @see http://semantic-ui.com/elements/icon.html#/definition |
13
|
|
|
* @author jc |
14
|
|
|
* @version 1.001 |
15
|
|
|
*/ |
16
|
|
|
class HtmlIconGroups extends HtmlSemCollection { |
17
|
|
|
|
18
|
|
|
public function __construct($identifier, $icons=array(), $size="") { |
19
|
|
|
parent::__construct($identifier, "i", "icons"); |
20
|
|
|
$this->addItems($icons); |
21
|
|
|
$this->setSize($size); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
protected function createItem($value) { |
25
|
|
|
$icon=$value; |
26
|
|
|
if (\is_array($value)) { |
27
|
|
|
$icon=JArray::getValue($value, "icon", 0); |
28
|
|
|
$size=JArray::getValue($value, "size", 1); |
29
|
|
|
} |
30
|
|
|
$iconO=new HtmlIcon("icon-" . $this->identifier, $icon); |
31
|
|
|
if (isset($size)) { |
32
|
|
|
$iconO->setSize($size); |
33
|
|
|
} |
34
|
|
|
return $iconO; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function createCondition($value) { |
38
|
|
|
return ($value instanceof HtmlIcon) === false; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getIcon($index) { |
42
|
|
|
return $this->content[$index]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function run(JsUtils $js){ |
46
|
|
|
$result= parent::run($js); |
47
|
|
|
return $result->setItemSelector("i"); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function toCorner($index=1) { |
51
|
|
|
$this->getItem($index)->toCorner(); |
|
|
|
|
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public static function corner($mainIcon,$cornerIcon,$size="huge"){ |
56
|
|
|
$icons=new HtmlIconGroups("icons",[$mainIcon,$cornerIcon],$size); |
57
|
|
|
return $icons->toCorner(1); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
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: