@@ -33,11 +33,17 @@ |
||
33 | 33 | class Text extends Tag { |
34 | 34 | protected $escape = true; |
35 | 35 | |
36 | + /** |
|
37 | + * @param string $tag |
|
38 | + */ |
|
36 | 39 | function __construct($tag) { |
37 | 40 | parent::__construct(); |
38 | 41 | $this->escape = ($tag == "_"); |
39 | 42 | } |
40 | 43 | |
44 | + /** |
|
45 | + * @param string $s |
|
46 | + */ |
|
41 | 47 | function addContent($s, $strtype = H\Text::TOKEN_HTML) { |
42 | 48 | if (trim($s)) { |
43 | 49 | if ($this->escape) { |
@@ -43,8 +43,9 @@ |
||
43 | 43 | if ($this->escape) { |
44 | 44 | $parse = new H\Text($s, $strtype); |
45 | 45 | $this->content[] = $parse->toHTML(); |
46 | - } else |
|
47 | - $this->content[] = $s; |
|
46 | + } else { |
|
47 | + $this->content[] = $s; |
|
48 | + } |
|
48 | 49 | } |
49 | 50 | } |
50 | 51 |
@@ -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; |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: Chris |
|
5 | - * Date: 4/12/2014 |
|
6 | - * Time: 12:04 PM |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: Chris |
|
5 | + * Date: 4/12/2014 |
|
6 | + * Time: 12:04 PM |
|
7 | + */ |
|
8 | 8 | namespace Seufert\Hamle\Text; |
9 | 9 | |
10 | 10 | use Seufert\Hamle\Text; |
@@ -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 |
@@ -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 |
@@ -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,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"; |
@@ -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'); |
@@ -97,8 +97,8 @@ |
||
97 | 97 | break; |
98 | 98 | case "include": |
99 | 99 | $file = $hsv->toHTML(); |
100 | - if($file[0] == "#") |
|
101 | - $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
100 | + if ($file[0] == "#") |
|
101 | + $out .= "echo Hamle\\Run::includeFragment(" . $hsv->toPHP() . ");"; |
|
102 | 102 | else |
103 | 103 | $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
104 | 104 | break; |
@@ -53,10 +53,12 @@ discard block |
||
53 | 53 | if ($parentTag) { |
54 | 54 | $elseTag = $parentTag->tags[count($parentTag->tags) - 1]; |
55 | 55 | if ($this->type == "else") { |
56 | - if (!$elseTag instanceOf H\Tag) |
|
57 | - throw new ParseError("Unable to use else here"); |
|
58 | - if (!in_array($elseTag->type, array('with', 'if'))) |
|
59 | - throw new ParseError("You can only use else with |with and |if, you tried |{$parentTag->type}"); |
|
56 | + if (!$elseTag instanceOf H\Tag) { |
|
57 | + throw new ParseError("Unable to use else here"); |
|
58 | + } |
|
59 | + if (!in_array($elseTag->type, array('with', 'if'))) { |
|
60 | + throw new ParseError("You can only use else with |with and |if, you tried |{$parentTag->type}"); |
|
61 | + } |
|
60 | 62 | $elseTag->else = true; |
61 | 63 | } |
62 | 64 | } |
@@ -69,14 +71,16 @@ discard block |
||
69 | 71 | $scopeName = $m[1]; |
70 | 72 | $lookup = substr($this->var, 0, strlen($this->var) - strlen($m[0])); |
71 | 73 | $hsv = new H\Text(trim($lookup), H\Text::TOKEN_CONTROL); |
72 | - } else |
|
73 | - $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL); |
|
74 | + } else { |
|
75 | + $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL); |
|
76 | + } |
|
74 | 77 | switch ($this->type) { |
75 | 78 | case "each": |
76 | - if ($this->var) |
|
77 | - $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
78 | - else |
|
79 | - $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
|
79 | + if ($this->var) { |
|
80 | + $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
81 | + } else { |
|
82 | + $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
|
83 | + } |
|
80 | 84 | $out .= "Hamle\\Scope::add({$this->o}); "; |
81 | 85 | break; |
82 | 86 | case "if": |
@@ -84,9 +88,9 @@ discard block |
||
84 | 88 | $out .= "if(" . $hsvcomp->toPHP() . ") {"; |
85 | 89 | break; |
86 | 90 | case "with": |
87 | - if ($scopeName) |
|
88 | - $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
89 | - else { |
|
91 | + if ($scopeName) { |
|
92 | + $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
93 | + } else { |
|
90 | 94 | $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " . |
91 | 95 | "{$this->o}->valid()) {\n"; |
92 | 96 | $out .= "Hamle\\Scope::add({$this->o});\n;"; |
@@ -97,10 +101,11 @@ discard block |
||
97 | 101 | break; |
98 | 102 | case "include": |
99 | 103 | $file = $hsv->toHTML(); |
100 | - if($file[0] == "#") |
|
101 | - $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
102 | - else |
|
103 | - $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
104 | + if($file[0] == "#") { |
|
105 | + $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
106 | + } else { |
|
107 | + $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
108 | + } |
|
104 | 109 | break; |
105 | 110 | } |
106 | 111 | return $out . ' ?>'; |
@@ -119,8 +124,9 @@ discard block |
||
119 | 124 | case "each"; |
120 | 125 | $out .= 'Hamle\\Scope::done(); '; |
121 | 126 | $out .= '}'; |
122 | - if (!$this->var) |
|
123 | - $out .= "Hamle\\Scope::get()->rewind();\n"; |
|
127 | + if (!$this->var) { |
|
128 | + $out .= "Hamle\\Scope::get()->rewind();\n"; |
|
129 | + } |
|
124 | 130 | break; |
125 | 131 | case "if": |
126 | 132 | case "else": |
@@ -136,7 +142,9 @@ discard block |
||
136 | 142 | return ""; |
137 | 143 | break; |
138 | 144 | } |
139 | - if ($this->else) $out .= "else{"; |
|
145 | + if ($this->else) { |
|
146 | + $out .= "else{"; |
|
147 | + } |
|
140 | 148 | return $out . ' ?>'; |
141 | 149 | } |
142 | 150 |
@@ -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() { |
@@ -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 | } |
@@ -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 |
@@ -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) { |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | } |
82 | 82 | $rand = false; |
83 | 83 | if (preg_match_all('/\\^(-?)([a-zA-Z0-9\_]*)/', $s, $m)) { |
84 | - foreach($m[0] as $k=>$mv) |
|
84 | + foreach ($m[0] as $k=>$mv) |
|
85 | 85 | if ($m[2][$k]) { |
86 | - $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING; |
|
86 | + $dir = $m[1][$k] == "-" ? Hamle\Hamle::SORT_DESCENDING : Hamle\Hamle::SORT_ASCENDING; |
|
87 | 87 | $att['sort'][$m[2][$k]] = $dir; |
88 | 88 | } else $rand = true; |
89 | 89 | } |
90 | - if($rand) |
|
90 | + if ($rand) |
|
91 | 91 | $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
92 | 92 | return $att; |
93 | 93 | } |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | $this->sortlimit['limit'] . "," . $this->sortlimit['offset']; |
107 | 107 | $sub = $this->sub ? "->" . $this->sub->toPHP() : ""; |
108 | 108 | if ($this->scope) { |
109 | - if($this->scope === true) |
|
109 | + if ($this->scope === true) |
|
110 | 110 | return "Hamle\\Scope::get(0)$sub"; |
111 | - return $this->scope->toPHP().$sub; |
|
111 | + return $this->scope->toPHP() . $sub; |
|
112 | 112 | } |
113 | 113 | if (count($this->filt['tag'])) |
114 | 114 | return "Hamle\\Run::modelTypeTags(" . |
@@ -38,10 +38,12 @@ discard block |
||
38 | 38 | |
39 | 39 | function __construct($s) { |
40 | 40 | $m = array(); |
41 | - if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) |
|
42 | - throw new ParseError("Unable to read \$ func in '$s'"); |
|
43 | - if (trim($m[2])) |
|
44 | - $this->sub = new FuncSub($m[2]); |
|
41 | + if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) { |
|
42 | + throw new ParseError("Unable to read \$ func in '$s'"); |
|
43 | + } |
|
44 | + if (trim($m[2])) { |
|
45 | + $this->sub = new FuncSub($m[2]); |
|
46 | + } |
|
45 | 47 | if (!trim($m[1])) { |
46 | 48 | $this->scope = true; |
47 | 49 | return; |
@@ -58,17 +60,24 @@ discard block |
||
58 | 60 | $m = array(); |
59 | 61 | $att = array('id' => array(), 'tag' => array()); |
60 | 62 | foreach (explode(",", $s) as $str) { |
61 | - if (preg_match('/^[a-zA-Z0-9\\_]+/', $str, $m)) $type = $m[0]; |
|
62 | - else $type = "*"; |
|
63 | - if (preg_match('/#([a-zA-Z0-9\_\\${}]+)/', $str, $m)) $att['id'][$type][] = $m[1]; |
|
64 | - elseif (preg_match_all('/\\.([a-zA-Z0-9\_\-\\${}]+)/', $str, $m)) |
|
65 | - foreach ($m[1] as $tag) |
|
63 | + if (preg_match('/^[a-zA-Z0-9\\_]+/', $str, $m)) { |
|
64 | + $type = $m[0]; |
|
65 | + } else { |
|
66 | + $type = "*"; |
|
67 | + } |
|
68 | + if (preg_match('/#([a-zA-Z0-9\_\\${}]+)/', $str, $m)) { |
|
69 | + $att['id'][$type][] = $m[1]; |
|
70 | + } elseif (preg_match_all('/\\.([a-zA-Z0-9\_\-\\${}]+)/', $str, $m)) { |
|
71 | + foreach ($m[1] as $tag) |
|
66 | 72 | $att['tag'][$type][] = new Text($tag, Text::TOKEN_CODE); |
67 | - else $att['tag'][$type] = array(); |
|
73 | + } else { |
|
74 | + $att['tag'][$type] = array(); |
|
75 | + } |
|
68 | 76 | } |
69 | 77 | //var_dump($att); |
70 | - if (!(count($att['id']) xor count($att['tag']))) |
|
71 | - throw new ParseError("Only tag, type or id can be combined"); |
|
78 | + if (!(count($att['id']) xor count($att['tag']))) { |
|
79 | + throw new ParseError("Only tag, type or id can be combined"); |
|
80 | + } |
|
72 | 81 | return $att; |
73 | 82 | } |
74 | 83 | |
@@ -81,14 +90,18 @@ discard block |
||
81 | 90 | } |
82 | 91 | $rand = false; |
83 | 92 | if (preg_match_all('/\\^(-?)([a-zA-Z0-9\_]*)/', $s, $m)) { |
84 | - foreach($m[0] as $k=>$mv) |
|
85 | - if ($m[2][$k]) { |
|
93 | + foreach($m[0] as $k=>$mv) { |
|
94 | + if ($m[2][$k]) { |
|
86 | 95 | $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING; |
96 | + } |
|
87 | 97 | $att['sort'][$m[2][$k]] = $dir; |
88 | - } else $rand = true; |
|
98 | + } else { |
|
99 | + $rand = true; |
|
100 | + } |
|
101 | + } |
|
102 | + if($rand) { |
|
103 | + $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
|
89 | 104 | } |
90 | - if($rand) |
|
91 | - $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
|
92 | 105 | return $att; |
93 | 106 | } |
94 | 107 | |
@@ -106,21 +119,24 @@ discard block |
||
106 | 119 | $this->sortlimit['limit'] . "," . $this->sortlimit['offset']; |
107 | 120 | $sub = $this->sub ? "->" . $this->sub->toPHP() : ""; |
108 | 121 | if ($this->scope) { |
109 | - if($this->scope === true) |
|
110 | - return "Hamle\\Scope::get(0)$sub"; |
|
122 | + if($this->scope === true) { |
|
123 | + return "Hamle\\Scope::get(0)$sub"; |
|
124 | + } |
|
111 | 125 | return $this->scope->toPHP().$sub; |
112 | 126 | } |
113 | - if (count($this->filt['tag'])) |
|
114 | - return "Hamle\\Run::modelTypeTags(" . |
|
127 | + if (count($this->filt['tag'])) { |
|
128 | + return "Hamle\\Run::modelTypeTags(" . |
|
115 | 129 | Text::varToCode($this->filt['tag']) . ",$limit)$sub"; |
116 | - if (count($this->filt['id'])) |
|
117 | - if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) |
|
130 | + } |
|
131 | + if (count($this->filt['id'])) { |
|
132 | + if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) |
|
118 | 133 | return "Hamle\\Run::modelId(" . |
119 | 134 | Text::varToCode(current($this->filt['id']['*'])) . |
120 | 135 | ",$limit)$sub"; |
121 | - else |
|
122 | - return "Hamle\\Run::modelTypeId(" . |
|
136 | + } else { |
|
137 | + return "Hamle\\Run::modelTypeId(" . |
|
123 | 138 | Text::varToCode($this->filt['id']) . ",$limit)$sub"; |
139 | + } |
|
124 | 140 | return ""; |
125 | 141 | } |
126 | 142 |