@@ -71,6 +71,10 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | |
| 73 | 73 | |
| 74 | + /** |
|
| 75 | + * @param string $name |
|
| 76 | + * @param string[] $typeCtrl |
|
| 77 | + */ |
|
| 74 | 78 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
| 75 | 79 | if ($this->ctrl($name, $value, $typeCtrl) === true) { |
| 76 | 80 | return $name=$value; |
@@ -88,6 +92,10 @@ discard block |
||
| 88 | 92 | |
| 89 | 93 | |
| 90 | 94 | |
| 95 | + /** |
|
| 96 | + * @param string $name |
|
| 97 | + * @param string[] $typeCtrl |
|
| 98 | + */ |
|
| 91 | 99 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
| 92 | 100 | if ($this->ctrl($name, $value, $typeCtrl) === true) { |
| 93 | 101 | if (\is_array($typeCtrl)) { |
@@ -98,6 +106,9 @@ discard block |
||
| 98 | 106 | return $this; |
| 99 | 107 | } |
| 100 | 108 | |
| 109 | + /** |
|
| 110 | + * @param string $name |
|
| 111 | + */ |
|
| 101 | 112 | protected function addToMember(&$name, $value, $separator=" ") { |
| 102 | 113 | $name=str_ireplace($value, "", $name) . $separator . $value; |
| 103 | 114 | return $this; |
@@ -179,6 +190,9 @@ discard block |
||
| 179 | 190 | return $this->_getElementBy(function($element) use ($identifier){return $element->getIdentifier()===$identifier;}, $elements); |
| 180 | 191 | } |
| 181 | 192 | |
| 193 | + /** |
|
| 194 | + * @param \Closure $callback |
|
| 195 | + */ |
|
| 182 | 196 | protected function _getElementBy($callback,$elements){ |
| 183 | 197 | if (\is_array($elements)) { |
| 184 | 198 | $flag=false; |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | * @version 1.2 |
| 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 | 25 | public function getBsComponent() { |
@@ -32,24 +32,24 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | protected function getTemplate(JsUtils $js=NULL) { |
| 35 | - return PropertyWrapper::wrap($this->_wrapBefore, $js) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 35 | + return PropertyWrapper::wrap($this->_wrapBefore, $js).$this->_template.PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
| 39 | 39 | $result=$this->getTemplate($js); |
| 40 | - foreach ( $this as $key => $value ) { |
|
| 41 | - if (JString::startswith($key, "_") === false && $key !== "events") { |
|
| 40 | + foreach ($this as $key => $value) { |
|
| 41 | + if (JString::startswith($key, "_")===false && $key!=="events") { |
|
| 42 | 42 | if (\is_array($value)) { |
| 43 | 43 | $v=PropertyWrapper::wrap($value, $js); |
| 44 | 44 | } else { |
| 45 | 45 | $v=$value; |
| 46 | 46 | } |
| 47 | - $result=str_ireplace("%" . $key . "%", $v, $result); |
|
| 47 | + $result=str_ireplace("%".$key."%", $v, $result); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | if (isset($js)===true) { |
| 51 | 51 | $this->run($js); |
| 52 | - if (isset($view) === true) { |
|
| 52 | + if (isset($view)===true) { |
|
| 53 | 53 | $js->addViewElement($this->identifier, $result, $view); |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -58,12 +58,12 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | protected function ctrl($name, $value, $typeCtrl) { |
| 60 | 60 | if (\is_array($typeCtrl)) { |
| 61 | - if (array_search($value, $typeCtrl) === false) { |
|
| 62 | - throw new \Exception("La valeur passée `" . $value . "` à la propriété `" . $name . "` ne fait pas partie des valeurs possibles : {" . implode(",", $typeCtrl) . "}"); |
|
| 61 | + if (array_search($value, $typeCtrl)===false) { |
|
| 62 | + throw new \Exception("La valeur passée `".$value."` à la propriété `".$name."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
| 63 | 63 | } |
| 64 | 64 | } else { |
| 65 | 65 | if (!$typeCtrl($value)) { |
| 66 | - throw new \Exception("La fonction " . $typeCtrl . " a retourné faux pour l'affectation de la propriété " . $name); |
|
| 66 | + throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$name); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | return true; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | |
| 74 | 74 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
| 75 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 75 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 76 | 76 | return $name=$value; |
| 77 | 77 | } |
| 78 | 78 | return $this; |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") { |
| 82 | 82 | if (\is_array($typeCtrl)) { |
| 83 | 83 | $this->removeOldValues($name, $typeCtrl); |
| 84 | - $name.=$separator . $value; |
|
| 84 | + $name.=$separator.$value; |
|
| 85 | 85 | } |
| 86 | 86 | return $this; |
| 87 | 87 | } |
@@ -89,17 +89,17 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | |
| 91 | 91 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
| 92 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 92 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 93 | 93 | if (\is_array($typeCtrl)) { |
| 94 | 94 | $this->removeOldValues($name, $typeCtrl); |
| 95 | 95 | } |
| 96 | - $name.=$separator . $value; |
|
| 96 | + $name.=$separator.$value; |
|
| 97 | 97 | } |
| 98 | 98 | return $this; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | protected function addToMember(&$name, $value, $separator=" ") { |
| 102 | - $name=str_ireplace($value, "", $name) . $separator . $value; |
|
| 102 | + $name=str_ireplace($value, "", $name).$separator.$value; |
|
| 103 | 103 | return $this; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -127,26 +127,26 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | public function fromArray($array) { |
| 130 | - foreach ( $this as $key => $value ) { |
|
| 131 | - if(array_key_exists($key, $array)===true) |
|
| 132 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
| 130 | + foreach ($this as $key => $value) { |
|
| 131 | + if (array_key_exists($key, $array)===true) |
|
| 132 | + $this->_callSetter("set".ucfirst($key), $key, $array[$key], $array); |
|
| 133 | 133 | } |
| 134 | - foreach ( $array as $key => $value ) { |
|
| 135 | - if($this->_callSetter($key, $key, $value, $array)===false){ |
|
| 136 | - $this->_callSetter("set" . ucfirst($key), $key, $value, $array); |
|
| 134 | + foreach ($array as $key => $value) { |
|
| 135 | + if ($this->_callSetter($key, $key, $value, $array)===false) { |
|
| 136 | + $this->_callSetter("set".ucfirst($key), $key, $value, $array); |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | return $array; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - private function _callSetter($setter,$key,$value,&$array){ |
|
| 142 | + private function _callSetter($setter, $key, $value, &$array) { |
|
| 143 | 143 | $result=false; |
| 144 | 144 | if (method_exists($this, $setter) && !JString::startswith($key, "_")) { |
| 145 | 145 | try { |
| 146 | 146 | $this->$setter($value); |
| 147 | 147 | unset($array[$key]); |
| 148 | 148 | $result=true; |
| 149 | - } catch ( \Exception $e ) { |
|
| 149 | + }catch (\Exception $e) { |
|
| 150 | 150 | $result=false; |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | public function fromDatabaseObjects($objects, $function) { |
| 157 | 157 | if (isset($objects)) { |
| 158 | - foreach ( $objects as $object ) { |
|
| 158 | + foreach ($objects as $object) { |
|
| 159 | 159 | $this->fromDatabaseObject($object, $function); |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -176,20 +176,20 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | |
| 178 | 178 | public function getElementById($identifier, $elements) { |
| 179 | - return $this->_getElementBy(function($element) use ($identifier){return $element->getIdentifier()===$identifier;}, $elements); |
|
| 179 | + return $this->_getElementBy(function($element) use ($identifier){return $element->getIdentifier()===$identifier; }, $elements); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - protected function _getElementBy($callback,$elements){ |
|
| 182 | + protected function _getElementBy($callback, $elements) { |
|
| 183 | 183 | if (\is_array($elements)) { |
| 184 | 184 | $flag=false; |
| 185 | 185 | $index=0; |
| 186 | - while ( !$flag && $index < sizeof($elements) ) { |
|
| 186 | + while (!$flag && $index<sizeof($elements)) { |
|
| 187 | 187 | if ($elements[$index] instanceof BaseHtml) |
| 188 | 188 | $flag=($callback($elements[$index])); |
| 189 | 189 | $index++; |
| 190 | 190 | } |
| 191 | - if ($flag === true) |
|
| 192 | - return $elements[$index - 1]; |
|
| 191 | + if ($flag===true) |
|
| 192 | + return $elements[$index-1]; |
|
| 193 | 193 | } elseif ($elements instanceof BaseHtml) { |
| 194 | 194 | if ($callback($elements)) |
| 195 | 195 | return $elements; |
@@ -8,12 +8,12 @@ discard block |
||
| 8 | 8 | * @author jc |
| 9 | 9 | * |
| 10 | 10 | */ |
| 11 | -trait BaseHtmlPropertiesTrait{ |
|
| 11 | +trait BaseHtmlPropertiesTrait { |
|
| 12 | 12 | |
| 13 | - protected $properties=array (); |
|
| 13 | + protected $properties=array(); |
|
| 14 | 14 | abstract protected function ctrl($name, $value, $typeCtrl); |
| 15 | 15 | abstract protected function removeOldValues(&$oldValue, $allValues); |
| 16 | - abstract protected function _getElementBy($callback,$elements); |
|
| 16 | + abstract protected function _getElementBy($callback, $elements); |
|
| 17 | 17 | public function getProperties() { |
| 18 | 18 | return $this->properties; |
| 19 | 19 | } |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | public function addToProperty($name, $value, $separator=" ") { |
| 41 | 41 | if (\is_array($value)) { |
| 42 | - foreach ( $value as $v ) { |
|
| 42 | + foreach ($value as $v) { |
|
| 43 | 43 | $this->addToProperty($name, $v, $separator); |
| 44 | 44 | } |
| 45 | - } else if ($value !== "" && $this->propertyContains($name, $value) === false) { |
|
| 45 | + } else if ($value!=="" && $this->propertyContains($name, $value)===false) { |
|
| 46 | 46 | $v=@$this->properties[$name]; |
| 47 | - if (isset($v) && $v !== "") |
|
| 48 | - $v=$v . $separator . $value; |
|
| 47 | + if (isset($v) && $v!=="") |
|
| 48 | + $v=$v.$separator.$value; |
|
| 49 | 49 | else |
| 50 | 50 | $v=$value; |
| 51 | 51 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | public function addToPropertyCtrlCheck($name, $value, $typeCtrl) { |
| 86 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 86 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 87 | 87 | return $this->addToProperty($name, $value); |
| 88 | 88 | } |
| 89 | 89 | return $this; |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | protected function setPropertyCtrl($name, $value, $typeCtrl) { |
| 107 | - if ($this->ctrl($name, $value, $typeCtrl) === true) |
|
| 107 | + if ($this->ctrl($name, $value, $typeCtrl)===true) |
|
| 108 | 108 | return $this->setProperty($name, $value); |
| 109 | 109 | return $this; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - protected function getElementByPropertyValue($propertyName,$value, $elements) { |
|
| 113 | - return $this->_getElementBy(function($element) use ($propertyName,$value){return $element->propertyContains($propertyName, $value) === true;}, $elements); |
|
| 112 | + protected function getElementByPropertyValue($propertyName, $value, $elements) { |
|
| 113 | + return $this->_getElementBy(function($element) use ($propertyName, $value){return $element->propertyContains($propertyName, $value)===true; }, $elements); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | \ No newline at end of file |