@@ -42,22 +42,22 @@ 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 | $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() { |
59 | 59 | $close = in_array($this->type, self::$selfCloseTags) ? " />" : ">"; |
60 | - return "<{$this->type}" . $this->optToTags() . $close; |
|
60 | + return "<{$this->type}".$this->optToTags().$close; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | function renderEnTag() { |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | if (!$v instanceof H\Text) |
80 | 80 | $v = new H\Text($v); |
81 | 81 | $k = new H\Text($k); |
82 | - $out[] = " " . $k->toHTML() . "=\"" . $v->toHTMLAtt() . "\""; |
|
82 | + $out[] = " ".$k->toHTML()."=\"".$v->toHTMLAtt()."\""; |
|
83 | 83 | } |
84 | 84 | return implode("", $out); |
85 | 85 | } |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | |
64 | 64 | public $baseModel; |
65 | 65 | |
66 | - const REL_CHILD = 0x01; /* Child Relation */ |
|
66 | + const REL_CHILD = 0x01; /* Child Relation */ |
|
67 | 67 | const REL_PARENT = 0x02; /* Parent Relation */ |
68 | - const REL_ANY = 0x03; /* Unspecified or any relation */ |
|
68 | + const REL_ANY = 0x03; /* Unspecified or any relation */ |
|
69 | 69 | |
70 | - const SORT_NATURAL = 0x00; /* Sort in what ever order is 'default' */ |
|
71 | - const SORT_ASCENDING = 0x02; /* Sort Ascending */ |
|
70 | + const SORT_NATURAL = 0x00; /* Sort in what ever order is 'default' */ |
|
71 | + const SORT_ASCENDING = 0x02; /* Sort Ascending */ |
|
72 | 72 | const SORT_DESCENDING = 0x03; /* Sort Decending */ |
73 | - const SORT_RANDOM = 0x04; /* Sort Randomly */ |
|
73 | + const SORT_RANDOM = 0x04; /* Sort Randomly */ |
|
74 | 74 | /** |
75 | 75 | * Create new HAMLE Parser |
76 | 76 | * |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | */ |
82 | 82 | function __construct($baseModel, $setup = NULL) { |
83 | 83 | self::$me = $this; |
84 | - if(!$setup) |
|
84 | + if (!$setup) |
|
85 | 85 | $setup = new Setup(); |
86 | 86 | $this->parse = new Parse(); |
87 | - if(!$setup instanceOf Setup) |
|
87 | + if (!$setup instanceOf Setup) |
|
88 | 88 | throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup"); |
89 | - if(!$baseModel instanceOf Model) |
|
89 | + if (!$baseModel instanceOf Model) |
|
90 | 90 | throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel"); |
91 | 91 | $this->setup = $setup; |
92 | 92 | $this->baseModel = $baseModel; |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | function initSnipFiles() { |
97 | - if($this->snipMod == 0) { |
|
97 | + if ($this->snipMod == 0) { |
|
98 | 98 | $this->snipFiles = $this->setup->snippetFiles(); |
99 | - foreach($this->snipFiles as $f) { |
|
99 | + foreach ($this->snipFiles as $f) { |
|
100 | 100 | if (!file_exists($f)) throw new Exception\NotFound("Unable to find Snippet File ($f)"); |
101 | 101 | $this->snipFiles = max($this->snipFiles, filemtime($f)); |
102 | 102 | } |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | */ |
112 | 112 | function load($hamleFile, \Closure $parseFunc = null) { |
113 | 113 | $template = $this->setup->templatePath($hamleFile); |
114 | - if(!file_exists($template)) |
|
114 | + if (!file_exists($template)) |
|
115 | 115 | throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
116 | 116 | $this->cacheFile = $this->setup->cachePath( |
117 | - str_replace("/","-",$hamleFile).".php"); |
|
117 | + str_replace("/", "-", $hamleFile).".php"); |
|
118 | 118 | $this->setup->debugLog("Set cache file path to ({$this->cacheFile})"); |
119 | - $cacheFileAge = is_file($this->cacheFile)?filemtime($this->cacheFile):0; |
|
119 | + $cacheFileAge = is_file($this->cacheFile) ?filemtime($this->cacheFile) : 0; |
|
120 | 120 | $cacheDirty = !$this->cache || |
121 | 121 | $cacheFileAge < $this->snipMod || $cacheFileAge < filemtime($template); |
122 | - if($cacheDirty) { |
|
122 | + if ($cacheDirty) { |
|
123 | 123 | $this->setup->debugLog("Parsing File ($template to {$this->cacheFile})"); |
124 | - $this->parse($parseFunc?"":file_get_contents($template), $parseFunc); |
|
124 | + $this->parse($parseFunc ? "" : file_get_contents($template), $parseFunc); |
|
125 | 125 | } else |
126 | 126 | $this->setup->debugLog("Using Cached file ({$this->cacheFile})"); |
127 | 127 | return $this; |
@@ -135,22 +135,22 @@ discard block |
||
135 | 135 | * @throws Exception\ParseError if unable to write to the cache file |
136 | 136 | */ |
137 | 137 | function parse($hamleCode, \Closure $parseFunc = null) { |
138 | - if(!$this->cacheFile) |
|
138 | + if (!$this->cacheFile) |
|
139 | 139 | $this->cacheFile = $this->setup->cachePath("string.hamle.php"); |
140 | - if($parseFunc) |
|
140 | + if ($parseFunc) |
|
141 | 141 | $parseFunc($this->parse); |
142 | 142 | else |
143 | 143 | $this->parse->str($hamleCode); |
144 | 144 | $this->setup->debugLog("Loading Snippet Files"); |
145 | - foreach($this->snipFiles as $snip) |
|
145 | + foreach ($this->snipFiles as $snip) |
|
146 | 146 | $this->parse->parseSnip(file_get_contents($snip)); |
147 | 147 | $this->setup->debugLog("Applying Snippet Files"); |
148 | 148 | $this->parse->applySnip(); |
149 | 149 | $this->setup->debugLog("Executing Parse Filters"); |
150 | - foreach($this->setup->getFilters() as $filter) |
|
150 | + foreach ($this->setup->getFilters() as $filter) |
|
151 | 151 | $this->parse->parseFilter($filter); |
152 | 152 | $this->setup->debugLog("Updating Cache File ({$this->cacheFile})"); |
153 | - if(FALSE === file_put_contents($this->cacheFile, $this->parse->output())) |
|
153 | + if (FALSE === file_put_contents($this->cacheFile, $this->parse->output())) |
|
154 | 154 | throw new Exception\ParseError( |
155 | 155 | "Unable to write to cache file ({$this->cacheFile})"); |
156 | 156 | } |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | */ |
162 | 162 | function string($hamleString) { |
163 | 163 | $md5 = md5($hamleString); |
164 | - $stringId = substr($md5,0,12).substr($md5,24,8); |
|
164 | + $stringId = substr($md5, 0, 12).substr($md5, 24, 8); |
|
165 | 165 | $this->cacheFile = $this->setup->cachePath("string.$stringId.hamle.php"); |
166 | - if(!is_file($this->cacheFile)) |
|
166 | + if (!is_file($this->cacheFile)) |
|
167 | 167 | $this->parse($hamleString); |
168 | 168 | } |
169 | 169 | |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | $baseModel = $this->baseModel; |
180 | 180 | $this->baseModel = null; |
181 | 181 | $currentModel = $baseModel == Scope::getTopScope(); |
182 | - if(!$currentModel && $baseModel) Scope::add($baseModel); |
|
182 | + if (!$currentModel && $baseModel) Scope::add($baseModel); |
|
183 | 183 | require $this->cacheFile; |
184 | - if(!$currentModel && $baseModel) Scope::done(); |
|
184 | + if (!$currentModel && $baseModel) Scope::done(); |
|
185 | 185 | $this->baseModel = $baseModel; |
186 | 186 | $out = ob_get_contents(); |
187 | 187 | ob_end_clean(); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @return int The line number being passed by the parser |
199 | 199 | */ |
200 | 200 | static function getLineNo() { |
201 | - if(!isset(self::$me)) |
|
201 | + if (!isset(self::$me)) |
|
202 | 202 | return 0; |
203 | 203 | return self::$me->parse->getLineNo(); |
204 | 204 | } |
@@ -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 |
@@ -36,17 +36,17 @@ discard block |
||
36 | 36 | function __construct($s) { |
37 | 37 | $m = []; |
38 | 38 | //var_dump($s); |
39 | - if(!preg_match('/\$\[(-?[0-9]+|[a-zA-Z][a-zA-Z0-9]+)\]/', $s, $m)) { |
|
39 | + if (!preg_match('/\$\[(-?[0-9]+|[a-zA-Z][a-zA-Z0-9]+)\]/', $s, $m)) { |
|
40 | 40 | throw new ParseError("Unable to match scope ($s)"); |
41 | 41 | } |
42 | 42 | $this->scope = $m[1]; |
43 | 43 | } |
44 | 44 | |
45 | 45 | function toPHP() { |
46 | - if(is_numeric($this->scope)) { |
|
47 | - return "Hamle\\Scope::get(" . Text::varToCode($this->scope) . ")"; |
|
46 | + if (is_numeric($this->scope)) { |
|
47 | + return "Hamle\\Scope::get(".Text::varToCode($this->scope).")"; |
|
48 | 48 | } else { |
49 | - return "Hamle\\Scope::getName(" . Text::varToCode($this->scope) . ")"; |
|
49 | + return "Hamle\\Scope::getName(".Text::varToCode($this->scope).")"; |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | |
62 | 62 | function getOrCreateModel(Model $parent = null) { |
63 | - if(is_numeric($this->scope)) { |
|
63 | + if (is_numeric($this->scope)) { |
|
64 | 64 | return \Seufert\Hamle\Scope::get($this->scope); |
65 | 65 | } |
66 | 66 | return \Seufert\Hamle\Scope::getName($this->scope); |
@@ -35,26 +35,26 @@ discard block |
||
35 | 35 | protected $filter; |
36 | 36 | |
37 | 37 | function __construct($s) { |
38 | - if(FALSE !== $pos = strpos($s,'|')) { |
|
39 | - $this->var = substr($s,1,$pos-1); |
|
40 | - $this->filter = new Filter(substr($s, $pos+1), $this); |
|
38 | + if (FALSE !== $pos = strpos($s, '|')) { |
|
39 | + $this->var = substr($s, 1, $pos - 1); |
|
40 | + $this->filter = new Filter(substr($s, $pos + 1), $this); |
|
41 | 41 | } else { |
42 | 42 | $this->var = substr($s, 1); |
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | 46 | function toHTML($escape = false) { |
47 | - if($escape) |
|
48 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
49 | - return "<?=" . $this->toPHP() . "?>"; |
|
47 | + if ($escape) |
|
48 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
49 | + return "<?=".$this->toPHP()."?>"; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | function toPHP() { |
53 | - return $this->filter?$this->filter->toPHP():$this->toPHPVar(); |
|
53 | + return $this->filter ? $this->filter->toPHP() : $this->toPHPVar(); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | function toPHPVar() { |
57 | - return "Hamle\\Scope::get()->hamleGet(" . Text::varToCode($this->var) . ")"; |
|
57 | + return "Hamle\\Scope::get()->hamleGet(".Text::varToCode($this->var).")"; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | function getOrCreateModel(Model $parent = null) { |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | function setValue($value) { |
69 | 69 | $model = $this->getOrCreateModel(); |
70 | - if(!$model instanceof WriteModel) |
|
70 | + if (!$model instanceof WriteModel) |
|
71 | 71 | throw new \RuntimeException('Can only write to model that implements WriteModel'); |
72 | 72 | $model->hamleSet($this->var, $value); |
73 | 73 | return $model; |
@@ -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)->current(); |
79 | 79 | return $model->current(); |
80 | 80 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function __construct($s) { |
52 | 52 | $m = array(); |
53 | - if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) |
|
53 | + if (!preg_match('/^\$\(('.self::REGEX_FUNCSEL.'*)(.*)\)$/', $s, $m)) |
|
54 | 54 | throw new ParseError("Unable to read \$ func in '$s'"); |
55 | 55 | if (trim($m[2])) |
56 | 56 | $this->sub = new FuncSub($m[2]); |
@@ -92,13 +92,13 @@ discard block |
||
92 | 92 | } |
93 | 93 | $rand = false; |
94 | 94 | if (preg_match_all('/\\^(-?)([a-zA-Z0-9\_]*)/', $s, $m)) { |
95 | - foreach($m[0] as $k=>$mv) |
|
95 | + foreach ($m[0] as $k=>$mv) |
|
96 | 96 | if ($m[2][$k]) { |
97 | - $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING; |
|
97 | + $dir = $m[1][$k] == "-" ?Hamle\Hamle::SORT_DESCENDING : Hamle\Hamle::SORT_ASCENDING; |
|
98 | 98 | $att['sort'][$m[2][$k]] = $dir; |
99 | 99 | } else $rand = true; |
100 | 100 | } |
101 | - if($rand) |
|
101 | + if ($rand) |
|
102 | 102 | $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
103 | 103 | return $att; |
104 | 104 | } |
@@ -116,25 +116,25 @@ discard block |
||
116 | 116 | * @return string PHP Code |
117 | 117 | */ |
118 | 118 | public function toPHP() { |
119 | - $sub = $this->sub ? "->" . $this->sub->toPHP() : ""; |
|
120 | - if($this->scope instanceof Scope) { |
|
121 | - return $this->scope->toPHP() . $sub; |
|
122 | - } elseif($this->scope === true) { |
|
119 | + $sub = $this->sub ? "->".$this->sub->toPHP() : ""; |
|
120 | + if ($this->scope instanceof Scope) { |
|
121 | + return $this->scope->toPHP().$sub; |
|
122 | + } elseif ($this->scope === true) { |
|
123 | 123 | return "Hamle\\Scope::get(0)$sub"; |
124 | 124 | } |
125 | - $limit = Text::varToCode($this->sortlimit['sort']) . "," . |
|
126 | - $this->sortlimit['limit'] . "," . $this->sortlimit['offset']; |
|
125 | + $limit = Text::varToCode($this->sortlimit['sort']).",". |
|
126 | + $this->sortlimit['limit'].",".$this->sortlimit['offset']; |
|
127 | 127 | if (count($this->filt['tag'])) |
128 | - return "Hamle\\Run::modelTypeTags(" . |
|
129 | - Text::varToCode($this->filt['tag']) . ",$limit)$sub"; |
|
128 | + return "Hamle\\Run::modelTypeTags(". |
|
129 | + Text::varToCode($this->filt['tag']).",$limit)$sub"; |
|
130 | 130 | if (count($this->filt['id'])) |
131 | 131 | if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) |
132 | - return "Hamle\\Run::modelId(" . |
|
133 | - Text::varToCode(current($this->filt['id']['*'])) . |
|
132 | + return "Hamle\\Run::modelId(". |
|
133 | + Text::varToCode(current($this->filt['id']['*'])). |
|
134 | 134 | ",$limit)$sub"; |
135 | 135 | else |
136 | - return "Hamle\\Run::modelTypeId(" . |
|
137 | - Text::varToCode($this->filt['id']) . ",$limit)$sub"; |
|
136 | + return "Hamle\\Run::modelTypeId(". |
|
137 | + Text::varToCode($this->filt['id']).",$limit)$sub"; |
|
138 | 138 | return ""; |
139 | 139 | } |
140 | 140 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @return Model |
144 | 144 | */ |
145 | 145 | public function getOrCreateModel(Model $parent = null) { |
146 | - if($this->scope instanceof Scope) { |
|
146 | + if ($this->scope instanceof Scope) { |
|
147 | 147 | $parent = $this->scope->getOrCreateModel(); |
148 | 148 | } elseif ($this->scope === true) |
149 | 149 | $parent = \Seufert\Hamle\Scope::get(0); |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | $this->sortlimit['limit'], |
170 | 170 | $this->sortlimit['offset'] |
171 | 171 | ); |
172 | - if($this->sub) |
|
172 | + if ($this->sub) |
|
173 | 173 | return $this->sub->getOrCreateModel($parent)->current(); |
174 | - if(!$parent) |
|
174 | + if (!$parent) |
|
175 | 175 | throw new \RuntimeException('Unable to create model with no relation'); |
176 | 176 | return $parent->current(); |
177 | 177 | } |
@@ -41,49 +41,49 @@ discard block |
||
41 | 41 | protected $chained; |
42 | 42 | |
43 | 43 | function __construct($s, Text $what) { |
44 | - if(preg_match("/^([a-z]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
|
44 | + if (preg_match("/^([a-z]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) { |
|
45 | 45 | $this->filter = $m[1]; |
46 | 46 | $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : []; |
47 | - foreach($this->vars as $k=>$v) |
|
48 | - $this->vars[$k] = str_replace(",",',',$v); |
|
49 | - if(isset($m['chained']) && strlen($m['chained'])) { |
|
50 | - $this->chained = new Filter($m['chained'],$what); |
|
47 | + foreach ($this->vars as $k=>$v) |
|
48 | + $this->vars[$k] = str_replace(",", ',', $v); |
|
49 | + if (isset($m['chained']) && strlen($m['chained'])) { |
|
50 | + $this->chained = new Filter($m['chained'], $what); |
|
51 | 51 | } |
52 | 52 | } else { |
53 | 53 | throw new ParseError("Unable to parse filter expression \"$s\""); |
54 | 54 | } |
55 | - if(!in_array($this->filter, ['itersplit', 'newlinebr', 'round', |
|
56 | - 'strtoupper', 'strtolower', 'ucfirst','replace', 'json'])) { |
|
55 | + if (!in_array($this->filter, ['itersplit', 'newlinebr', 'round', |
|
56 | + 'strtoupper', 'strtolower', 'ucfirst', 'replace', 'json'])) { |
|
57 | 57 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
58 | 58 | } |
59 | - if(in_array($this->filter,['itersplit','newlinebr', 'replace'])) { |
|
59 | + if (in_array($this->filter, ['itersplit', 'newlinebr', 'replace'])) { |
|
60 | 60 | $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}"; |
61 | 61 | } |
62 | 62 | $mapFilter = ['json'=>'json_encode']; |
63 | - if(isset($mapFilter[$this->filter])) |
|
63 | + if (isset($mapFilter[$this->filter])) |
|
64 | 64 | $this->filter = $mapFilter[$this->filter]; |
65 | 65 | $this->what = $what; |
66 | 66 | } |
67 | 67 | |
68 | 68 | function toHTML($escape = false) { |
69 | - if($escape) |
|
70 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
71 | - return "<?=" . $this->toPHP() . "?>"; |
|
69 | + if ($escape) |
|
70 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
71 | + return "<?=".$this->toPHP()."?>"; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | function toPHPpre() { |
75 | 75 | $pre = ''; |
76 | - if($this->chained) |
|
76 | + if ($this->chained) |
|
77 | 77 | $pre = $this->chained->toPHPpre(); |
78 | 78 | return "$pre{$this->filter}("; |
79 | 79 | } |
80 | 80 | |
81 | 81 | function toPHPpost() { |
82 | 82 | $post = ''; |
83 | - if($this->chained) |
|
83 | + if ($this->chained) |
|
84 | 84 | $post = $this->chained->toPHPpost(); |
85 | 85 | $o = ''; |
86 | - foreach($this->vars as $v) |
|
86 | + foreach ($this->vars as $v) |
|
87 | 87 | $o .= ','.$this->varToCode($v); |
88 | 88 | return "$o)$post"; |
89 | 89 | } |
@@ -98,19 +98,19 @@ discard block |
||
98 | 98 | |
99 | 99 | static function itersplit($v, $sep = ",") { |
100 | 100 | $o = []; |
101 | - foreach(explode($sep, $v) as $k=>$i) { |
|
102 | - if($i) |
|
103 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
101 | + foreach (explode($sep, $v) as $k=>$i) { |
|
102 | + if ($i) |
|
103 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k]; |
|
104 | 104 | } |
105 | 105 | return new WrapArray($o); |
106 | 106 | } |
107 | 107 | |
108 | 108 | static function newlinebr($v) { |
109 | - return str_replace("\n","<br />\n",$v); |
|
109 | + return str_replace("\n", "<br />\n", $v); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | static function replace($v, $src, $dst) { |
113 | - return str_replace($src,$dst,$v); |
|
113 | + return str_replace($src, $dst, $v); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | } |
117 | 117 | \ No newline at end of file |