1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\traits; |
4
|
|
|
use Ajax\common\components\GenericComponent; |
5
|
|
|
use Ajax\semantic\components\Popup; |
6
|
|
|
use Ajax\semantic\components\Dropdown; |
7
|
|
|
use Ajax\semantic\components\Accordion; |
8
|
|
|
use Ajax\common\components\SimpleComponent; |
9
|
|
|
use Ajax\semantic\components\Sticky; |
10
|
|
|
use Ajax\semantic\components\Checkbox; |
11
|
|
|
use Ajax\semantic\components\Rating; |
12
|
|
|
trait SemanticComponentsTrait { |
13
|
|
|
|
14
|
|
|
public abstract function addComponent(SimpleComponent $component, $attachTo, $params); |
15
|
|
|
/** |
16
|
|
|
* |
17
|
|
|
* @param string $attachTo |
18
|
|
|
* @param string|array $params |
19
|
|
|
* @return GenericComponent |
20
|
|
|
*/ |
21
|
|
|
public function generic($attachTo=NULL, $params=NULL) { |
22
|
|
|
return $this->addComponent(new GenericComponent($this->js), $attachTo, $params); |
|
|
|
|
23
|
|
|
} |
24
|
|
|
/** |
25
|
|
|
* |
26
|
|
|
* @param string $attachTo |
27
|
|
|
* @param string|array $params |
28
|
|
|
* @return Popup |
29
|
|
|
*/ |
30
|
|
|
public function popup($attachTo=NULL, $params=NULL) { |
31
|
|
|
return $this->addComponent(new Popup($this->js), $attachTo, $params); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $attachTo |
36
|
|
|
* @param string|array $params |
37
|
|
|
* @return Dropdown |
38
|
|
|
*/ |
39
|
|
|
public function dropdown($attachTo=NULL, $params=NULL) { |
40
|
|
|
return $this->addComponent(new Dropdown($this->js), $attachTo, $params); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $attachTo |
45
|
|
|
* @param string|array $params |
46
|
|
|
* @return Accordion |
47
|
|
|
*/ |
48
|
|
|
public function accordion($attachTo=NULL, $params=NULL) { |
49
|
|
|
return $this->addComponent(new Accordion($this->js), $attachTo, $params); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function sticky($attachTo=NULL, $params=NULL) { |
53
|
|
|
return $this->addComponent(new Sticky($this->js), $attachTo, $params); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function checkbox($attachTo=NULL, $params=NULL) { |
57
|
|
|
return $this->addComponent(new Checkbox($this->js), $attachTo, $params); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function rating($attachTo=NULL, $params=NULL) { |
61
|
|
|
return $this->addComponent(new Rating($this->js), $attachTo, $params); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: