@@ -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; |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | protected $filter; |
38 | 38 | |
39 | 39 | function __construct($s) { |
40 | - if(FALSE !== $pos = strpos($s,'|')) { |
|
41 | - $this->filter = new Filter(substr($s, $pos+1), $this); |
|
42 | - $s = substr($s,0,$pos); |
|
40 | + if (FALSE !== $pos = strpos($s, '|')) { |
|
41 | + $this->filter = new Filter(substr($s, $pos + 1), $this); |
|
42 | + $s = substr($s, 0, $pos); |
|
43 | 43 | } |
44 | 44 | $s = preg_split("/-[>!]/", $s); |
45 | 45 | // if(count($s) == 1) $s = explode("-!",$s[0]); |
@@ -55,19 +55,19 @@ discard block |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | function toHTML($escape = false) { |
58 | - if($escape) |
|
59 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
60 | - return "<?=" . $this->toPHP() . "?>"; |
|
58 | + if ($escape) |
|
59 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
60 | + return "<?=".$this->toPHP()."?>"; |
|
61 | 61 | } |
62 | 62 | function toPHP() { |
63 | - return $this->filter?$this->filter->toPHP():$this->toPHPVar(); |
|
63 | + return $this->filter ? $this->filter->toPHP() : $this->toPHPVar(); |
|
64 | 64 | } |
65 | 65 | function toPHPVar() { |
66 | 66 | if ($this->sel) { |
67 | 67 | $sel = array(); |
68 | 68 | foreach ($this->sel as $s) |
69 | 69 | $sel[] = "hamleGet('$s')"; |
70 | - return $this->func->toPHP() . "->" . implode('->', $sel); |
|
70 | + return $this->func->toPHP()."->".implode('->', $sel); |
|
71 | 71 | } else |
72 | 72 | return $this->func->toPHP(); |
73 | 73 | } |
@@ -34,26 +34,26 @@ discard block |
||
34 | 34 | protected $filter; |
35 | 35 | |
36 | 36 | function __construct($s) { |
37 | - if(FALSE !== $pos = strpos($s,'|')) { |
|
38 | - $this->var = substr($s,1,$pos-1); |
|
39 | - $this->filter = new Filter(substr($s, $pos+1), $this); |
|
37 | + if (FALSE !== $pos = strpos($s, '|')) { |
|
38 | + $this->var = substr($s, 1, $pos - 1); |
|
39 | + $this->filter = new Filter(substr($s, $pos + 1), $this); |
|
40 | 40 | } else { |
41 | 41 | $this->var = substr($s, 1); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | 45 | function toHTML($escape = false) { |
46 | - if($escape) |
|
47 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
48 | - return "<?=" . $this->toPHP() . "?>"; |
|
46 | + if ($escape) |
|
47 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
48 | + return "<?=".$this->toPHP()."?>"; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | function toPHP() { |
52 | - return $this->filter?$this->filter->toPHP():$this->toPHPVar(); |
|
52 | + return $this->filter ? $this->filter->toPHP() : $this->toPHPVar(); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | function toPHPVar() { |
56 | - return "Hamle\\Scope::get()->hamleGet(" . Text::varToCode($this->var) . ")"; |
|
56 | + return "Hamle\\Scope::get()->hamleGet(".Text::varToCode($this->var).")"; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | function setValue($value) { |
64 | 64 | $model = \Seufert\Hamle\Scope::get(); |
65 | - if(!$model instanceof WriteModel) |
|
65 | + if (!$model instanceof WriteModel) |
|
66 | 66 | throw new \RuntimeException('Can only write to model that implements WriteModel'); |
67 | 67 | $model->hamleSet($this->var, $value); |
68 | 68 | return $model; |
@@ -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 |