@@ -40,9 +40,9 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function cachePath($f) {
|
| 42 | 42 | $s = DIRECTORY_SEPARATOR; |
| 43 | - $dir = implode($s,[__DIR__,"..","..","cache",""]); |
|
| 44 | - if(!is_dir($dir)) mkdir($dir); |
|
| 45 | - return $dir.$f; |
|
| 43 | + $dir = implode($s, [__DIR__, "..", "..", "cache", ""]); |
|
| 44 | + if (!is_dir($dir)) mkdir($dir); |
|
| 45 | + return $dir . $f; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @throws Exception\RunTime |
| 68 | 68 | */ |
| 69 | 69 | public function getModelTypeID($typeId, $sort = [], $limit = 0, $offset = 0) {
|
| 70 | - if(count($typeId) > 1) |
|
| 70 | + if (count($typeId) > 1) |
|
| 71 | 71 | throw new Exception\RunTime("Unable to open more than one ID at a time");
|
| 72 | 72 | return new Model\Zero(); |
| 73 | 73 | } |
@@ -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,22 +81,22 @@ 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) |
|
| 90 | - throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel"); |
|
| 89 | + if (!$baseModel instanceOf Model) |
|
| 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; |
| 93 | 93 | $this->initSnipFiles(); |
| 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 | } |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | $this->type = strtolower($tag); |
| 52 | 52 | $this->var = ""; |
| 53 | 53 | if ($parentTag && $this->type == "else") { |
| 54 | - if($parentTag instanceof H\Tag) { |
|
| 54 | + if ($parentTag instanceof H\Tag) { |
|
| 55 | 55 | $elseTag = $parentTag->tags[count($parentTag->tags) - 1]; |
| 56 | - if($elseTag instanceof H\Tag\Control && |
|
| 56 | + if ($elseTag instanceof H\Tag\Control && |
|
| 57 | 57 | in_array($elseTag->type, array('with', 'if')) |
| 58 | 58 | ) { |
| 59 | 59 | $elseTag->else = true; |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | break; |
| 102 | 102 | case "include": |
| 103 | 103 | $file = $hsv->toHTML(); |
| 104 | - if($file[0] == "#") |
|
| 105 | - $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
| 104 | + if ($file[0] == "#") |
|
| 105 | + $out .= "echo Hamle\\Run::includeFragment(" . $hsv->toPHP() . ");"; |
|
| 106 | 106 | else |
| 107 | 107 | $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
| 108 | 108 | break; |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | $rand = false; |
| 88 | 88 | if (preg_match_all('/\\^(-?)([a-zA-Z0-9\_]*)/', $s, $m)) { |
| 89 | - foreach($m[0] as $k=>$mv) |
|
| 89 | + foreach ($m[0] as $k=>$mv) |
|
| 90 | 90 | if ($m[2][$k]) { |
| 91 | - $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING; |
|
| 91 | + $dir = $m[1][$k] == "-" ? Hamle\Hamle::SORT_DESCENDING : Hamle\Hamle::SORT_ASCENDING; |
|
| 92 | 92 | $att['sort'][$m[2][$k]] = $dir; |
| 93 | 93 | } else $rand = true; |
| 94 | 94 | } |
| 95 | - if($rand) |
|
| 95 | + if ($rand) |
|
| 96 | 96 | $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
| 97 | 97 | return $att; |
| 98 | 98 | } |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | function toPHP() { |
| 113 | 113 | $sub = $this->sub ? "->" . $this->sub->toPHP() : ""; |
| 114 | - if($this->scope instanceof Scope) { |
|
| 114 | + if ($this->scope instanceof Scope) { |
|
| 115 | 115 | return $this->scope->toPHP() . $sub; |
| 116 | - } elseif($this->scope === true) { |
|
| 116 | + } elseif ($this->scope === true) { |
|
| 117 | 117 | return "Hamle\\Scope::get(0)$sub"; |
| 118 | 118 | } |
| 119 | 119 | $limit = Text::varToCode($this->sortlimit['sort']) . "," . |
@@ -38,16 +38,16 @@ discard block |
||
| 38 | 38 | protected $what; |
| 39 | 39 | |
| 40 | 40 | function __construct($s, Text $what) { |
| 41 | - if(preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) { |
|
| 41 | + if (preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) { |
|
| 42 | 42 | $this->filter = $m[1]; |
| 43 | 43 | $this->vars = isset($m[3]) ? explode(',', $m[3]) : []; |
| 44 | 44 | } else { |
| 45 | 45 | throw new ParseError("Unable to parse filter expression \"$s\""); |
| 46 | 46 | } |
| 47 | - if(!in_array($this->filter, ['itersplit', 'newlinebr', 'round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
|
| 47 | + if (!in_array($this->filter, ['itersplit', 'newlinebr', 'round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
|
| 48 | 48 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
| 49 | 49 | } |
| 50 | - switch($this->filter) { |
|
| 50 | + switch ($this->filter) { |
|
| 51 | 51 | case "itersplit": |
| 52 | 52 | $this->filter = "Seufert\\Hamle\\Text\\Filter::iterSplit"; |
| 53 | 53 | break; |
@@ -59,29 +59,29 @@ discard block |
||
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function toHTML($escape = false) { |
| 62 | - if($escape) |
|
| 63 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 62 | + if ($escape) |
|
| 63 | + return "<?=htmlspecialchars(" . $this->toPHP() . ")?>"; |
|
| 64 | 64 | return "<?=" . $this->toPHP() . "?>"; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | function toPHP() { |
| 68 | - $o = [$this->what->toPHPVar()] ; |
|
| 69 | - foreach($this->vars as $v) |
|
| 68 | + $o = [$this->what->toPHPVar()]; |
|
| 69 | + foreach ($this->vars as $v) |
|
| 70 | 70 | $o[] = $this->varToCode($v); |
| 71 | - return "{$this->filter}(" . implode(',',$o) . ")"; |
|
| 71 | + return "{$this->filter}(" . implode(',', $o) . ")"; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | static function iterSplit($v, $sep = ",") { |
| 75 | 75 | $o = []; |
| 76 | - foreach(explode($sep, $v) as $k=>$i) { |
|
| 77 | - if($i) |
|
| 78 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
| 76 | + foreach (explode($sep, $v) as $k=>$i) { |
|
| 77 | + if ($i) |
|
| 78 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k]; |
|
| 79 | 79 | } |
| 80 | 80 | return new WrapArray($o); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | static function newlineBr($v) { |
| 84 | - return str_replace("\n","<br />\n",$v); |
|
| 84 | + return str_replace("\n", "<br />\n", $v); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | } |
| 88 | 88 | \ No newline at end of file |
@@ -34,12 +34,12 @@ discard block |
||
| 34 | 34 | protected $filter; |
| 35 | 35 | |
| 36 | 36 | function __construct($s) { |
| 37 | - if(FALSE !== $pos = strpos($s,'|')) { |
|
| 38 | - $this->filter = new Filter(substr($s, $pos+1), $this); |
|
| 39 | - $s = substr($s,0,$pos); |
|
| 37 | + if (FALSE !== $pos = strpos($s, '|')) { |
|
| 38 | + $this->filter = new Filter(substr($s, $pos + 1), $this); |
|
| 39 | + $s = substr($s, 0, $pos); |
|
| 40 | 40 | } |
| 41 | 41 | $s = explode("->", $s); |
| 42 | - if(count($s) == 1) $s = explode("-!",$s[0]); |
|
| 42 | + if (count($s) == 1) $s = explode("-!", $s[0]); |
|
| 43 | 43 | if (!$s[0]) throw new ParseError("Unable to parse Complex Expression"); |
| 44 | 44 | if ($s[0][1] == "(") |
| 45 | 45 | $this->func = new Text\Func($s[0]); |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | function toHTML($escape = false) { |
| 55 | - if($escape) |
|
| 56 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 55 | + if ($escape) |
|
| 56 | + return "<?=htmlspecialchars(" . $this->toPHP() . ")?>"; |
|
| 57 | 57 | return "<?=" . $this->toPHP() . "?>"; |
| 58 | 58 | } |
| 59 | 59 | function toPHP() { |
| 60 | - return $this->filter?$this->filter->toPHP():$this->toPHPVar(); |
|
| 60 | + return $this->filter ? $this->filter->toPHP() : $this->toPHPVar(); |
|
| 61 | 61 | } |
| 62 | 62 | function toPHPVar() { |
| 63 | 63 | if ($this->sel) { |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | $i = self::indentLevel($indent); |
| 158 | 158 | unset($m[0]); |
| 159 | 159 | switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) {
|
| 160 | - case "|": //Control Tag |
|
| 160 | + case "|" : //Control Tag |
|
| 161 | 161 | if ($code == "|snippet") |
| 162 | 162 | $hTag = new Tag\Snippet($text); |
| 163 | 163 | elseif ($code == "|form") |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | break; |
| 193 | 193 | default: |
| 194 | 194 | $attr = array(); |
| 195 | - if(isset($params[0]) && $params[0] == "[") {
|
|
| 195 | + if (isset($params[0]) && $params[0] == "[") {
|
|
| 196 | 196 | $param = substr($params, 1, strlen($params) - 2); |
| 197 | - $param = str_replace('+','%2B', $param);
|
|
| 197 | + $param = str_replace('+', '%2B', $param);
|
|
| 198 | 198 | // parse_str($param, $attr); |
| 199 | 199 | $attr = $this->parseQueryString($param); |
| 200 | 200 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | if ($s[0] == ".") $class[] = substr($s, 1); |
| 206 | 206 | if ($s[0] == "!") $ref = substr($s, 1); |
| 207 | 207 | } |
| 208 | - if($ref) |
|
| 208 | + if ($ref) |
|
| 209 | 209 | $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
| 210 | 210 | else |
| 211 | 211 | $hTag = new Tag\Html($tag, $class, $attr, $id); |
@@ -225,8 +225,8 @@ discard block |
||
| 225 | 225 | |
| 226 | 226 | function parseQueryString($qs) {
|
| 227 | 227 | $out = []; |
| 228 | - foreach(explode('&',$qs) as $s) {
|
|
| 229 | - list($k, $v) = explode('=',$s,2);
|
|
| 228 | + foreach (explode('&', $qs) as $s) {
|
|
| 229 | + list($k, $v) = explode('=', $s, 2);
|
|
| 230 | 230 | $out[urldecode($k)] = urldecode($v); |
| 231 | 231 | } |
| 232 | 232 | return $out; |