@@ -25,8 +25,6 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | namespace Seufert\Hamle\Text; |
| 27 | 27 | |
| 28 | -use http\Exception\RuntimeException; |
|
| 29 | -use Seufert\Hamle\Run; |
|
| 30 | 28 | use Seufert\Hamle\Text; |
| 31 | 29 | use Seufert\Hamle\Exception\ParseError; |
| 32 | 30 | use Seufert\Hamle\WriteModel; |
@@ -43,20 +43,24 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | $s = preg_split("/-[>!]/", $s); |
| 45 | 45 | // if(count($s) == 1) $s = explode("-!",$s[0]); |
| 46 | - if (!$s[0]) throw new ParseError("Unable to parse Complex Expression"); |
|
| 47 | - if ($s[0][1] == "(") |
|
| 48 | - $this->func = new Text\Func($s[0]); |
|
| 49 | - elseif ($s[0][1] == "[") |
|
| 50 | - $this->func = new Text\Scope($s[0]); |
|
| 51 | - else |
|
| 52 | - $this->func = new SimpleVar($s[0]); |
|
| 46 | + if (!$s[0]) { |
|
| 47 | + throw new ParseError("Unable to parse Complex Expression"); |
|
| 48 | + } |
|
| 49 | + if ($s[0][1] == "(") { |
|
| 50 | + $this->func = new Text\Func($s[0]); |
|
| 51 | + } elseif ($s[0][1] == "[") { |
|
| 52 | + $this->func = new Text\Scope($s[0]); |
|
| 53 | + } else { |
|
| 54 | + $this->func = new SimpleVar($s[0]); |
|
| 55 | + } |
|
| 53 | 56 | array_shift($s); |
| 54 | 57 | $this->sel = $s; |
| 55 | 58 | } |
| 56 | 59 | |
| 57 | 60 | function toHTML($escape = false) { |
| 58 | - if($escape) |
|
| 59 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 61 | + if($escape) { |
|
| 62 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 63 | + } |
|
| 60 | 64 | return "<?=" . $this->toPHP() . "?>"; |
| 61 | 65 | } |
| 62 | 66 | function toPHP() { |
@@ -65,11 +69,13 @@ discard block |
||
| 65 | 69 | function toPHPVar() { |
| 66 | 70 | if ($this->sel) { |
| 67 | 71 | $sel = array(); |
| 68 | - foreach ($this->sel as $s) |
|
| 69 | - $sel[] = "hamleGet('$s')"; |
|
| 72 | + foreach ($this->sel as $s) { |
|
| 73 | + $sel[] = "hamleGet('$s')"; |
|
| 74 | + } |
|
| 70 | 75 | return $this->func->toPHP() . "->" . implode('->', $sel); |
| 71 | - } else |
|
| 72 | - return $this->func->toPHP(); |
|
| 76 | + } else { |
|
| 77 | + return $this->func->toPHP(); |
|
| 78 | + } |
|
| 73 | 79 | } |
| 74 | 80 | |
| 75 | 81 | /** |
@@ -43,8 +43,9 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | function toHTML($escape = false) { |
| 46 | - if($escape) |
|
| 47 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 46 | + if($escape) { |
|
| 47 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 48 | + } |
|
| 48 | 49 | return "<?=" . $this->toPHP() . "?>"; |
| 49 | 50 | } |
| 50 | 51 | |
@@ -62,8 +63,9 @@ discard block |
||
| 62 | 63 | */ |
| 63 | 64 | function setValue($value) { |
| 64 | 65 | $model = \Seufert\Hamle\Scope::get(); |
| 65 | - if(!$model instanceof WriteModel) |
|
| 66 | - throw new \RuntimeException('Can only write to model that implements WriteModel'); |
|
| 66 | + if(!$model instanceof WriteModel) { |
|
| 67 | + throw new \RuntimeException('Can only write to model that implements WriteModel'); |
|
| 68 | + } |
|
| 67 | 69 | $model->hamleSet($this->var, $value); |
| 68 | 70 | return $model; |
| 69 | 71 | } |