@@ -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); |
@@ -27,7 +27,6 @@ |
||
27 | 27 | |
28 | 28 | use http\Exception\RuntimeException; |
29 | 29 | use Seufert\Hamle\Model; |
30 | -use Seufert\Hamle\Run; |
|
31 | 30 | use Seufert\Hamle\Text; |
32 | 31 | use Seufert\Hamle\Exception\ParseError; |
33 | 32 | use Seufert\Hamle\WriteModel; |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | protected $filter; |
39 | 39 | |
40 | 40 | function __construct($s) { |
41 | - if(FALSE !== $pos = strpos($s,'|')) { |
|
42 | - $this->filter = new Filter(substr($s, $pos+1), $this); |
|
43 | - $s = substr($s,0,$pos); |
|
41 | + if (FALSE !== $pos = strpos($s, '|')) { |
|
42 | + $this->filter = new Filter(substr($s, $pos + 1), $this); |
|
43 | + $s = substr($s, 0, $pos); |
|
44 | 44 | } |
45 | 45 | $s = preg_split("/-[>!]/", $s); |
46 | 46 | // if(count($s) == 1) $s = explode("-!",$s[0]); |
@@ -56,27 +56,27 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | function toHTML($escape = false) { |
59 | - if($escape) |
|
60 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
61 | - return "<?=" . $this->toPHP() . "?>"; |
|
59 | + if ($escape) |
|
60 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
61 | + return "<?=".$this->toPHP()."?>"; |
|
62 | 62 | } |
63 | 63 | function toPHP() { |
64 | - return $this->filter?$this->filter->toPHP():$this->toPHPVar(); |
|
64 | + return $this->filter ? $this->filter->toPHP() : $this->toPHPVar(); |
|
65 | 65 | } |
66 | 66 | function toPHPVar() { |
67 | 67 | if ($this->sel) { |
68 | 68 | $sel = array(); |
69 | 69 | foreach ($this->sel as $s) |
70 | 70 | $sel[] = "hamleGet('$s')"; |
71 | - return $this->func->toPHP() . "->" . implode('->', $sel); |
|
71 | + return $this->func->toPHP()."->".implode('->', $sel); |
|
72 | 72 | } else |
73 | 73 | return $this->func->toPHP(); |
74 | 74 | } |
75 | 75 | |
76 | 76 | function getOrCreateModel(Model $parent = null) { |
77 | - if($this->func instanceof Text\Scope) |
|
77 | + if ($this->func instanceof Text\Scope) |
|
78 | 78 | return $this->func->getOrCreateModel($parent); |
79 | - if($this->func instanceof Text\Func) |
|
79 | + if ($this->func instanceof Text\Func) |
|
80 | 80 | return $this->func->getOrCreateModel($parent); |
81 | 81 | } |
82 | 82 | |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | * @return WriteModel |
86 | 86 | */ |
87 | 87 | function setValue($value) { |
88 | - if(!$this->sel || count($this->sel) != 1) |
|
88 | + if (!$this->sel || count($this->sel) != 1) |
|
89 | 89 | throw new \RuntimeException('Can only set values, when one var name is present'); |
90 | 90 | $model = $this->getOrCreateModel(); |
91 | - if(!$model instanceof WriteModel) |
|
91 | + if (!$model instanceof WriteModel) |
|
92 | 92 | throw new \RuntimeException('Can only set values on Runtime Exceptions'); |
93 | 93 | $model->hamleSet($this->sel[0], $value); |
94 | 94 | return $model; |
@@ -44,20 +44,24 @@ discard block |
||
44 | 44 | } |
45 | 45 | $s = preg_split("/-[>!]/", $s); |
46 | 46 | // if(count($s) == 1) $s = explode("-!",$s[0]); |
47 | - if (!$s[0]) throw new ParseError("Unable to parse Complex Expression"); |
|
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]); |
|
47 | + if (!$s[0]) { |
|
48 | + throw new ParseError("Unable to parse Complex Expression"); |
|
49 | + } |
|
50 | + if ($s[0][1] == "(") { |
|
51 | + $this->func = new Text\Func($s[0]); |
|
52 | + } elseif ($s[0][1] == "[") { |
|
53 | + $this->func = new Text\Scope($s[0]); |
|
54 | + } else { |
|
55 | + $this->func = new SimpleVar($s[0]); |
|
56 | + } |
|
54 | 57 | array_shift($s); |
55 | 58 | $this->sel = $s; |
56 | 59 | } |
57 | 60 | |
58 | 61 | function toHTML($escape = false) { |
59 | - if($escape) |
|
60 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
62 | + if($escape) { |
|
63 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
64 | + } |
|
61 | 65 | return "<?=" . $this->toPHP() . "?>"; |
62 | 66 | } |
63 | 67 | function toPHP() { |
@@ -66,18 +70,22 @@ discard block |
||
66 | 70 | function toPHPVar() { |
67 | 71 | if ($this->sel) { |
68 | 72 | $sel = array(); |
69 | - foreach ($this->sel as $s) |
|
70 | - $sel[] = "hamleGet('$s')"; |
|
73 | + foreach ($this->sel as $s) { |
|
74 | + $sel[] = "hamleGet('$s')"; |
|
75 | + } |
|
71 | 76 | return $this->func->toPHP() . "->" . implode('->', $sel); |
72 | - } else |
|
73 | - return $this->func->toPHP(); |
|
77 | + } else { |
|
78 | + return $this->func->toPHP(); |
|
79 | + } |
|
74 | 80 | } |
75 | 81 | |
76 | 82 | function getOrCreateModel(Model $parent = null) { |
77 | - if($this->func instanceof Text\Scope) |
|
78 | - return $this->func->getOrCreateModel($parent); |
|
79 | - if($this->func instanceof Text\Func) |
|
80 | - return $this->func->getOrCreateModel($parent); |
|
83 | + if($this->func instanceof Text\Scope) { |
|
84 | + return $this->func->getOrCreateModel($parent); |
|
85 | + } |
|
86 | + if($this->func instanceof Text\Func) { |
|
87 | + return $this->func->getOrCreateModel($parent); |
|
88 | + } |
|
81 | 89 | } |
82 | 90 | |
83 | 91 | /** |
@@ -85,11 +93,13 @@ discard block |
||
85 | 93 | * @return WriteModel |
86 | 94 | */ |
87 | 95 | function setValue($value) { |
88 | - if(!$this->sel || count($this->sel) != 1) |
|
89 | - throw new \RuntimeException('Can only set values, when one var name is present'); |
|
96 | + if(!$this->sel || count($this->sel) != 1) { |
|
97 | + throw new \RuntimeException('Can only set values, when one var name is present'); |
|
98 | + } |
|
90 | 99 | $model = $this->getOrCreateModel(); |
91 | - if(!$model instanceof WriteModel) |
|
92 | - throw new \RuntimeException('Can only set values on Runtime Exceptions'); |
|
100 | + if(!$model instanceof WriteModel) { |
|
101 | + throw new \RuntimeException('Can only set values on Runtime Exceptions'); |
|
102 | + } |
|
93 | 103 | $model->hamleSet($this->sel[0], $value); |
94 | 104 | return $model; |
95 | 105 | } |
@@ -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('use Seufert\Hamle; return ' . $this->toPHP() . ';'); |
|
104 | + return eval('use Seufert\Hamle; 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 |
@@ -31,7 +31,8 @@ |
||
31 | 31 | function __construct($s) { |
32 | 32 | $s = explode("->", $s, 2); |
33 | 33 | $this->key = $s[0]; |
34 | - if (count($s) > 1) |
|
35 | - $this->sel = $s[1]; |
|
34 | + if (count($s) > 1) { |
|
35 | + $this->sel = $s[1]; |
|
36 | + } |
|
36 | 37 | } |
37 | 38 | } |
38 | 39 | \ No newline at end of file |
@@ -76,9 +76,10 @@ discard block |
||
76 | 76 | } |
77 | 77 | array_shift($path); |
78 | 78 | } |
79 | - foreach ($this->tags as $tag) |
|
80 | - if ($found = $tag->find($path)) |
|
81 | - $list = array_merge($list, $found); |
|
79 | + foreach ($this->tags as $tag) { |
|
80 | + if ($found = $tag->find($path)) |
|
81 | + $list = array_merge($list, $found); |
|
82 | + } |
|
82 | 83 | return $list; |
83 | 84 | } |
84 | 85 | |
@@ -90,7 +91,9 @@ discard block |
||
90 | 91 | */ |
91 | 92 | function replace($path, Tag $newTag) { |
92 | 93 | if ($this->compare($path[0])) { |
93 | - if (count($path) == 1) return $newTag; |
|
94 | + if (count($path) == 1) { |
|
95 | + return $newTag; |
|
96 | + } |
|
94 | 97 | array_shift($path); |
95 | 98 | } |
96 | 99 | foreach ($this->tags as $k => $tag) { |
@@ -103,21 +106,25 @@ discard block |
||
103 | 106 | } |
104 | 107 | |
105 | 108 | function addSnipContent($contentTag, &$tagArray = array(), $key = 0) { |
106 | - foreach ($this->tags as $k => $tag) |
|
107 | - $tag->addSnipContent($contentTag, $this->tags, $k); |
|
109 | + foreach ($this->tags as $k => $tag) { |
|
110 | + $tag->addSnipContent($contentTag, $this->tags, $k); |
|
111 | + } |
|
108 | 112 | } |
109 | 113 | |
110 | 114 | function compare($tic) { |
111 | - if (isset($tic['type']) && $this->type != $tic['type']) |
|
112 | - return false; |
|
115 | + if (isset($tic['type']) && $this->type != $tic['type']) { |
|
116 | + return false; |
|
117 | + } |
|
113 | 118 | if (isset($tic['id']) && |
114 | 119 | !(isset($this->opt['id']) && $tic['id'] == $this->opt['id']) |
115 | - ) |
|
116 | - return false; |
|
120 | + ) { |
|
121 | + return false; |
|
122 | + } |
|
117 | 123 | if (isset($tic['class']) && !(isset($this->opt['class']) |
118 | 124 | && !array_diff($tic['class'], $this->opt['class'])) |
119 | - ) |
|
120 | - return false; |
|
125 | + ) { |
|
126 | + return false; |
|
127 | + } |
|
121 | 128 | return true; |
122 | 129 | } |
123 | 130 | |
@@ -127,10 +134,11 @@ discard block |
||
127 | 134 | * @param string $mode Mode to add child [append|prepend] |
128 | 135 | */ |
129 | 136 | function addChild(Tag $tag, $mode = "append") { |
130 | - if ($mode == "prepend") |
|
131 | - array_unshift($this->tags, $tag); |
|
132 | - else |
|
133 | - $this->tags[] = $tag; |
|
137 | + if ($mode == "prepend") { |
|
138 | + array_unshift($this->tags, $tag); |
|
139 | + } else { |
|
140 | + $this->tags[] = $tag; |
|
141 | + } |
|
134 | 142 | } |
135 | 143 | |
136 | 144 | /** |
@@ -145,9 +153,12 @@ discard block |
||
145 | 153 | $ind = $doIndent ? str_pad("", $indent, " ") : ""; |
146 | 154 | $oneliner = ((count($this->content) > 1 || $this->tags) ? false : true); |
147 | 155 | $out = $ind . $this->renderStTag() . ($oneliner ? "" : "\n"); |
148 | - if ($this->content) $out .= $this->renderContent($ind, $oneliner); |
|
149 | - foreach ($this->tags as $tag) |
|
150 | - $out .= $tag->render($indent + self::INDENT_SIZE); |
|
156 | + if ($this->content) { |
|
157 | + $out .= $this->renderContent($ind, $oneliner); |
|
158 | + } |
|
159 | + foreach ($this->tags as $tag) { |
|
160 | + $out .= $tag->render($indent + self::INDENT_SIZE); |
|
161 | + } |
|
151 | 162 | $out .= ($oneliner ? "" : $ind) . $this->renderEnTag() . "\n"; |
152 | 163 | return $out; |
153 | 164 | } |
@@ -161,8 +172,9 @@ discard block |
||
161 | 172 | */ |
162 | 173 | function renderContent($pad = "", $oneliner = false) { |
163 | 174 | $out = ""; |
164 | - foreach ($this->content as $c) |
|
165 | - $out .= ($oneliner ? "" : $pad) . $c . ($oneliner ? "" : "\n"); |
|
175 | + foreach ($this->content as $c) { |
|
176 | + $out .= ($oneliner ? "" : $pad) . $c . ($oneliner ? "" : "\n"); |
|
177 | + } |
|
166 | 178 | return $out; |
167 | 179 | } |
168 | 180 |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | //if(strtoupper($this->type) == "A") var_dump($this); |
145 | 145 | $ind = $doIndent ? str_pad("", $indent, " ") : ""; |
146 | 146 | $oneliner = ((count($this->content) > 1 || $this->tags) ? false : true); |
147 | - $out = $ind . $this->renderStTag() . ($oneliner ? "" : "\n"); |
|
147 | + $out = $ind.$this->renderStTag().($oneliner ? "" : "\n"); |
|
148 | 148 | if ($this->content) $out .= $this->renderContent($ind, $oneliner); |
149 | 149 | foreach ($this->tags as $tag) |
150 | 150 | $out .= $tag->render($indent + self::INDENT_SIZE); |
151 | - $out .= ($oneliner ? "" : $ind) . $this->renderEnTag() . "\n"; |
|
151 | + $out .= ($oneliner ? "" : $ind).$this->renderEnTag()."\n"; |
|
152 | 152 | return $out; |
153 | 153 | } |
154 | 154 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | function renderContent($pad = "", $oneliner = false) { |
163 | 163 | $out = ""; |
164 | 164 | foreach ($this->content as $c) |
165 | - $out .= ($oneliner ? "" : $pad) . $c . ($oneliner ? "" : "\n"); |
|
165 | + $out .= ($oneliner ? "" : $pad).$c.($oneliner ? "" : "\n"); |
|
166 | 166 | return $out; |
167 | 167 | } |
168 | 168 |