1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\common; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Ajax\common\components\SimpleComponent; |
7
|
|
|
use Ajax\JsUtils; |
8
|
|
|
use Ajax\common\html\BaseHtml; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* BaseGui Phalcon library |
12
|
|
|
* @author jcheron |
13
|
|
|
* @version 1.001 |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* BaseGui |
18
|
|
|
*/ |
19
|
|
|
class BaseGui { |
20
|
|
|
protected $autoCompile; |
21
|
|
|
protected $components; |
22
|
|
|
protected $htmlComponents; |
23
|
|
|
/** |
24
|
|
|
* |
25
|
|
|
* @var \Ajax\JsUtils |
26
|
|
|
*/ |
27
|
|
|
protected $js; |
28
|
|
|
|
29
|
|
|
public function __construct($autoCompile=true) { |
30
|
|
|
$this->autoCompile=$autoCompile; |
31
|
|
|
$this->components=array (); |
32
|
|
|
$this->htmlComponents=array (); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function isAutoCompile() { |
36
|
|
|
return $this->autoCompile; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function setAutoCompile($autoCompile) { |
40
|
|
|
$this->autoCompile=$autoCompile; |
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function compile($internal=false) { |
45
|
|
|
if ($internal===false&&$this->autoCompile===true) |
46
|
|
|
throw new \Exception("Impossible to compile if autoCompile is set to 'true'"); |
47
|
|
|
foreach ( $this->components as $component ) { |
48
|
|
|
$component->compile(); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function setJs(JsUtils $js) { |
53
|
|
|
$this->js=$js; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function addComponent(SimpleComponent $component, $attachTo, $params) { |
57
|
|
|
if ($this->autoCompile) |
58
|
|
|
$this->components []=$component; |
59
|
|
|
if (isset($attachTo)) |
60
|
|
|
$component->attach($attachTo); |
61
|
|
|
if (isset($params)) |
62
|
|
|
if (\is_array($params)) |
63
|
|
|
$component->setParams($params); |
64
|
|
|
return $component; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function addHtmlComponent(BaseHtml $htmlComponent) { |
68
|
|
|
$this->htmlComponents [$htmlComponent->getIdentifier()]=$htmlComponent; |
69
|
|
|
return $htmlComponent; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function compileHtml(JsUtils $js=NULL, &$view=NULL) { |
73
|
|
|
foreach ( $this->htmlComponents as $htmlComponent ) { |
74
|
|
|
$htmlComponent->compile($js, $view); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function matchHtmlComponents($callback){ |
79
|
|
|
return array_filter($this->htmlComponents,$callback); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|