@@ -33,6 +33,9 @@ |
||
33 | 33 | protected $param1, $param2, $operator; |
34 | 34 | const REGEX_COMP_OPER = '(equals|notequal|notequals|less|greater|has|starts|contains|ends)'; |
35 | 35 | |
36 | + /** |
|
37 | + * @param string $s |
|
38 | + */ |
|
36 | 39 | function __construct($s, $mode = self::TOKEN_CONTROL) { |
37 | 40 | $m = array(); |
38 | 41 | if(preg_match('/^(.*) '.self::REGEX_COMP_OPER.' (.*)$/', $s, $m)) { |
@@ -39,8 +39,9 @@ discard block |
||
39 | 39 | $this->param1 = new Text($m[1],Text::TOKEN_HTML); |
40 | 40 | $this->param2 = new Text($m[3],Text::TOKEN_HTML); |
41 | 41 | $this->operator = $m[2]; |
42 | - } else |
|
43 | - $this->param1 = new Text($s,Text::TOKEN_HTML); |
|
42 | + } else { |
|
43 | + $this->param1 = new Text($s,Text::TOKEN_HTML); |
|
44 | + } |
|
44 | 45 | } |
45 | 46 | |
46 | 47 | // function __construct(String $p1, String $p2, $operator) { |
@@ -49,7 +50,9 @@ discard block |
||
49 | 50 | // $this->operator = $operator; |
50 | 51 | // } |
51 | 52 | function toPHP() { |
52 | - if(!$this->param2) return $this->param1->toPHP(); |
|
53 | + if(!$this->param2) { |
|
54 | + return $this->param1->toPHP(); |
|
55 | + } |
|
53 | 56 | $p1 = $this->param1->toPHP(); |
54 | 57 | $p2 = $this->param2->toPHP(); |
55 | 58 | switch($this->operator) { |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | |
36 | 36 | function __construct($s, $mode = self::TOKEN_CONTROL) { |
37 | 37 | $m = array(); |
38 | - if(preg_match('/^(.*) '.self::REGEX_COMP_OPER.' (.*)$/', $s, $m)) { |
|
39 | - $this->param1 = new Text($m[1],Text::TOKEN_HTML); |
|
40 | - $this->param2 = new Text($m[3],Text::TOKEN_HTML); |
|
38 | + if (preg_match('/^(.*) '.self::REGEX_COMP_OPER.' (.*)$/', $s, $m)) { |
|
39 | + $this->param1 = new Text($m[1], Text::TOKEN_HTML); |
|
40 | + $this->param2 = new Text($m[3], Text::TOKEN_HTML); |
|
41 | 41 | $this->operator = $m[2]; |
42 | 42 | } else |
43 | - $this->param1 = new Text($s,Text::TOKEN_HTML); |
|
43 | + $this->param1 = new Text($s, Text::TOKEN_HTML); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | // function __construct(String $p1, String $p2, $operator) { |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | // $this->operator = $operator; |
50 | 50 | // } |
51 | 51 | function toPHP() { |
52 | - if(!$this->param2) return $this->param1->toPHP(); |
|
52 | + if (!$this->param2) return $this->param1->toPHP(); |
|
53 | 53 | $p1 = $this->param1->toPHP(); |
54 | 54 | $p2 = $this->param2->toPHP(); |
55 | - switch($this->operator) { |
|
55 | + switch ($this->operator) { |
|
56 | 56 | case "equals": |
57 | 57 | case "equal": |
58 | 58 | return $p1." == ".$p2; |
@@ -33,6 +33,9 @@ |
||
33 | 33 | protected $sel = null; |
34 | 34 | protected $filter; |
35 | 35 | |
36 | + /** |
|
37 | + * @param string $s |
|
38 | + */ |
|
36 | 39 | function __construct($s) { |
37 | 40 | if(FALSE !== $pos = strpos($s,'|')) { |
38 | 41 | $this->filter = new Filter(substr($s, $pos+1), $this); |
@@ -39,21 +39,27 @@ discard block |
||
39 | 39 | $s = substr($s,0,$pos); |
40 | 40 | } |
41 | 41 | $s = explode("->", $s); |
42 | - if(count($s) == 1) $s = explode("-!",$s[0]); |
|
43 | - if (!$s[0]) throw new ParseError("Unable to parse Complex Expression"); |
|
44 | - if ($s[0][1] == "(") |
|
45 | - $this->func = new Text\Func($s[0]); |
|
46 | - elseif ($s[0][1] == "[") |
|
47 | - $this->func = new Text\Scope($s[0]); |
|
48 | - else |
|
49 | - $this->func = new SimpleVar($s[0]); |
|
42 | + if(count($s) == 1) { |
|
43 | + $s = explode("-!",$s[0]); |
|
44 | + } |
|
45 | + if (!$s[0]) { |
|
46 | + throw new ParseError("Unable to parse Complex Expression"); |
|
47 | + } |
|
48 | + if ($s[0][1] == "(") { |
|
49 | + $this->func = new Text\Func($s[0]); |
|
50 | + } elseif ($s[0][1] == "[") { |
|
51 | + $this->func = new Text\Scope($s[0]); |
|
52 | + } else { |
|
53 | + $this->func = new SimpleVar($s[0]); |
|
54 | + } |
|
50 | 55 | array_shift($s); |
51 | 56 | $this->sel = $s; |
52 | 57 | } |
53 | 58 | |
54 | 59 | function toHTML($escape = false) { |
55 | - if($escape) |
|
56 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
60 | + if($escape) { |
|
61 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
62 | + } |
|
57 | 63 | return "<?=" . $this->toPHP() . "?>"; |
58 | 64 | } |
59 | 65 | function toPHP() { |
@@ -62,11 +68,13 @@ discard block |
||
62 | 68 | function toPHPVar() { |
63 | 69 | if ($this->sel) { |
64 | 70 | $sel = array(); |
65 | - foreach ($this->sel as $s) |
|
66 | - $sel[] = "hamleGet('$s')"; |
|
71 | + foreach ($this->sel as $s) { |
|
72 | + $sel[] = "hamleGet('$s')"; |
|
73 | + } |
|
67 | 74 | return $this->func->toPHP() . "->" . implode('->', $sel); |
68 | - } else |
|
69 | - return $this->func->toPHP(); |
|
75 | + } else { |
|
76 | + return $this->func->toPHP(); |
|
77 | + } |
|
70 | 78 | } |
71 | 79 | |
72 | 80 | } |
73 | 81 | \ No newline at end of file |
@@ -34,12 +34,12 @@ 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 | - if(count($s) == 1) $s = explode("-!",$s[0]); |
|
42 | + if (count($s) == 1) $s = explode("-!", $s[0]); |
|
43 | 43 | if (!$s[0]) throw new ParseError("Unable to parse Complex Expression"); |
44 | 44 | if ($s[0][1] == "(") |
45 | 45 | $this->func = new Text\Func($s[0]); |
@@ -52,19 +52,19 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | function toHTML($escape = false) { |
55 | - if($escape) |
|
56 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
57 | - return "<?=" . $this->toPHP() . "?>"; |
|
55 | + if ($escape) |
|
56 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
57 | + return "<?=".$this->toPHP()."?>"; |
|
58 | 58 | } |
59 | 59 | function toPHP() { |
60 | - return $this->filter?$this->filter->toPHP():$this->toPHPVar(); |
|
60 | + return $this->filter ? $this->filter->toPHP() : $this->toPHPVar(); |
|
61 | 61 | } |
62 | 62 | function toPHPVar() { |
63 | 63 | if ($this->sel) { |
64 | 64 | $sel = array(); |
65 | 65 | foreach ($this->sel as $s) |
66 | 66 | $sel[] = "hamleGet('$s')"; |
67 | - return $this->func->toPHP() . "->" . implode('->', $sel); |
|
67 | + return $this->func->toPHP()."->".implode('->', $sel); |
|
68 | 68 | } else |
69 | 69 | return $this->func->toPHP(); |
70 | 70 | } |
@@ -13,6 +13,9 @@ |
||
13 | 13 | protected $s; |
14 | 14 | protected $type; |
15 | 15 | |
16 | + /** |
|
17 | + * @param string $s |
|
18 | + */ |
|
16 | 19 | function __construct($s, $type = self::TOKEN_HTML) { |
17 | 20 | $this->s = str_replace('\\$', "$", $s); |
18 | 21 | $this->type = $type; |
@@ -23,8 +23,9 @@ |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | function toHTML($escape = false) { |
26 | - if ($this->type == self::TOKEN_CODE) |
|
27 | - return $this->s; |
|
26 | + if ($this->type == self::TOKEN_CODE) { |
|
27 | + return $this->s; |
|
28 | + } |
|
28 | 29 | return htmlspecialchars($this->s); |
29 | 30 | } |
30 | 31 | } |
31 | 32 | \ No newline at end of file |
@@ -38,7 +38,9 @@ |
||
38 | 38 | $s = DIRECTORY_SEPARATOR; |
39 | 39 | $class = str_replace("\\",$s,substr($class,14)); |
40 | 40 | $path = __DIR__.$s."hamle".$s."$class.php"; |
41 | - if(is_file($path)) include_once($path); |
|
41 | + if(is_file($path)) { |
|
42 | + include_once($path); |
|
43 | + } |
|
42 | 44 | } |
43 | 45 | },true,true); |
44 | 46 |
@@ -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)); |
|
39 | + $class = str_replace("\\", $s, substr($class, 14)); |
|
40 | 40 | $path = __DIR__.$s."hamle".$s."$class.php"; |
41 | - if(is_file($path)) include_once($path); |
|
41 | + if (is_file($path)) include_once($path); |
|
42 | 42 | } |
43 | -},true,true); |
|
43 | +},true, true); |
|
44 | 44 |
@@ -34,14 +34,18 @@ |
||
34 | 34 | static function filterText($s) { |
35 | 35 | $as = explode("\n", $s); |
36 | 36 | $indent = -1; |
37 | - foreach ($as as $line) |
|
38 | - if (preg_match('/^(\s+).*$/', $line, $m)) { |
|
37 | + foreach ($as as $line) { |
|
38 | + if (preg_match('/^(\s+).*$/', $line, $m)) { |
|
39 | 39 | $lnInd = strlen($m[1]); |
40 | - if ($indent < 0) $indent = $lnInd; |
|
40 | + } |
|
41 | + if ($indent < 0) { |
|
42 | + $indent = $lnInd; |
|
43 | + } |
|
41 | 44 | $indent = min($indent, $lnInd); |
42 | 45 | } |
43 | - foreach ($as as $k => $v) |
|
44 | - $as[$k] = substr($v, $indent); |
|
46 | + foreach ($as as $k => $v) { |
|
47 | + $as[$k] = substr($v, $indent); |
|
48 | + } |
|
45 | 49 | $s = implode("\n", $as); |
46 | 50 | |
47 | 51 | require_once ME_DIR . "/lib/phpsass/SassParser.php"; |
@@ -44,13 +44,13 @@ |
||
44 | 44 | $as[$k] = substr($v, $indent); |
45 | 45 | $s = implode("\n", $as); |
46 | 46 | |
47 | - require_once ME_DIR . "/lib/phpsass/SassParser.php"; |
|
47 | + require_once ME_DIR."/lib/phpsass/SassParser.php"; |
|
48 | 48 | $sp = new SassParser(array("cache" => FALSE, |
49 | 49 | "style" => stdConf::get("me.developer") ? SassRenderer::STYLE_EXPANDED : SassRenderer::STYLE_COMPRESSED, |
50 | 50 | "syntax" => SassFile::SASS, 'debug' => TRUE)); |
51 | 51 | $tree = $sp->toTree($s); |
52 | 52 | $out = $tree->render(); |
53 | 53 | $pad = str_pad("", $indent, " "); |
54 | - return $pad . str_replace("\n", "\n$pad", trim($out)); |
|
54 | + return $pad.str_replace("\n", "\n$pad", trim($out)); |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | \ No newline at end of file |
@@ -53,39 +53,48 @@ discard block |
||
53 | 53 | $pos = 0; |
54 | 54 | $this->nodes = array(); |
55 | 55 | $rFlag = PREG_OFFSET_CAPTURE + PREG_SET_ORDER; |
56 | - if (strlen(trim($s)) == 0) return; |
|
56 | + if (strlen(trim($s)) == 0) { |
|
57 | + return; |
|
58 | + } |
|
57 | 59 | if ($mode == self::TOKEN_CONTROL) { |
58 | 60 | if (preg_match('/^"(.*)"$/', trim($s), $m)) { |
59 | 61 | $this->nodes[] = new Text($m[1]); |
60 | - } else |
|
61 | - $this->nodes[] = new Text\Complex(trim($s)); |
|
62 | + } else { |
|
63 | + $this->nodes[] = new Text\Complex(trim($s)); |
|
64 | + } |
|
62 | 65 | return; |
63 | 66 | } |
64 | 67 | preg_match_all(self::REGEX_HTML, $s, $m, $rFlag); |
65 | 68 | foreach ($m as $match) { |
66 | 69 | if ($mode & self::FIND_BARDOLLAR && isset($match[2])) { |
67 | - if ($match[2][1] != $pos) |
|
68 | - $this->nodes[] = new Text\Plain( |
|
70 | + if ($match[2][1] != $pos) { |
|
71 | + $this->nodes[] = new Text\Plain( |
|
69 | 72 | substr($s, $pos, $match[2][1] - $pos), $mode); |
73 | + } |
|
70 | 74 | $this->nodes[] = new Text\Complex(substr($match[2][0], 1, -1)); |
71 | 75 | $pos = $match[2][1] + strlen($match[2][0]); |
72 | 76 | } elseif ($mode & self::FIND_DOLLARVAR) { |
73 | - if ($match[1][1] > 0 && $s[$match[1][1] - 1] == '\\') continue; |
|
74 | - if ($match[1][1] != $pos) |
|
75 | - $this->nodes[] = new Text\Plain( |
|
77 | + if ($match[1][1] > 0 && $s[$match[1][1] - 1] == '\\') { |
|
78 | + continue; |
|
79 | + } |
|
80 | + if ($match[1][1] != $pos) { |
|
81 | + $this->nodes[] = new Text\Plain( |
|
76 | 82 | substr($s, $pos, $match[1][1] - $pos), $mode); |
83 | + } |
|
77 | 84 | $this->nodes[] = new Text\SimpleVar($match[1][0]); |
78 | 85 | $pos = $match[1][1] + strlen($match[1][0]); |
79 | 86 | } |
80 | 87 | } |
81 | - if ($pos != strlen($s)) |
|
82 | - $this->nodes[] = new Text\Plain(substr($s, $pos), $mode); |
|
88 | + if ($pos != strlen($s)) { |
|
89 | + $this->nodes[] = new Text\Plain(substr($s, $pos), $mode); |
|
90 | + } |
|
83 | 91 | } |
84 | 92 | |
85 | 93 | function toHTML($escape = false) { |
86 | 94 | $out = array(); |
87 | - foreach ($this->nodes as $string) |
|
88 | - $out[] = $string->toHTML($escape); |
|
95 | + foreach ($this->nodes as $string) { |
|
96 | + $out[] = $string->toHTML($escape); |
|
97 | + } |
|
89 | 98 | return implode("", $out); |
90 | 99 | } |
91 | 100 | |
@@ -95,8 +104,9 @@ discard block |
||
95 | 104 | |
96 | 105 | function toPHP() { |
97 | 106 | $out = array(); |
98 | - foreach ($this->nodes as $string) |
|
99 | - $out[] = $string->toPHP(); |
|
107 | + foreach ($this->nodes as $string) { |
|
108 | + $out[] = $string->toPHP(); |
|
109 | + } |
|
100 | 110 | return implode(".", $out); |
101 | 111 | } |
102 | 112 | |
@@ -107,8 +117,9 @@ discard block |
||
107 | 117 | static function varToCode($var) { |
108 | 118 | if (is_array($var)) { |
109 | 119 | $code = array(); |
110 | - foreach ($var as $key => $value) |
|
111 | - $code[] = self::varToCode($key) . "=>" . self::varToCode($value); |
|
120 | + foreach ($var as $key => $value) { |
|
121 | + $code[] = self::varToCode($key) . "=>" . self::varToCode($value); |
|
122 | + } |
|
112 | 123 | return 'array(' . implode(",", $code) . ')'; //remove unnecessary coma |
113 | 124 | } elseif (is_bool($var)) { |
114 | 125 | return ($var ? 'TRUE' : 'FALSE'); |
@@ -101,15 +101,15 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | function doEval() { |
104 | - return eval('return ' . $this->toPHP() . ';'); |
|
104 | + return eval('return '.$this->toPHP().';'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | static function varToCode($var) { |
108 | 108 | if (is_array($var)) { |
109 | 109 | $code = array(); |
110 | 110 | foreach ($var as $key => $value) |
111 | - $code[] = self::varToCode($key) . "=>" . self::varToCode($value); |
|
112 | - return 'array(' . implode(",", $code) . ')'; //remove unnecessary coma |
|
111 | + $code[] = self::varToCode($key)."=>".self::varToCode($value); |
|
112 | + return 'array('.implode(",", $code).')'; //remove unnecessary coma |
|
113 | 113 | } elseif (is_bool($var)) { |
114 | 114 | return ($var ? 'TRUE' : 'FALSE'); |
115 | 115 | } elseif (is_int($var) || is_float($var) || is_numeric($var)) { |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | } elseif ($var instanceof Text) { |
118 | 118 | return $var->toPHP(); |
119 | 119 | } else { |
120 | - return "'" . str_replace(array('$', "'"), array('\\$', "\\'"), $var) . "'"; |
|
120 | + return "'".str_replace(array('$', "'"), array('\\$', "\\'"), $var)."'"; |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 |
@@ -42,17 +42,21 @@ discard block |
||
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 | 48 | $this->source = array(); |
48 | 49 | $this->type = $tag ? $tag : "div"; |
49 | 50 | if($class) { |
50 | - if (isset($this->opt['class'])) |
|
51 | - $this->opt['class'] = array_merge($this->opt['class'], $class); |
|
52 | - else |
|
53 | - $this->opt['class'] = $class; |
|
51 | + if (isset($this->opt['class'])) { |
|
52 | + $this->opt['class'] = array_merge($this->opt['class'], $class); |
|
53 | + } else { |
|
54 | + $this->opt['class'] = $class; |
|
55 | + } |
|
56 | + } |
|
57 | + if($id) { |
|
58 | + $this->opt['id'] = $id; |
|
54 | 59 | } |
55 | - if($id) $this->opt['id'] = $id; |
|
56 | 60 | } |
57 | 61 | |
58 | 62 | function renderStTag() { |
@@ -61,8 +65,9 @@ discard block |
||
61 | 65 | } |
62 | 66 | |
63 | 67 | function renderEnTag() { |
64 | - if (in_array($this->type, self::$selfCloseTags)) |
|
65 | - return ""; |
|
68 | + if (in_array($this->type, self::$selfCloseTags)) { |
|
69 | + return ""; |
|
70 | + } |
|
66 | 71 | return "</{$this->type}>"; |
67 | 72 | } |
68 | 73 | |
@@ -74,10 +79,15 @@ discard block |
||
74 | 79 | function optToTags() { |
75 | 80 | $out = array(); |
76 | 81 | foreach ($this->opt as $k => $v) { |
77 | - if ($k == "class" && !$v) continue; |
|
78 | - if (is_array($v)) $v = implode(" ", $v); |
|
79 | - if (!$v instanceof H\Text) |
|
80 | - $v = new H\Text($v); |
|
82 | + if ($k == "class" && !$v) { |
|
83 | + continue; |
|
84 | + } |
|
85 | + if (is_array($v)) { |
|
86 | + $v = implode(" ", $v); |
|
87 | + } |
|
88 | + if (!$v instanceof H\Text) { |
|
89 | + $v = new H\Text($v); |
|
90 | + } |
|
81 | 91 | $k = new H\Text($k); |
82 | 92 | $out[] = " " . $k->toHTML() . "=\"" . $v->toHTMLAtt() . "\""; |
83 | 93 | } |
@@ -42,22 +42,22 @@ discard block |
||
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() { |
59 | 59 | $close = in_array($this->type, self::$selfCloseTags) ? " />" : ">"; |
60 | - return "<{$this->type}" . $this->optToTags() . $close; |
|
60 | + return "<{$this->type}".$this->optToTags().$close; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | function renderEnTag() { |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | if (!$v instanceof H\Text) |
80 | 80 | $v = new H\Text($v); |
81 | 81 | $k = new H\Text($k); |
82 | - $out[] = " " . $k->toHTML() . "=\"" . $v->toHTMLAtt() . "\""; |
|
82 | + $out[] = " ".$k->toHTML()."=\"".$v->toHTMLAtt()."\""; |
|
83 | 83 | } |
84 | 84 | return implode("", $out); |
85 | 85 | } |
@@ -64,15 +64,18 @@ discard block |
||
64 | 64 | |
65 | 65 | function process() { |
66 | 66 | $clicked = ""; |
67 | - foreach($this->_fields as $f) |
|
68 | - if($f instanceOf Field\Button) |
|
67 | + foreach($this->_fields as $f) { |
|
68 | + if($f instanceOf Field\Button) |
|
69 | 69 | if($f->isClicked()) |
70 | - $clicked = $f; |
|
71 | - foreach($this->_fields as $f) |
|
72 | - $f->doProcess($clicked?true:false); |
|
73 | - if($clicked) |
|
74 | - try { |
|
75 | - $this->onSubmit($clicked); |
|
70 | + $clicked = $f; |
|
71 | + } |
|
72 | + foreach($this->_fields as $f) { |
|
73 | + $f->doProcess($clicked?true:false); |
|
74 | + } |
|
75 | + if($clicked) { |
|
76 | + try { |
|
77 | + $this->onSubmit($clicked); |
|
78 | + } |
|
76 | 79 | } catch(Exception\FormInvalid $e) { |
77 | 80 | $this->hint = $e->getMessage(); |
78 | 81 | } |
@@ -80,8 +83,9 @@ discard block |
||
80 | 83 | |
81 | 84 | function isValid() { |
82 | 85 | $valid = true; |
83 | - foreach($this->_fields as $f) |
|
84 | - $valid = $f->valid && $valid; |
|
86 | + foreach($this->_fields as $f) { |
|
87 | + $valid = $f->valid && $valid; |
|
88 | + } |
|
85 | 89 | return $valid; |
86 | 90 | } |
87 | 91 | /** |
@@ -95,8 +99,9 @@ discard block |
||
95 | 99 | return $this->_fields; |
96 | 100 | } |
97 | 101 | function getField($n) { |
98 | - if(!isset($this->_fields[$n])) |
|
99 | - throw new Exception\NoKey("unable to find form field ($n)"); |
|
102 | + if(!isset($this->_fields[$n])) { |
|
103 | + throw new Exception\NoKey("unable to find form field ($n)"); |
|
104 | + } |
|
100 | 105 | return $this->_fields[$n]; |
101 | 106 | } |
102 | 107 | function __get($n) { |
@@ -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 |
@@ -34,16 +34,18 @@ |
||
34 | 34 | function __construct($s) { |
35 | 35 | $m = array(); |
36 | 36 | //var_dump($s); |
37 | - if (!preg_match('/\$\[(-?[0-9]+|[a-zA-Z][a-zA-Z0-9]+)\]/', $s, $m)) |
|
38 | - throw new ParseError("Unable to match scope ($s)"); |
|
37 | + if (!preg_match('/\$\[(-?[0-9]+|[a-zA-Z][a-zA-Z0-9]+)\]/', $s, $m)) { |
|
38 | + throw new ParseError("Unable to match scope ($s)"); |
|
39 | + } |
|
39 | 40 | $this->scope = $m[1]; |
40 | 41 | } |
41 | 42 | |
42 | 43 | function toPHP() { |
43 | - if (is_numeric($this->scope)) |
|
44 | - return "Hamle\\Scope::get(" . Text::varToCode($this->scope) . ")"; |
|
45 | - else |
|
46 | - return "Hamle\\Scope::getName(" . Text::varToCode($this->scope) . ")"; |
|
44 | + if (is_numeric($this->scope)) { |
|
45 | + return "Hamle\\Scope::get(" . Text::varToCode($this->scope) . ")"; |
|
46 | + } else { |
|
47 | + return "Hamle\\Scope::getName(" . Text::varToCode($this->scope) . ")"; |
|
48 | + } |
|
47 | 49 | } |
48 | 50 | |
49 | 51 | function toHTML($escape = false) { |
@@ -41,9 +41,9 @@ |
||
41 | 41 | |
42 | 42 | function toPHP() { |
43 | 43 | if (is_numeric($this->scope)) |
44 | - return "Hamle\\Scope::get(" . Text::varToCode($this->scope) . ")"; |
|
44 | + return "Hamle\\Scope::get(".Text::varToCode($this->scope).")"; |
|
45 | 45 | else |
46 | - return "Hamle\\Scope::getName(" . Text::varToCode($this->scope) . ")"; |
|
46 | + return "Hamle\\Scope::getName(".Text::varToCode($this->scope).")"; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | function toHTML($escape = false) { |