@@ -55,6 +55,10 @@ discard block |
||
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | + /** |
|
59 | + * @param string $name |
|
60 | + * @param string[] $typeCtrl |
|
61 | + */ |
|
58 | 62 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
59 | 63 | if ($this->ctrl($name, $value, $typeCtrl) === true) { |
60 | 64 | return $name=$value; |
@@ -72,6 +76,10 @@ discard block |
||
72 | 76 | |
73 | 77 | |
74 | 78 | |
79 | + /** |
|
80 | + * @param string $name |
|
81 | + * @param string[] $typeCtrl |
|
82 | + */ |
|
75 | 83 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
76 | 84 | if ($this->ctrl($name, $value, $typeCtrl) === true) { |
77 | 85 | if (\is_array($typeCtrl)) { |
@@ -82,6 +90,9 @@ discard block |
||
82 | 90 | return $this; |
83 | 91 | } |
84 | 92 | |
93 | + /** |
|
94 | + * @param string $name |
|
95 | + */ |
|
85 | 96 | protected function addToMember(&$name, $value, $separator=" ") { |
86 | 97 | $name=str_ireplace($value, "", $name) . $separator . $value; |
87 | 98 | return $this; |
@@ -94,6 +105,9 @@ discard block |
||
94 | 105 | $oldValue=trim($oldValue); |
95 | 106 | } |
96 | 107 | |
108 | + /** |
|
109 | + * @param \Closure $callback |
|
110 | + */ |
|
97 | 111 | protected function _getElementBy($callback,$elements){ |
98 | 112 | if (\is_array($elements)) { |
99 | 113 | $flag=false; |
@@ -15,21 +15,21 @@ discard block |
||
15 | 15 | * @version 1.3 |
16 | 16 | */ |
17 | 17 | abstract class BaseHtml extends BaseWidget { |
18 | - use BaseHtmlEventsTrait,BaseHtmlPropertiesTrait; |
|
18 | + use BaseHtmlEventsTrait, BaseHtmlPropertiesTrait; |
|
19 | 19 | protected $_template; |
20 | 20 | protected $tagName; |
21 | - protected $_wrapBefore=array (); |
|
22 | - protected $_wrapAfter=array (); |
|
21 | + protected $_wrapBefore=array(); |
|
22 | + protected $_wrapAfter=array(); |
|
23 | 23 | protected $_bsComponent; |
24 | 24 | |
25 | - private function _callSetter($setter,$key,$value,&$array){ |
|
25 | + private function _callSetter($setter, $key, $value, &$array) { |
|
26 | 26 | $result=false; |
27 | 27 | if (method_exists($this, $setter) && !JString::startswith($key, "_")) { |
28 | 28 | try { |
29 | 29 | $this->$setter($value); |
30 | 30 | unset($array[$key]); |
31 | 31 | $result=true; |
32 | - } catch ( \Exception $e ) { |
|
32 | + }catch (\Exception $e) { |
|
33 | 33 | $result=false; |
34 | 34 | } |
35 | 35 | } |
@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | protected function getTemplate(JsUtils $js=NULL) { |
40 | - return PropertyWrapper::wrap($this->_wrapBefore, $js) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
40 | + return PropertyWrapper::wrap($this->_wrapBefore, $js).$this->_template.PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | protected function ctrl($name, $value, $typeCtrl) { |
44 | 44 | if (\is_array($typeCtrl)) { |
45 | - if (array_search($value, $typeCtrl) === false) { |
|
46 | - throw new \Exception("La valeur passée `" . $value . "` à la propriété `" . $name . "` ne fait pas partie des valeurs possibles : {" . implode(",", $typeCtrl) . "}"); |
|
45 | + if (array_search($value, $typeCtrl)===false) { |
|
46 | + throw new \Exception("La valeur passée `".$value."` à la propriété `".$name."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
47 | 47 | } |
48 | 48 | } else { |
49 | 49 | if (!$typeCtrl($value)) { |
50 | - throw new \Exception("La fonction " . $typeCtrl . " a retourné faux pour l'affectation de la propriété " . $name); |
|
50 | + throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$name); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | return true; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | |
58 | 58 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
59 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
59 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
60 | 60 | return $name=$value; |
61 | 61 | } |
62 | 62 | return $this; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") { |
66 | 66 | if (\is_array($typeCtrl)) { |
67 | 67 | $this->removeOldValues($name, $typeCtrl); |
68 | - $name.=$separator . $value; |
|
68 | + $name.=$separator.$value; |
|
69 | 69 | } |
70 | 70 | return $this; |
71 | 71 | } |
@@ -73,17 +73,17 @@ discard block |
||
73 | 73 | |
74 | 74 | |
75 | 75 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
76 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
76 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
77 | 77 | if (\is_array($typeCtrl)) { |
78 | 78 | $this->removeOldValues($name, $typeCtrl); |
79 | 79 | } |
80 | - $name.=$separator . $value; |
|
80 | + $name.=$separator.$value; |
|
81 | 81 | } |
82 | 82 | return $this; |
83 | 83 | } |
84 | 84 | |
85 | 85 | protected function addToMember(&$name, $value, $separator=" ") { |
86 | - $name=str_ireplace($value, "", $name) . $separator . $value; |
|
86 | + $name=str_ireplace($value, "", $name).$separator.$value; |
|
87 | 87 | return $this; |
88 | 88 | } |
89 | 89 | |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | $oldValue=trim($oldValue); |
95 | 95 | } |
96 | 96 | |
97 | - protected function _getElementBy($callback,$elements){ |
|
97 | + protected function _getElementBy($callback, $elements) { |
|
98 | 98 | if (\is_array($elements)) { |
99 | 99 | $flag=false; |
100 | 100 | $index=0; |
101 | - while ( !$flag && $index < sizeof($elements) ) { |
|
101 | + while (!$flag && $index<sizeof($elements)) { |
|
102 | 102 | if ($elements[$index] instanceof BaseHtml) |
103 | 103 | $flag=($callback($elements[$index])); |
104 | 104 | $index++; |
105 | 105 | } |
106 | - if ($flag === true) |
|
107 | - return $elements[$index - 1]; |
|
106 | + if ($flag===true) |
|
107 | + return $elements[$index-1]; |
|
108 | 108 | } elseif ($elements instanceof BaseHtml) { |
109 | 109 | if ($callback($elements)) |
110 | 110 | return $elements; |
@@ -139,13 +139,13 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | public function fromArray($array) { |
142 | - foreach ( $this as $key => $value ) { |
|
143 | - if(array_key_exists($key, $array)===true) |
|
144 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
142 | + foreach ($this as $key => $value) { |
|
143 | + if (array_key_exists($key, $array)===true) |
|
144 | + $this->_callSetter("set".ucfirst($key), $key, $array[$key], $array); |
|
145 | 145 | } |
146 | - foreach ( $array as $key => $value ) { |
|
147 | - if($this->_callSetter($key, $key, $value, $array)===false){ |
|
148 | - $this->_callSetter("set" . ucfirst($key), $key, $value, $array); |
|
146 | + foreach ($array as $key => $value) { |
|
147 | + if ($this->_callSetter($key, $key, $value, $array)===false) { |
|
148 | + $this->_callSetter("set".ucfirst($key), $key, $value, $array); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | return $array; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | public function fromDatabaseObjects($objects, $function) { |
155 | 155 | if (isset($objects)) { |
156 | - foreach ( $objects as $object ) { |
|
156 | + foreach ($objects as $object) { |
|
157 | 157 | $this->fromDatabaseObject($object, $function); |
158 | 158 | } |
159 | 159 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | |
175 | 175 | |
176 | 176 | public function getElementById($identifier, $elements) { |
177 | - return $this->_getElementBy(function($element) use ($identifier){return $element->getIdentifier()===$identifier;}, $elements); |
|
177 | + return $this->_getElementBy(function($element) use ($identifier){return $element->getIdentifier()===$identifier; }, $elements); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | public function getBsComponent() { |
@@ -188,19 +188,19 @@ discard block |
||
188 | 188 | |
189 | 189 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
190 | 190 | $result=$this->getTemplate($js); |
191 | - foreach ( $this as $key => $value ) { |
|
192 | - if (JString::startswith($key, "_") === false && $key !== "events") { |
|
191 | + foreach ($this as $key => $value) { |
|
192 | + if (JString::startswith($key, "_")===false && $key!=="events") { |
|
193 | 193 | if (\is_array($value)) { |
194 | 194 | $v=PropertyWrapper::wrap($value, $js); |
195 | 195 | } else { |
196 | 196 | $v=$value; |
197 | 197 | } |
198 | - $result=str_ireplace("%" . $key . "%", $v, $result); |
|
198 | + $result=str_ireplace("%".$key."%", $v, $result); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | if (isset($js)===true) { |
202 | 202 | $this->run($js); |
203 | - if (isset($view) === true) { |
|
203 | + if (isset($view)===true) { |
|
204 | 204 | $js->addViewElement($this->identifier, $result, $view); |
205 | 205 | } |
206 | 206 | } |
@@ -99,15 +99,18 @@ discard block |
||
99 | 99 | $flag=false; |
100 | 100 | $index=0; |
101 | 101 | while ( !$flag && $index < sizeof($elements) ) { |
102 | - if ($elements[$index] instanceof BaseHtml) |
|
103 | - $flag=($callback($elements[$index])); |
|
102 | + if ($elements[$index] instanceof BaseHtml) { |
|
103 | + $flag=($callback($elements[$index])); |
|
104 | + } |
|
104 | 105 | $index++; |
105 | 106 | } |
106 | - if ($flag === true) |
|
107 | - return $elements[$index - 1]; |
|
107 | + if ($flag === true) { |
|
108 | + return $elements[$index - 1]; |
|
109 | + } |
|
108 | 110 | } elseif ($elements instanceof BaseHtml) { |
109 | - if ($callback($elements)) |
|
110 | - return $elements; |
|
111 | + if ($callback($elements)) { |
|
112 | + return $elements; |
|
113 | + } |
|
111 | 114 | } |
112 | 115 | return null; |
113 | 116 | } |
@@ -140,8 +143,9 @@ discard block |
||
140 | 143 | |
141 | 144 | public function fromArray($array) { |
142 | 145 | foreach ( $this as $key => $value ) { |
143 | - if(array_key_exists($key, $array)===true) |
|
144 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
146 | + if(array_key_exists($key, $array)===true) { |
|
147 | + $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
148 | + } |
|
145 | 149 | } |
146 | 150 | foreach ( $array as $key => $value ) { |
147 | 151 | if($this->_callSetter($key, $key, $value, $array)===false){ |
@@ -17,186 +17,186 @@ discard block |
||
17 | 17 | |
18 | 18 | public static $index=0; |
19 | 19 | |
20 | - public function __construct($identifier,$instance=NULL,$captions=NULL){ |
|
20 | + public function __construct($identifier, $instance=NULL, $captions=NULL) { |
|
21 | 21 | $this->widgetIdentifier=$identifier; |
22 | 22 | $this->values=[]; |
23 | 23 | $this->afterCompile=[]; |
24 | - if(isset($instance)) |
|
24 | + if (isset($instance)) |
|
25 | 25 | $this->setInstance($instance); |
26 | 26 | $this->setCaptions($captions); |
27 | 27 | $this->captionCallback=NULL; |
28 | - $this->defaultValueFunction=function($name,$value){return $value;}; |
|
28 | + $this->defaultValueFunction=function($name, $value) {return $value; }; |
|
29 | 29 | } |
30 | 30 | |
31 | - public function getValues(){ |
|
31 | + public function getValues() { |
|
32 | 32 | $values=[]; |
33 | 33 | $index=0; |
34 | 34 | $count=$this->count(); |
35 | - while($index<$count){ |
|
35 | + while ($index<$count) { |
|
36 | 36 | $values[]=$this->getValue($index++); |
37 | 37 | } |
38 | 38 | return $values; |
39 | 39 | } |
40 | 40 | |
41 | - public function getIdentifier($index=NULL){ |
|
42 | - if(!isset($index)) |
|
41 | + public function getIdentifier($index=NULL) { |
|
42 | + if (!isset($index)) |
|
43 | 43 | $index=self::$index; |
44 | 44 | $value=$index; |
45 | - if(isset($this->values["identifier"])) |
|
46 | - $value=$this->values["identifier"]($index,$this->instance); |
|
45 | + if (isset($this->values["identifier"])) |
|
46 | + $value=$this->values["identifier"]($index, $this->instance); |
|
47 | 47 | return $value; |
48 | 48 | } |
49 | 49 | |
50 | - public function getValue($index){ |
|
50 | + public function getValue($index) { |
|
51 | 51 | $property=$this->properties[$index]; |
52 | 52 | return $this->_getValue($property, $index); |
53 | 53 | } |
54 | 54 | |
55 | - protected function _beforeAddProperty($index,&$field){ |
|
55 | + protected function _beforeAddProperty($index, &$field) { |
|
56 | 56 | |
57 | 57 | } |
58 | 58 | |
59 | - protected function _getDefaultValue($name,$value,$index){ |
|
59 | + protected function _getDefaultValue($name, $value, $index) { |
|
60 | 60 | $func=$this->defaultValueFunction; |
61 | - return $func($name,$value,$index,$this->instance); |
|
61 | + return $func($name, $value, $index, $this->instance); |
|
62 | 62 | } |
63 | 63 | |
64 | - protected function _getPropertyValue(\ReflectionProperty $property,$index){ |
|
64 | + protected function _getPropertyValue(\ReflectionProperty $property, $index) { |
|
65 | 65 | $property->setAccessible(true); |
66 | 66 | $value=$property->getValue($this->instance); |
67 | - if(isset($this->values[$index])){ |
|
68 | - $value= $this->values[$index]($value,$this->instance,$index); |
|
69 | - }else{ |
|
70 | - $value=$this->_getDefaultValue($property->getName(),$value, $index); |
|
67 | + if (isset($this->values[$index])) { |
|
68 | + $value=$this->values[$index]($value, $this->instance, $index); |
|
69 | + } else { |
|
70 | + $value=$this->_getDefaultValue($property->getName(), $value, $index); |
|
71 | 71 | } |
72 | 72 | return $value; |
73 | 73 | } |
74 | 74 | |
75 | - protected function _getValue($property,$index){ |
|
75 | + protected function _getValue($property, $index) { |
|
76 | 76 | $value=null; |
77 | - if($property instanceof \ReflectionProperty){ |
|
77 | + if ($property instanceof \ReflectionProperty) { |
|
78 | 78 | $value=$this->_getPropertyValue($property, $index); |
79 | - }else{ |
|
80 | - if(\is_callable($property)) |
|
79 | + } else { |
|
80 | + if (\is_callable($property)) |
|
81 | 81 | $value=$property($this->instance); |
82 | - elseif(\is_array($property)){ |
|
83 | - $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
|
82 | + elseif (\is_array($property)) { |
|
83 | + $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property); |
|
84 | 84 | $value=\implode("", $values); |
85 | - }else{ |
|
86 | - if(isset($this->values[$index])){ |
|
87 | - $value= $this->values[$index]($property,$this->instance,$index); |
|
88 | - }elseif(isset($this->instance->{$property})){ |
|
85 | + } else { |
|
86 | + if (isset($this->values[$index])) { |
|
87 | + $value=$this->values[$index]($property, $this->instance, $index); |
|
88 | + }elseif (isset($this->instance->{$property})) { |
|
89 | 89 | $value=$this->instance->{$property}; |
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | - if(isset($this->afterCompile[$index])){ |
|
94 | - if(\is_callable($this->afterCompile[$index])){ |
|
95 | - $this->afterCompile[$index]($value,$this->instance,$index); |
|
93 | + if (isset($this->afterCompile[$index])) { |
|
94 | + if (\is_callable($this->afterCompile[$index])) { |
|
95 | + $this->afterCompile[$index]($value, $this->instance, $index); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | return $value; |
99 | 99 | } |
100 | 100 | |
101 | - public function insertField($index,$field){ |
|
102 | - array_splice( $this->visibleProperties, $index, 0, $field ); |
|
101 | + public function insertField($index, $field) { |
|
102 | + array_splice($this->visibleProperties, $index, 0, $field); |
|
103 | 103 | return $this; |
104 | 104 | } |
105 | 105 | |
106 | - public function insertInField($index,$field){ |
|
106 | + public function insertInField($index, $field) { |
|
107 | 107 | $vb=$this->visibleProperties; |
108 | - if(isset($vb[$index])){ |
|
109 | - if(\is_array($vb[$index])){ |
|
108 | + if (isset($vb[$index])) { |
|
109 | + if (\is_array($vb[$index])) { |
|
110 | 110 | $this->visibleProperties[$index][]=$field; |
111 | - }else{ |
|
112 | - $this->visibleProperties[$index]=[$vb[$index],$field]; |
|
111 | + } else { |
|
112 | + $this->visibleProperties[$index]=[$vb[$index], $field]; |
|
113 | 113 | } |
114 | - }else{ |
|
114 | + } else { |
|
115 | 115 | return $this->insertField($index, $field); |
116 | 116 | } |
117 | 117 | return $this; |
118 | 118 | } |
119 | 119 | |
120 | - public function addField($field){ |
|
120 | + public function addField($field) { |
|
121 | 121 | $this->visibleProperties[]=$field; |
122 | 122 | return $this; |
123 | 123 | } |
124 | 124 | |
125 | - public function count(){ |
|
125 | + public function count() { |
|
126 | 126 | return \sizeof($this->properties); |
127 | 127 | } |
128 | 128 | |
129 | - public function visiblePropertiesCount(){ |
|
129 | + public function visiblePropertiesCount() { |
|
130 | 130 | return \sizeof($this->visibleProperties); |
131 | 131 | } |
132 | 132 | |
133 | - public function getProperty($index){ |
|
133 | + public function getProperty($index) { |
|
134 | 134 | return $this->properties[$index]; |
135 | 135 | } |
136 | 136 | |
137 | - public function getFieldName($index){ |
|
137 | + public function getFieldName($index) { |
|
138 | 138 | $property=$this->getProperty($index); |
139 | - if($property instanceof \ReflectionProperty){ |
|
139 | + if ($property instanceof \ReflectionProperty) { |
|
140 | 140 | $result=$property->getName(); |
141 | - }elseif(\is_callable($property)){ |
|
141 | + }elseif (\is_callable($property)) { |
|
142 | 142 | $result=$this->visibleProperties[$index]; |
143 | - }else{ |
|
143 | + } else { |
|
144 | 144 | $result=$property; |
145 | 145 | } |
146 | 146 | return $result; |
147 | 147 | } |
148 | 148 | |
149 | 149 | |
150 | - protected function showableProperty(\ReflectionProperty $rProperty){ |
|
151 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
150 | + protected function showableProperty(\ReflectionProperty $rProperty) { |
|
151 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | public function setInstance($instance) { |
155 | - if(\is_string($instance)){ |
|
155 | + if (\is_string($instance)) { |
|
156 | 156 | $instance=new $instance(); |
157 | 157 | } |
158 | 158 | $this->instance=$instance; |
159 | 159 | $this->properties=[]; |
160 | 160 | $this->reflect=new \ReflectionClass($instance); |
161 | - if(\sizeof($this->visibleProperties)===0){ |
|
161 | + if (\sizeof($this->visibleProperties)===0) { |
|
162 | 162 | $this->properties=$this->getDefaultProperties(); |
163 | - }else{ |
|
164 | - foreach ($this->visibleProperties as $property){ |
|
163 | + } else { |
|
164 | + foreach ($this->visibleProperties as $property) { |
|
165 | 165 | $this->setInstanceProperty($property); |
166 | 166 | } |
167 | 167 | } |
168 | 168 | return $this; |
169 | 169 | } |
170 | 170 | |
171 | - private function setInstanceProperty($property){ |
|
172 | - if(\is_callable($property)){ |
|
171 | + private function setInstanceProperty($property) { |
|
172 | + if (\is_callable($property)) { |
|
173 | 173 | $this->properties[]=$property; |
174 | - }elseif(\is_string($property)){ |
|
175 | - try{ |
|
174 | + }elseif (\is_string($property)) { |
|
175 | + try { |
|
176 | 176 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
177 | 177 | $rProperty=$this->reflect->getProperty($property); |
178 | 178 | $this->properties[]=$rProperty; |
179 | - }catch(\Exception $e){ |
|
179 | + }catch (\Exception $e) { |
|
180 | 180 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
181 | 181 | $this->properties[]=$property; |
182 | 182 | } |
183 | - }elseif(\is_int($property)){ |
|
183 | + }elseif (\is_int($property)) { |
|
184 | 184 | $props=$this->getDefaultProperties(); |
185 | - if(isset($props[$property])) |
|
185 | + if (isset($props[$property])) |
|
186 | 186 | $this->properties[]=$props[$property]; |
187 | 187 | else |
188 | 188 | $this->properties[]=$property; |
189 | - }else{ |
|
189 | + } else { |
|
190 | 190 | $this->properties[]=$property; |
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - protected function getDefaultProperties(){ |
|
194 | + protected function getDefaultProperties() { |
|
195 | 195 | $result=[]; |
196 | 196 | $properties=$this->reflect->getProperties(); |
197 | - foreach ($properties as $property){ |
|
197 | + foreach ($properties as $property) { |
|
198 | 198 | $showable=$this->showableProperty($property); |
199 | - if($showable!==false){ |
|
199 | + if ($showable!==false) { |
|
200 | 200 | $result[]=$property; |
201 | 201 | } |
202 | 202 | } |
@@ -208,12 +208,12 @@ discard block |
||
208 | 208 | return $this; |
209 | 209 | } |
210 | 210 | |
211 | - public function setValueFunction($index,$callback){ |
|
211 | + public function setValueFunction($index, $callback) { |
|
212 | 212 | $this->values[$index]=$callback; |
213 | 213 | return $this; |
214 | 214 | } |
215 | 215 | |
216 | - public function setIdentifierFunction($callback){ |
|
216 | + public function setIdentifierFunction($callback) { |
|
217 | 217 | $this->values["identifier"]=$callback; |
218 | 218 | return $this; |
219 | 219 | } |
@@ -226,41 +226,41 @@ discard block |
||
226 | 226 | return $this->properties; |
227 | 227 | } |
228 | 228 | |
229 | - public function getCaption($index){ |
|
230 | - if(isset($this->captions[$index])){ |
|
229 | + public function getCaption($index) { |
|
230 | + if (isset($this->captions[$index])) { |
|
231 | 231 | return $this->captions[$index]; |
232 | 232 | } |
233 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
233 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
234 | 234 | return $this->properties[$index]->getName(); |
235 | - elseif(\is_callable($this->properties[$index])) |
|
235 | + elseif (\is_callable($this->properties[$index])) |
|
236 | 236 | return ""; |
237 | 237 | else |
238 | 238 | return $this->properties[$index]; |
239 | 239 | } |
240 | 240 | |
241 | - public function getCaptions(){ |
|
242 | - if(isset($this->captions)){ |
|
243 | - $captions= $this->captions; |
|
244 | - for($i=\sizeof($captions);$i<$this->count();$i++){ |
|
241 | + public function getCaptions() { |
|
242 | + if (isset($this->captions)) { |
|
243 | + $captions=$this->captions; |
|
244 | + for ($i=\sizeof($captions); $i<$this->count(); $i++) { |
|
245 | 245 | $captions[]=""; |
246 | 246 | } |
247 | - }else{ |
|
247 | + } else { |
|
248 | 248 | $captions=[]; |
249 | 249 | $index=0; |
250 | 250 | $count=$this->count(); |
251 | - while($index<$count){ |
|
251 | + while ($index<$count) { |
|
252 | 252 | $captions[]=$this->getCaption($index++); |
253 | 253 | } |
254 | 254 | } |
255 | - if(isset($this->captionCallback) && \is_callable($this->captionCallback)){ |
|
255 | + if (isset($this->captionCallback) && \is_callable($this->captionCallback)) { |
|
256 | 256 | $callback=$this->captionCallback; |
257 | - $callback($captions,$this->instance); |
|
257 | + $callback($captions, $this->instance); |
|
258 | 258 | } |
259 | 259 | return $captions; |
260 | 260 | } |
261 | 261 | |
262 | - public function setCaption($index,$caption){ |
|
263 | - if(isset($this->captions)===false) |
|
262 | + public function setCaption($index, $caption) { |
|
263 | + if (isset($this->captions)===false) |
|
264 | 264 | $this->captions=[]; |
265 | 265 | $this->captions[$index]=$caption; |
266 | 266 | return $this; |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @param callable $callback function called after the field compilation |
279 | 279 | * @return \Ajax\semantic\widgets\datatable\InstanceViewer |
280 | 280 | */ |
281 | - public function afterCompile($index,$callback){ |
|
281 | + public function afterCompile($index, $callback) { |
|
282 | 282 | $this->afterCompile[$index]=$callback; |
283 | 283 | return $this; |
284 | 284 | } |
@@ -21,8 +21,9 @@ discard block |
||
21 | 21 | $this->widgetIdentifier=$identifier; |
22 | 22 | $this->values=[]; |
23 | 23 | $this->afterCompile=[]; |
24 | - if(isset($instance)) |
|
25 | - $this->setInstance($instance); |
|
24 | + if(isset($instance)) { |
|
25 | + $this->setInstance($instance); |
|
26 | + } |
|
26 | 27 | $this->setCaptions($captions); |
27 | 28 | $this->captionCallback=NULL; |
28 | 29 | $this->defaultValueFunction=function($name,$value){return $value;}; |
@@ -39,11 +40,13 @@ discard block |
||
39 | 40 | } |
40 | 41 | |
41 | 42 | public function getIdentifier($index=NULL){ |
42 | - if(!isset($index)) |
|
43 | - $index=self::$index; |
|
43 | + if(!isset($index)) { |
|
44 | + $index=self::$index; |
|
45 | + } |
|
44 | 46 | $value=$index; |
45 | - if(isset($this->values["identifier"])) |
|
46 | - $value=$this->values["identifier"]($index,$this->instance); |
|
47 | + if(isset($this->values["identifier"])) { |
|
48 | + $value=$this->values["identifier"]($index,$this->instance); |
|
49 | + } |
|
47 | 50 | return $value; |
48 | 51 | } |
49 | 52 | |
@@ -66,7 +69,7 @@ discard block |
||
66 | 69 | $value=$property->getValue($this->instance); |
67 | 70 | if(isset($this->values[$index])){ |
68 | 71 | $value= $this->values[$index]($value,$this->instance,$index); |
69 | - }else{ |
|
72 | + } else{ |
|
70 | 73 | $value=$this->_getDefaultValue($property->getName(),$value, $index); |
71 | 74 | } |
72 | 75 | return $value; |
@@ -76,16 +79,16 @@ discard block |
||
76 | 79 | $value=null; |
77 | 80 | if($property instanceof \ReflectionProperty){ |
78 | 81 | $value=$this->_getPropertyValue($property, $index); |
79 | - }else{ |
|
80 | - if(\is_callable($property)) |
|
81 | - $value=$property($this->instance); |
|
82 | - elseif(\is_array($property)){ |
|
82 | + } else{ |
|
83 | + if(\is_callable($property)) { |
|
84 | + $value=$property($this->instance); |
|
85 | + } elseif(\is_array($property)){ |
|
83 | 86 | $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
84 | 87 | $value=\implode("", $values); |
85 | - }else{ |
|
88 | + } else{ |
|
86 | 89 | if(isset($this->values[$index])){ |
87 | 90 | $value= $this->values[$index]($property,$this->instance,$index); |
88 | - }elseif(isset($this->instance->{$property})){ |
|
91 | + } elseif(isset($this->instance->{$property})){ |
|
89 | 92 | $value=$this->instance->{$property}; |
90 | 93 | } |
91 | 94 | } |
@@ -108,10 +111,10 @@ discard block |
||
108 | 111 | if(isset($vb[$index])){ |
109 | 112 | if(\is_array($vb[$index])){ |
110 | 113 | $this->visibleProperties[$index][]=$field; |
111 | - }else{ |
|
114 | + } else{ |
|
112 | 115 | $this->visibleProperties[$index]=[$vb[$index],$field]; |
113 | 116 | } |
114 | - }else{ |
|
117 | + } else{ |
|
115 | 118 | return $this->insertField($index, $field); |
116 | 119 | } |
117 | 120 | return $this; |
@@ -138,9 +141,9 @@ discard block |
||
138 | 141 | $property=$this->getProperty($index); |
139 | 142 | if($property instanceof \ReflectionProperty){ |
140 | 143 | $result=$property->getName(); |
141 | - }elseif(\is_callable($property)){ |
|
144 | + } elseif(\is_callable($property)){ |
|
142 | 145 | $result=$this->visibleProperties[$index]; |
143 | - }else{ |
|
146 | + } else{ |
|
144 | 147 | $result=$property; |
145 | 148 | } |
146 | 149 | return $result; |
@@ -160,7 +163,7 @@ discard block |
||
160 | 163 | $this->reflect=new \ReflectionClass($instance); |
161 | 164 | if(\sizeof($this->visibleProperties)===0){ |
162 | 165 | $this->properties=$this->getDefaultProperties(); |
163 | - }else{ |
|
166 | + } else{ |
|
164 | 167 | foreach ($this->visibleProperties as $property){ |
165 | 168 | $this->setInstanceProperty($property); |
166 | 169 | } |
@@ -171,22 +174,23 @@ discard block |
||
171 | 174 | private function setInstanceProperty($property){ |
172 | 175 | if(\is_callable($property)){ |
173 | 176 | $this->properties[]=$property; |
174 | - }elseif(\is_string($property)){ |
|
177 | + } elseif(\is_string($property)){ |
|
175 | 178 | try{ |
176 | 179 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
177 | 180 | $rProperty=$this->reflect->getProperty($property); |
178 | 181 | $this->properties[]=$rProperty; |
179 | - }catch(\Exception $e){ |
|
182 | + } catch(\Exception $e){ |
|
180 | 183 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
181 | 184 | $this->properties[]=$property; |
182 | 185 | } |
183 | - }elseif(\is_int($property)){ |
|
186 | + } elseif(\is_int($property)){ |
|
184 | 187 | $props=$this->getDefaultProperties(); |
185 | - if(isset($props[$property])) |
|
186 | - $this->properties[]=$props[$property]; |
|
187 | - else |
|
188 | - $this->properties[]=$property; |
|
189 | - }else{ |
|
188 | + if(isset($props[$property])) { |
|
189 | + $this->properties[]=$props[$property]; |
|
190 | + } else { |
|
191 | + $this->properties[]=$property; |
|
192 | + } |
|
193 | + } else{ |
|
190 | 194 | $this->properties[]=$property; |
191 | 195 | } |
192 | 196 | } |
@@ -230,12 +234,13 @@ discard block |
||
230 | 234 | if(isset($this->captions[$index])){ |
231 | 235 | return $this->captions[$index]; |
232 | 236 | } |
233 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
234 | - return $this->properties[$index]->getName(); |
|
235 | - elseif(\is_callable($this->properties[$index])) |
|
236 | - return ""; |
|
237 | - else |
|
238 | - return $this->properties[$index]; |
|
237 | + if($this->properties[$index] instanceof \ReflectionProperty) { |
|
238 | + return $this->properties[$index]->getName(); |
|
239 | + } elseif(\is_callable($this->properties[$index])) { |
|
240 | + return ""; |
|
241 | + } else { |
|
242 | + return $this->properties[$index]; |
|
243 | + } |
|
239 | 244 | } |
240 | 245 | |
241 | 246 | public function getCaptions(){ |
@@ -244,7 +249,7 @@ discard block |
||
244 | 249 | for($i=\sizeof($captions);$i<$this->count();$i++){ |
245 | 250 | $captions[]=""; |
246 | 251 | } |
247 | - }else{ |
|
252 | + } else{ |
|
248 | 253 | $captions=[]; |
249 | 254 | $index=0; |
250 | 255 | $count=$this->count(); |
@@ -260,8 +265,9 @@ discard block |
||
260 | 265 | } |
261 | 266 | |
262 | 267 | public function setCaption($index,$caption){ |
263 | - if(isset($this->captions)===false) |
|
264 | - $this->captions=[]; |
|
268 | + if(isset($this->captions)===false) { |
|
269 | + $this->captions=[]; |
|
270 | + } |
|
265 | 271 | $this->captions[$index]=$caption; |
266 | 272 | return $this; |
267 | 273 | } |