phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
BaseComponent.php
Go to the documentation of this file.
1<?php
2
4
5
12abstract class BaseComponent {
13 public $jquery_code_for_compile=array ();
14 protected $params=array ();
15
20 protected $js;
21
22 public function __construct(JsUtils $js=NULL) {
23 $this->js=$js;
24 }
25
26 protected function getParamsAsJSON($params) {
27 $result="";
28 if (sizeof($params)>0) {
29 $result=json_encode($params, JSON_UNESCAPED_SLASHES);
30 $result=str_ireplace("%quote%", "\"", $result);
31 }
32 return $result;
33 }
34
35 public function setParam($key, $value) {
36 $this->params [$key]=$value;
37 return $this;
38 }
39
40 public function getParam($key) {
41 $value=null;
42 if (array_key_exists($key, $this->params))
43 $value=$this->params [$key];
44 return $value;
45 }
46
47 public function getParams() {
48 return $this->params;
49 }
50
51 public function compile(JsUtils $js=NULL) {
52 if ($js==NULL)
54 $script=$this->getScript();
55 $js->addToCompile($script);
56 }
57
58 protected function setParamCtrl($key, $value, $typeCtrl) {
59 if (\is_array($typeCtrl)) {
60 if (array_search($value, $typeCtrl)===false)
61 throw new \Exception("La valeur passée a propriété `".$key."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}");
62 } else {
63 if (!$typeCtrl($value)) {
64 throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$key);
65 }
66 }
67 $this->setParam($key, $value);
68 }
69
70 public function setParams($params) {
71 if(\is_array($params)) {
72 foreach ($params as $k => $v) {
73 $method = "set" . ucfirst($k);
74 if (method_exists($this, $method))
75 $this->$method($v);
76 else {
77 $this->setParam($k, $v);
78 trigger_error("`{$k}` doesn't exists!", E_USER_NOTICE);
79 }
80 }
81 }
82
83 return $this;
84 }
85
86 public function addParams($params){
87 foreach ($params as $k=>$v){
88 $this->setParam($k, $v);
89 }
90 return $this;
91 }
92
93 abstract public function getScript();
94
95 public function setDebug($value){
96 return $this->setParam("debug", $value);
97 }
98
99 public function setVerbose($value){
100 return $this->setParam("verbose", $value);
101 }
102
103}
JQuery PHP library.
Definition JsUtils.php:23
Base component for JQuery UI visuals components.
setParamCtrl($key, $value, $typeCtrl)