@@ -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 WriteModel, got '.get_class($model)); |
93 | 93 | $model->hamleSet($this->sel[0], $value); |
94 | 94 | return $model; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct($s) { |
41 | 41 | $m = array(); |
42 | - if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) |
|
42 | + if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL.'+)(.*)$/', $s, $m)) |
|
43 | 43 | throw new ParseError("Unable to read \$ sub func in '$s'"); |
44 | 44 | if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT; |
45 | 45 | elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD; |
@@ -57,24 +57,24 @@ discard block |
||
57 | 57 | * @return string |
58 | 58 | */ |
59 | 59 | public function toPHP() { |
60 | - $limit = Hamle\Text::varToCode($this->sortlimit['sort']) . "," . |
|
61 | - $this->sortlimit['limit'] . "," . $this->sortlimit['offset'] . "," . |
|
60 | + $limit = Hamle\Text::varToCode($this->sortlimit['sort']).",". |
|
61 | + $this->sortlimit['limit'].",".$this->sortlimit['offset'].",". |
|
62 | 62 | $this->grouptype['grouptype']; |
63 | - $sub = $this->sub ? "->" . $this->sub->toPHP() : ""; |
|
64 | - return "hamleRel(" . $this->dir . "," . |
|
65 | - Hamle\Text::varToCode($this->filt['tag']) . ",$limit)$sub"; |
|
63 | + $sub = $this->sub ? "->".$this->sub->toPHP() : ""; |
|
64 | + return "hamleRel(".$this->dir.",". |
|
65 | + Hamle\Text::varToCode($this->filt['tag']).",$limit)$sub"; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | public function getOrCreateModel(Model $parent = null) { |
69 | 69 | $model = $parent->hamleRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'], |
70 | 70 | $this->sortlimit['limit'], $this->sortlimit['offset']); |
71 | - if(!$model->valid()) { |
|
72 | - if(!$parent instanceof Hamle\WriteModel) |
|
73 | - throw new \Exception('Cant create model, ' . get_class($parent) . ' must implement Hamle\\WriteModel.'); |
|
71 | + if (!$model->valid()) { |
|
72 | + if (!$parent instanceof Hamle\WriteModel) |
|
73 | + throw new \Exception('Cant create model, '.get_class($parent).' must implement Hamle\\WriteModel.'); |
|
74 | 74 | $model = $parent->current()->hamleCreateRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'], |
75 | 75 | $this->sortlimit['limit'], $this->sortlimit['offset']); |
76 | 76 | } |
77 | - if($this->sub) |
|
77 | + if ($this->sub) |
|
78 | 78 | return $this->sub->getOrCreateModel($model); |
79 | 79 | return $model; |
80 | 80 | } |