phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
BaseGui.php
Go to the documentation of this file.
1 <?php
2 namespace Ajax\common;
3 
5 use Ajax\JsUtils;
7 
18 class BaseGui {
19 
20  protected $autoCompile;
21 
22  protected $components;
23 
24  protected $htmlComponents;
25 
30  protected $js;
31 
32  public function __construct($autoCompile = true) {
33  $this->autoCompile = $autoCompile;
34  $this->components = array();
35  $this->htmlComponents = array();
36  }
37 
38  public function isAutoCompile() {
39  return $this->autoCompile;
40  }
41 
42  public function setAutoCompile($autoCompile) {
43  $this->autoCompile = $autoCompile;
44  return $this;
45  }
46 
47  public function compile($internal = false) {
48  if ($internal === false && $this->autoCompile === true)
49  throw new \Exception("Impossible to compile if autoCompile is set to 'true'");
50  foreach ($this->components as $component) {
51  $component->compile();
52  }
53  }
54 
55  public function setJs(JsUtils $js) {
56  $this->js = $js;
57  }
58 
59  public function addComponent(SimpleComponent $component, $attachTo, $params) {
60  if ($this->autoCompile) {
61  if ($attachTo != null) {
62  if (! isset($this->components[$attachTo])) {
63  $this->components[$attachTo] = $component;
64  } else {
65  $this->components[] = $component;
66  }
67  $component->attach($attachTo);
68  } else {
69  $this->components[] = $component;
70  }
71  }
72  if (isset($params))
73  if (\is_array($params))
74  $component->setParams($params);
75  return $component;
76  }
77 
78  public function addHtmlComponent(BaseHtml $htmlComponent) {
79  $this->htmlComponents[$htmlComponent->getIdentifier()] = $htmlComponent;
80  return $htmlComponent;
81  }
82 
83  public function compileHtml(JsUtils $js = NULL, &$view = NULL) {
84  foreach ($this->htmlComponents as $htmlComponent) {
85  $htmlComponent->compile($js, $view);
86  }
87  }
88 
89  public function matchHtmlComponents($callback) {
90  return array_filter($this->htmlComponents, $callback);
91  }
92 
93  public function getHtmlComponent($identifier){
94  return $this->htmlComponents[$identifier]??'';
95  }
96  public function clearComponents(){
97  $this->components=[];
98  $this->htmlComponents=[];
99  }
100 }
BaseHtml for HTML components.
Definition: BaseHtml.php:17
addHtmlComponent(BaseHtml $htmlComponent)
Definition: BaseGui.php:78
setAutoCompile($autoCompile)
Definition: BaseGui.php:42
Base component for JQuery UI visuals components.
getHtmlComponent($identifier)
Definition: BaseGui.php:93
BaseGui Phalcon library.
Definition: BaseGui.php:18
setJs(JsUtils $js)
Definition: BaseGui.php:55
addComponent(SimpleComponent $component, $attachTo, $params)
Definition: BaseGui.php:59
JQuery PHP library.
Definition: JsUtils.php:23
compile($internal=false)
Definition: BaseGui.php:47
compileHtml(JsUtils $js=NULL, &$view=NULL)
Definition: BaseGui.php:83
__construct($autoCompile=true)
Definition: BaseGui.php:32
matchHtmlComponents($callback)
Definition: BaseGui.php:89