@@ -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 | } |
@@ -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 | /** |
@@ -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; |
@@ -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 | } |
@@ -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 | |