@@ -34,11 +34,11 @@ |
||
| 34 | 34 | * @param string $class Class name to be autoloaded |
| 35 | 35 | */ |
| 36 | 36 | spl_autoload_register(function($class) {
|
| 37 | - if(strpos($class, "Seufert\\Hamle\\") === 0) {
|
|
| 37 | + if (strpos($class, "Seufert\\Hamle\\") === 0) {
|
|
| 38 | 38 | $s = DIRECTORY_SEPARATOR; |
| 39 | - $class = str_replace("\\",$s,substr($class,14));
|
|
| 40 | - $path = __DIR__.$s."hamle".$s."$class.php"; |
|
| 41 | - if(is_file($path)) include_once($path); |
|
| 39 | + $class = str_replace("\\", $s, substr($class, 14));
|
|
| 40 | + $path = __DIR__ . $s . "hamle" . $s . "$class.php"; |
|
| 41 | + if (is_file($path)) include_once($path); |
|
| 42 | 42 | } |
| 43 | -},true,true); |
|
| 43 | +},true, true); |
|
| 44 | 44 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | function getInputAttStatic(&$atts, &$type, &$content) {
|
| 125 | 125 | $atts['id'] = $atts['name'] = $this->form . "_" . $this->name; |
| 126 | 126 | $atts['type'] = "text"; |
| 127 | - $atts['class'][] = str_replace(['Seufert\\','\\'],['','_'],get_class($this)); |
|
| 127 | + $atts['class'][] = str_replace(['Seufert\\', '\\'], ['', '_'], get_class($this)); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | function getInputAttDynamic(&$atts, &$type, &$content) {
|
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | function getLabelAttStatic(&$atts, &$type, &$content) {
|
| 145 | - $atts['class'][] = str_replace(['Seufert\\','\\'],['','_'],get_class($this)); |
|
| 145 | + $atts['class'][] = str_replace(['Seufert\\', '\\'], ['', '_'], get_class($this)); |
|
| 146 | 146 | $atts["for"] = $this->form . "_" . $this->name; |
| 147 | 147 | $content = array($this->opt['label']); |
| 148 | 148 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | function getHintAttStatic(&$atts, &$type, &$content) {
|
| 154 | - $atts['class'][] = str_replace(['Seufert\\','\\'],['','_'],get_class($this)); |
|
| 154 | + $atts['class'][] = str_replace(['Seufert\\', '\\'], ['', '_'], get_class($this)); |
|
| 155 | 155 | $atts['class'][] = "hamleFormHint"; |
| 156 | 156 | } |
| 157 | 157 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | foreach ($labelTags as $tag) |
| 62 | 62 | if ($tag instanceOf Html) |
| 63 | 63 | foreach ($tag->source as $source) { |
| 64 | - if(isset($fields[$source])) |
|
| 64 | + if (isset($fields[$source])) |
|
| 65 | 65 | $fields[$source]->getLabelAttStatic($tag->opt, $tag->type, $tag->content); |
| 66 | 66 | else |
| 67 | 67 | $tag->opt['style'] = "display:none;"; |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | foreach ($inputTags as $tag) |
| 71 | 71 | if ($tag instanceOf Html) |
| 72 | 72 | foreach ($tag->source as $source) { |
| 73 | - if(isset($fields[$source])) |
|
| 73 | + if (isset($fields[$source])) |
|
| 74 | 74 | $fields[$source]->getHintAttStatic($tag->opt, $tag->type, $tag->content); |
| 75 | 75 | else |
| 76 | 76 | $tag->opt['style'] = "display:none;"; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | foreach ($inputTags as $tag) |
| 80 | 80 | if ($tag instanceOf Html) |
| 81 | 81 | foreach ($tag->source as $source) { |
| 82 | - if(isset($fields[$source])) { |
|
| 82 | + if (isset($fields[$source])) { |
|
| 83 | 83 | $fields[$source]->getInputAttStatic($tag->opt, $tag->type, $tag->content); |
| 84 | 84 | unset($fields[$source]); |
| 85 | 85 | } else |
@@ -87,10 +87,10 @@ discard block |
||
| 87 | 87 | } |
| 88 | 88 | foreach ($fields as $n => $f) { |
| 89 | 89 | if (!$f instanceOf Button) { |
| 90 | - $this->addChild($label = new DynHtml("label", [],[],"",$n)); |
|
| 90 | + $this->addChild($label = new DynHtml("label", [], [], "", $n)); |
|
| 91 | 91 | $f->getLabelAttStatic($label->opt, $label->type, $label->content); |
| 92 | 92 | } |
| 93 | - $this->addChild($input = new DynHtml("input", [],[],"",$n)); |
|
| 93 | + $this->addChild($input = new DynHtml("input", [], [], "", $n)); |
|
| 94 | 94 | $f->getInputAttStatic($input->opt, $input->type, $input->content); |
| 95 | 95 | } |
| 96 | 96 | return "<form " . implode(" ", $out) . "><?php \$form = " . $this->var->toPHP() . "; \$form->process(); ?>"; |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | |
| 46 | 46 | static function decodeClassId($s) { |
| 47 | 47 | $out = $m = array(); |
| 48 | - if(preg_match('/^[a-zA-Z0-9\_]+/', $s, $m)) |
|
| 48 | + if (preg_match('/^[a-zA-Z0-9\_]+/', $s, $m)) |
|
| 49 | 49 | $out['type'] = $m[0]; |
| 50 | 50 | preg_match_all('/[#\.][a-zA-Z0-9\-\_]+/m', $s, $m); |
| 51 | 51 | if (isset($m[0])) foreach ($m[0] as $s) { |
@@ -42,17 +42,17 @@ |
||
| 42 | 42 | function __construct($tag, $class = array(), $attr = array(), $id = "") { |
| 43 | 43 | parent::__construct(); |
| 44 | 44 | $this->opt = $attr; |
| 45 | - if(isset($attr['class']) && !is_array($attr['class'])) |
|
| 46 | - $this->opt['class'] = $attr['class']?explode(" ",$attr['class']):array(); |
|
| 45 | + if (isset($attr['class']) && !is_array($attr['class'])) |
|
| 46 | + $this->opt['class'] = $attr['class'] ? explode(" ", $attr['class']) : array(); |
|
| 47 | 47 | $this->source = array(); |
| 48 | 48 | $this->type = $tag ? $tag : "div"; |
| 49 | - if($class) { |
|
| 49 | + if ($class) { |
|
| 50 | 50 | if (isset($this->opt['class'])) |
| 51 | 51 | $this->opt['class'] = array_merge($this->opt['class'], $class); |
| 52 | 52 | else |
| 53 | 53 | $this->opt['class'] = $class; |
| 54 | 54 | } |
| 55 | - if($id) $this->opt['id'] = $id; |
|
| 55 | + if ($id) $this->opt['id'] = $id; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | function renderStTag() { |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * Fills the $this->fields array with hamleFields |
| 45 | 45 | */ |
| 46 | 46 | function setup() {
|
| 47 | - throw new Exception\RunTime("You must configure the form in the setup ".
|
|
| 47 | + throw new Exception\RunTime("You must configure the form in the setup " .
|
|
| 48 | 48 | "function, by adding fields to the \$this->fields array"); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $this->setup(); |
| 55 | 55 | $fields = $this->_fields; |
| 56 | 56 | $this->_fields = array(); |
| 57 | - foreach($fields as $v) {
|
|
| 57 | + foreach ($fields as $v) {
|
|
| 58 | 58 | $this->_fields[$v->name] = $v; |
| 59 | 59 | $v->form($this->_name); |
| 60 | 60 | } |
@@ -64,23 +64,23 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | function process() {
|
| 66 | 66 | $clicked = ""; |
| 67 | - foreach($this->_fields as $f) |
|
| 68 | - if($f instanceOf Field\Button) |
|
| 69 | - if($f->isClicked()) |
|
| 67 | + foreach ($this->_fields as $f) |
|
| 68 | + if ($f instanceOf Field\Button) |
|
| 69 | + if ($f->isClicked()) |
|
| 70 | 70 | $clicked = $f; |
| 71 | - foreach($this->_fields as $f) |
|
| 72 | - $f->doProcess($clicked?true:false); |
|
| 73 | - if($clicked) |
|
| 71 | + foreach ($this->_fields as $f) |
|
| 72 | + $f->doProcess($clicked ? true : false); |
|
| 73 | + if ($clicked) |
|
| 74 | 74 | try {
|
| 75 | 75 | $this->onSubmit($clicked); |
| 76 | - } catch(Exception\FormInvalid $e) {
|
|
| 76 | + } catch (Exception\FormInvalid $e) {
|
|
| 77 | 77 | $this->hint = $e->getMessage(); |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | function isValid() {
|
| 82 | 82 | $valid = true; |
| 83 | - foreach($this->_fields as $f) |
|
| 83 | + foreach ($this->_fields as $f) |
|
| 84 | 84 | $valid = $f->valid && $valid; |
| 85 | 85 | return $valid; |
| 86 | 86 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | return $this->_fields; |
| 96 | 96 | } |
| 97 | 97 | function getField($n) {
|
| 98 | - if(!isset($this->_fields[$n])) |
|
| 98 | + if (!isset($this->_fields[$n])) |
|
| 99 | 99 | throw new Exception\NoKey("unable to find form field ($n)");
|
| 100 | 100 | return $this->_fields[$n]; |
| 101 | 101 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function getHTMLProp() {
|
| 107 | - return array('action'=>'','method'=>'post','name'=>$this->_name,
|
|
| 107 | + return array('action'=>'', 'method'=>'post', 'name'=>$this->_name,
|
|
| 108 | 108 | 'enctype'=>'multipart/form-data'); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | |
| 34 | 34 | function __construct($s) { |
| 35 | 35 | $m = array(); |
| 36 | - if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) |
|
| 36 | + if (!preg_match('/^ +([><]) +(' . self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) |
|
| 37 | 37 | throw new ParseError("Unable to read \$ sub func in '$s'"); |
| 38 | 38 | if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT; |
| 39 | 39 | elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD; |
@@ -34,9 +34,9 @@ discard block |
||
| 34 | 34 | protected $filter; |
| 35 | 35 | |
| 36 | 36 | function __construct($s) { |
| 37 | - if(FALSE !== $pos = strpos($s,'|')) { |
|
| 38 | - $this->filter = new Filter(substr($s, $pos+1), $this); |
|
| 39 | - $s = substr($s,0,$pos); |
|
| 37 | + if (FALSE !== $pos = strpos($s, '|')) { |
|
| 38 | + $this->filter = new Filter(substr($s, $pos + 1), $this); |
|
| 39 | + $s = substr($s, 0, $pos); |
|
| 40 | 40 | } |
| 41 | 41 | $s = explode("->", $s); |
| 42 | 42 | if (!$s[0]) throw new ParseError("Unable to parse Complex Expression"); |
@@ -51,12 +51,12 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | function toHTML($escape = false) { |
| 54 | - if($escape) |
|
| 55 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 54 | + if ($escape) |
|
| 55 | + return "<?=htmlspecialchars(" . $this->toPHP() . ")?>"; |
|
| 56 | 56 | return "<?=" . $this->toPHP() . "?>"; |
| 57 | 57 | } |
| 58 | 58 | function toPHP() { |
| 59 | - return $this->filter?$this->filter->toPHP():$this->toPHPVar(); |
|
| 59 | + return $this->filter ? $this->filter->toPHP() : $this->toPHPVar(); |
|
| 60 | 60 | } |
| 61 | 61 | function toPHPVar() { |
| 62 | 62 | if ($this->sel) { |
@@ -33,22 +33,22 @@ |
||
| 33 | 33 | protected $filter; |
| 34 | 34 | |
| 35 | 35 | function __construct($s) { |
| 36 | - if(FALSE !== $pos = strpos($s,'|')) { |
|
| 37 | - $this->var = substr($s,1,$pos-1); |
|
| 38 | - $this->filter = new Filter(substr($s, $pos+1), $this); |
|
| 36 | + if (FALSE !== $pos = strpos($s, '|')) { |
|
| 37 | + $this->var = substr($s, 1, $pos - 1); |
|
| 38 | + $this->filter = new Filter(substr($s, $pos + 1), $this); |
|
| 39 | 39 | } else { |
| 40 | 40 | $this->var = substr($s, 1); |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | function toHTML($escape = false) { |
| 45 | - if($escape) |
|
| 46 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 45 | + if ($escape) |
|
| 46 | + return "<?=htmlspecialchars(" . $this->toPHP() . ")?>"; |
|
| 47 | 47 | return "<?=" . $this->toPHP() . "?>"; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | function toPHP() { |
| 51 | - return $this->filter?$this->filter->toPHP():$this->toPHPVar(); |
|
| 51 | + return $this->filter ? $this->filter->toPHP() : $this->toPHPVar(); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | function toPHPVar() { |