@@ -50,15 +50,17 @@ |
||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function toHTML($escape = false) { |
| 53 | - if($escape) |
|
| 54 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 53 | + if($escape) { |
|
| 54 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 55 | + } |
|
| 55 | 56 | return "<?=" . $this->toPHP() . "?>"; |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | function toPHP() { |
| 59 | 60 | $o = [$this->what->toPHPVar()] ; |
| 60 | - foreach($this->vars as $v) |
|
| 61 | - $o[] = $this->varToCode($v); |
|
| 61 | + foreach($this->vars as $v) { |
|
| 62 | + $o[] = $this->varToCode($v); |
|
| 63 | + } |
|
| 62 | 64 | return "{$this->filter}(" . implode(',',$o) . ")"; |
| 63 | 65 | } |
| 64 | 66 | } |
| 65 | 67 | \ No newline at end of file |
@@ -39,8 +39,9 @@ discard block |
||
| 39 | 39 | $this->param1 = new Text($m[1],Text::TOKEN_HTML); |
| 40 | 40 | $this->param2 = new Text($m[3],Text::TOKEN_HTML); |
| 41 | 41 | $this->operator = $m[2]; |
| 42 | - } else |
|
| 43 | - $this->param1 = new Text($s,Text::TOKEN_HTML); |
|
| 42 | + } else { |
|
| 43 | + $this->param1 = new Text($s,Text::TOKEN_HTML); |
|
| 44 | + } |
|
| 44 | 45 | } |
| 45 | 46 | |
| 46 | 47 | // function __construct(String $p1, String $p2, $operator) { |
@@ -49,7 +50,9 @@ discard block |
||
| 49 | 50 | // $this->operator = $operator; |
| 50 | 51 | // } |
| 51 | 52 | function toPHP() { |
| 52 | - if(!$this->param2) return $this->param1->toPHP(); |
|
| 53 | + if(!$this->param2) { |
|
| 54 | + return $this->param1->toPHP(); |
|
| 55 | + } |
|
| 53 | 56 | $p1 = $this->param1->toPHP(); |
| 54 | 57 | $p2 = $this->param2->toPHP(); |
| 55 | 58 | switch($this->operator) { |
@@ -31,7 +31,8 @@ |
||
| 31 | 31 | function __construct($s) { |
| 32 | 32 | $s = explode("->", $s, 2); |
| 33 | 33 | $this->key = $s[0]; |
| 34 | - if (count($s) > 1) |
|
| 35 | - $this->sel = $s[1]; |
|
| 34 | + if (count($s) > 1) { |
|
| 35 | + $this->sel = $s[1]; |
|
| 36 | + } |
|
| 36 | 37 | } |
| 37 | 38 | } |
| 38 | 39 | \ No newline at end of file |
@@ -18,12 +18,14 @@ discard block |
||
| 18 | 18 | static $namedScopes = array(); |
| 19 | 19 | |
| 20 | 20 | static function add($model, $name = null) {
|
| 21 | - if (!$model instanceOf Model) |
|
| 22 | - throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface");
|
|
| 23 | - if ($name) |
|
| 24 | - self::$namedScopes[$name] = $model; |
|
| 25 | - else |
|
| 26 | - self::$scopes[] = $model; |
|
| 21 | + if (!$model instanceOf Model) { |
|
| 22 | + throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface"); |
|
| 23 | + } |
|
| 24 | + if ($name) { |
|
| 25 | + self::$namedScopes[$name] = $model; |
|
| 26 | + } else { |
|
| 27 | + self::$scopes[] = $model; |
|
| 28 | + } |
|
| 27 | 29 | } |
| 28 | 30 | |
| 29 | 31 | static function done() {
|
@@ -41,15 +43,21 @@ discard block |
||
| 41 | 43 | */ |
| 42 | 44 | static function get($id = 0) {
|
| 43 | 45 | if (0 == $id) {
|
| 44 | - if ($scope = end(self::$scopes)) |
|
| 45 | - return $scope; |
|
| 46 | + if ($scope = end(self::$scopes)) { |
|
| 47 | + return $scope; |
|
| 48 | + } |
|
| 46 | 49 | throw new OutOfScope("Unable to find Scope ($id)");
|
| 47 | 50 | } |
| 48 | 51 | $key = $id - 1; |
| 49 | - if ($id < 0) $key = count(self::$scopes) + $id - 1; |
|
| 50 | - if ($id == 0) $key = count(self::$scopes) - 1; |
|
| 51 | - if (!isset(self::$scopes[$key])) |
|
| 52 | - throw new OutOfScope("Unable to find Scope ($id) or $key");
|
|
| 52 | + if ($id < 0) { |
|
| 53 | + $key = count(self::$scopes) + $id - 1; |
|
| 54 | + } |
|
| 55 | + if ($id == 0) { |
|
| 56 | + $key = count(self::$scopes) - 1; |
|
| 57 | + } |
|
| 58 | + if (!isset(self::$scopes[$key])) { |
|
| 59 | + throw new OutOfScope("Unable to find Scope ($id) or $key"); |
|
| 60 | + } |
|
| 53 | 61 | return self::$scopes[$key]; |
| 54 | 62 | } |
| 55 | 63 | |
@@ -64,8 +72,9 @@ discard block |
||
| 64 | 72 | if ($name && isset(self::$namedScopes[$name])) {
|
| 65 | 73 | self::$namedScopes[$name]->rewind(); |
| 66 | 74 | return self::$namedScopes[$name]; |
| 67 | - } else |
|
| 68 | - throw new RunTime("Unable to find scope ($name)");
|
|
| 75 | + } else { |
|
| 76 | + throw new RunTime("Unable to find scope ($name)"); |
|
| 77 | + } |
|
| 69 | 78 | } |
| 70 | 79 | |
| 71 | 80 | } |
@@ -76,9 +76,10 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | array_shift($path); |
| 78 | 78 | } |
| 79 | - foreach ($this->tags as $tag) |
|
| 80 | - if ($found = $tag->find($path)) |
|
| 81 | - $list = array_merge($list, $found); |
|
| 79 | + foreach ($this->tags as $tag) { |
|
| 80 | + if ($found = $tag->find($path)) |
|
| 81 | + $list = array_merge($list, $found); |
|
| 82 | + } |
|
| 82 | 83 | return $list; |
| 83 | 84 | } |
| 84 | 85 | |
@@ -90,7 +91,9 @@ discard block |
||
| 90 | 91 | */ |
| 91 | 92 | function replace($path, Tag $newTag) {
|
| 92 | 93 | if ($this->compare($path[0])) {
|
| 93 | - if (count($path) == 1) return $newTag; |
|
| 94 | + if (count($path) == 1) { |
|
| 95 | + return $newTag; |
|
| 96 | + } |
|
| 94 | 97 | array_shift($path); |
| 95 | 98 | } |
| 96 | 99 | foreach ($this->tags as $k => $tag) {
|
@@ -103,21 +106,25 @@ discard block |
||
| 103 | 106 | } |
| 104 | 107 | |
| 105 | 108 | function addSnipContent($contentTag, &$tagArray = array(), $key = 0) {
|
| 106 | - foreach ($this->tags as $k => $tag) |
|
| 107 | - $tag->addSnipContent($contentTag, $this->tags, $k); |
|
| 109 | + foreach ($this->tags as $k => $tag) { |
|
| 110 | + $tag->addSnipContent($contentTag, $this->tags, $k); |
|
| 111 | + } |
|
| 108 | 112 | } |
| 109 | 113 | |
| 110 | 114 | function compare($tic) {
|
| 111 | - if (isset($tic['type']) && $this->type != $tic['type']) |
|
| 112 | - return false; |
|
| 115 | + if (isset($tic['type']) && $this->type != $tic['type']) { |
|
| 116 | + return false; |
|
| 117 | + } |
|
| 113 | 118 | if (isset($tic['id']) && |
| 114 | 119 | !(isset($this->opt['id']) && $tic['id'] == $this->opt['id']) |
| 115 | - ) |
|
| 116 | - return false; |
|
| 120 | + ) { |
|
| 121 | + return false; |
|
| 122 | + } |
|
| 117 | 123 | if (isset($tic['class']) && !(isset($this->opt['class']) |
| 118 | 124 | && !array_diff($tic['class'], $this->opt['class'])) |
| 119 | - ) |
|
| 120 | - return false; |
|
| 125 | + ) { |
|
| 126 | + return false; |
|
| 127 | + } |
|
| 121 | 128 | return true; |
| 122 | 129 | } |
| 123 | 130 | |
@@ -127,10 +134,11 @@ discard block |
||
| 127 | 134 | * @param string $mode Mode to add child [append|prepend] |
| 128 | 135 | */ |
| 129 | 136 | function addChild(Tag $tag, $mode = "append") {
|
| 130 | - if ($mode == "prepend") |
|
| 131 | - array_unshift($this->tags, $tag); |
|
| 132 | - else |
|
| 133 | - $this->tags[] = $tag; |
|
| 137 | + if ($mode == "prepend") { |
|
| 138 | + array_unshift($this->tags, $tag); |
|
| 139 | + } else { |
|
| 140 | + $this->tags[] = $tag; |
|
| 141 | + } |
|
| 134 | 142 | } |
| 135 | 143 | |
| 136 | 144 | /** |
@@ -145,9 +153,12 @@ discard block |
||
| 145 | 153 | $ind = $doIndent ? str_pad("", $indent, " ") : "";
|
| 146 | 154 | $oneliner = ((count($this->content) > 1 || $this->tags) ? false : true); |
| 147 | 155 | $out = $ind . $this->renderStTag() . ($oneliner ? "" : "\n"); |
| 148 | - if ($this->content) $out .= $this->renderContent($ind, $oneliner); |
|
| 149 | - foreach ($this->tags as $tag) |
|
| 150 | - $out .= $tag->render($indent + self::INDENT_SIZE); |
|
| 156 | + if ($this->content) { |
|
| 157 | + $out .= $this->renderContent($ind, $oneliner); |
|
| 158 | + } |
|
| 159 | + foreach ($this->tags as $tag) { |
|
| 160 | + $out .= $tag->render($indent + self::INDENT_SIZE); |
|
| 161 | + } |
|
| 151 | 162 | $out .= ($oneliner ? "" : $ind) . $this->renderEnTag() . "\n"; |
| 152 | 163 | return $out; |
| 153 | 164 | } |
@@ -161,8 +172,9 @@ discard block |
||
| 161 | 172 | */ |
| 162 | 173 | function renderContent($pad = "", $oneliner = false) {
|
| 163 | 174 | $out = ""; |
| 164 | - foreach ($this->content as $c) |
|
| 165 | - $out .= ($oneliner ? "" : $pad) . $c . ($oneliner ? "" : "\n"); |
|
| 175 | + foreach ($this->content as $c) { |
|
| 176 | + $out .= ($oneliner ? "" : $pad) . $c . ($oneliner ? "" : "\n"); |
|
| 177 | + } |
|
| 166 | 178 | return $out; |
| 167 | 179 | } |
| 168 | 180 | |
@@ -36,14 +36,18 @@ |
||
| 36 | 36 | function getInputAttDynamic(&$atts, &$type, &$content) { |
| 37 | 37 | parent::getInputAttDynamic($atts, $type, $content); |
| 38 | 38 | $atts['value'] = "ON"; |
| 39 | - if ($this->getValue()) |
|
| 40 | - $atts['checked'] = "checked"; |
|
| 39 | + if ($this->getValue()) { |
|
| 40 | + $atts['checked'] = "checked"; |
|
| 41 | + } |
|
| 41 | 42 | } |
| 42 | 43 | |
| 43 | 44 | function getValue() { |
| 44 | - if (!is_null($this->setValue)) return $this->setValue; |
|
| 45 | - if (isset($_REQUEST[$this->form . "__submit"])) |
|
| 46 | - return isset($_REQUEST[$this->form . "_" . $this->name]); |
|
| 45 | + if (!is_null($this->setValue)) { |
|
| 46 | + return $this->setValue; |
|
| 47 | + } |
|
| 48 | + if (isset($_REQUEST[$this->form . "__submit"])) { |
|
| 49 | + return isset($_REQUEST[$this->form . "_" . $this->name]); |
|
| 50 | + } |
|
| 47 | 51 | return $this->opt['default']; |
| 48 | 52 | } |
| 49 | 53 | } |
| 50 | 54 | \ No newline at end of file |
@@ -41,7 +41,9 @@ discard block |
||
| 41 | 41 | public function cachePath($f) {
|
| 42 | 42 | $s = DIRECTORY_SEPARATOR; |
| 43 | 43 | $dir = implode($s,[__DIR__,"..","..","cache",""]); |
| 44 | - if(!is_dir($dir)) mkdir($dir); |
|
| 44 | + if(!is_dir($dir)) { |
|
| 45 | + mkdir($dir); |
|
| 46 | + } |
|
| 45 | 47 | return $dir.$f; |
| 46 | 48 | } |
| 47 | 49 | |
@@ -67,8 +69,9 @@ discard block |
||
| 67 | 69 | * @throws Exception\RunTime |
| 68 | 70 | */ |
| 69 | 71 | public function getModelTypeID($typeId, $sort = [], $limit = 0, $offset = 0) {
|
| 70 | - if(count($typeId) > 1) |
|
| 71 | - throw new Exception\RunTime("Unable to open more than one ID at a time");
|
|
| 72 | + if(count($typeId) > 1) { |
|
| 73 | + throw new Exception\RunTime("Unable to open more than one ID at a time"); |
|
| 74 | + } |
|
| 72 | 75 | return new Model\Zero(); |
| 73 | 76 | } |
| 74 | 77 | |
@@ -35,8 +35,9 @@ |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | function hamleGet($key) { |
| 38 | - if (!isset($this->data[$this->pos][$key])) |
|
| 39 | - return "Missing Key [$key]"; |
|
| 38 | + if (!isset($this->data[$this->pos][$key])) { |
|
| 39 | + return "Missing Key [$key]"; |
|
| 40 | + } |
|
| 40 | 41 | return $this->data[$this->pos][$key]; |
| 41 | 42 | } |
| 42 | 43 | |
@@ -81,13 +81,16 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | function __construct($baseModel, $setup = NULL) { |
| 83 | 83 | self::$me = $this; |
| 84 | - if(!$setup) |
|
| 85 | - $setup = new Setup(); |
|
| 84 | + if(!$setup) { |
|
| 85 | + $setup = new Setup(); |
|
| 86 | + } |
|
| 86 | 87 | $this->parse = new Parse(); |
| 87 | - if(!$setup instanceOf Setup) |
|
| 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"); |
|
| 88 | + if(!$setup instanceOf Setup) { |
|
| 89 | + throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup"); |
|
| 90 | + } |
|
| 91 | + if(!$baseModel instanceOf Model) { |
|
| 92 | + throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel"); |
|
| 93 | + } |
|
| 91 | 94 | $this->setup = $setup; |
| 92 | 95 | $this->baseModel = $baseModel; |
| 93 | 96 | $this->initSnipFiles(); |
@@ -97,7 +100,9 @@ discard block |
||
| 97 | 100 | if($this->snipMod == 0) { |
| 98 | 101 | $this->snipFiles = $this->setup->snippetFiles(); |
| 99 | 102 | foreach($this->snipFiles as $f) { |
| 100 | - if (!file_exists($f)) throw new Exception\NotFound("Unable to find Snippet File ($f)"); |
|
| 103 | + if (!file_exists($f)) { |
|
| 104 | + throw new Exception\NotFound("Unable to find Snippet File ($f)"); |
|
| 105 | + } |
|
| 101 | 106 | $this->snipFiles = max($this->snipFiles, filemtime($f)); |
| 102 | 107 | } |
| 103 | 108 | } |
@@ -111,8 +116,9 @@ discard block |
||
| 111 | 116 | */ |
| 112 | 117 | function load($hamleFile, \Closure $parseFunc = null) { |
| 113 | 118 | $template = $this->setup->templatePath($hamleFile); |
| 114 | - if(!file_exists($template)) |
|
| 115 | - throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
|
| 119 | + if(!file_exists($template)) { |
|
| 120 | + throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
|
| 121 | + } |
|
| 116 | 122 | $this->cacheFile = $this->setup->cachePath( |
| 117 | 123 | str_replace("/","-",$hamleFile).".php"); |
| 118 | 124 | $this->setup->debugLog("Set cache file path to ({$this->cacheFile})"); |
@@ -122,8 +128,9 @@ discard block |
||
| 122 | 128 | if($cacheDirty) { |
| 123 | 129 | $this->setup->debugLog("Parsing File ($template to {$this->cacheFile})"); |
| 124 | 130 | $this->parse($parseFunc?"":file_get_contents($template), $parseFunc); |
| 125 | - } else |
|
| 126 | - $this->setup->debugLog("Using Cached file ({$this->cacheFile})"); |
|
| 131 | + } else { |
|
| 132 | + $this->setup->debugLog("Using Cached file ({$this->cacheFile})"); |
|
| 133 | + } |
|
| 127 | 134 | return $this; |
| 128 | 135 | } |
| 129 | 136 | /** |
@@ -135,24 +142,29 @@ discard block |
||
| 135 | 142 | * @throws Exception\ParseError if unable to write to the cache file |
| 136 | 143 | */ |
| 137 | 144 | function parse($hamleCode, \Closure $parseFunc = null) { |
| 138 | - if(!$this->cacheFile) |
|
| 139 | - $this->cacheFile = $this->setup->cachePath("string.hamle.php"); |
|
| 140 | - if($parseFunc) |
|
| 141 | - $parseFunc($this->parse); |
|
| 142 | - else |
|
| 143 | - $this->parse->str($hamleCode); |
|
| 145 | + if(!$this->cacheFile) { |
|
| 146 | + $this->cacheFile = $this->setup->cachePath("string.hamle.php"); |
|
| 147 | + } |
|
| 148 | + if($parseFunc) { |
|
| 149 | + $parseFunc($this->parse); |
|
| 150 | + } else { |
|
| 151 | + $this->parse->str($hamleCode); |
|
| 152 | + } |
|
| 144 | 153 | $this->setup->debugLog("Loading Snippet Files"); |
| 145 | - foreach($this->snipFiles as $snip) |
|
| 146 | - $this->parse->parseSnip(file_get_contents($snip)); |
|
| 154 | + foreach($this->snipFiles as $snip) { |
|
| 155 | + $this->parse->parseSnip(file_get_contents($snip)); |
|
| 156 | + } |
|
| 147 | 157 | $this->setup->debugLog("Applying Snippet Files"); |
| 148 | 158 | $this->parse->applySnip(); |
| 149 | 159 | $this->setup->debugLog("Executing Parse Filters"); |
| 150 | - foreach($this->setup->getFilters() as $filter) |
|
| 151 | - $this->parse->parseFilter($filter); |
|
| 160 | + foreach($this->setup->getFilters() as $filter) { |
|
| 161 | + $this->parse->parseFilter($filter); |
|
| 162 | + } |
|
| 152 | 163 | $this->setup->debugLog("Updating Cache File ({$this->cacheFile})"); |
| 153 | - if(FALSE === file_put_contents($this->cacheFile, $this->parse->output())) |
|
| 154 | - throw new Exception\ParseError( |
|
| 164 | + if(FALSE === file_put_contents($this->cacheFile, $this->parse->output())) { |
|
| 165 | + throw new Exception\ParseError( |
|
| 155 | 166 | "Unable to write to cache file ({$this->cacheFile})"); |
| 167 | + } |
|
| 156 | 168 | } |
| 157 | 169 | |
| 158 | 170 | /** |
@@ -163,8 +175,9 @@ discard block |
||
| 163 | 175 | $md5 = md5($hamleString); |
| 164 | 176 | $stringId = substr($md5,0,12).substr($md5,24,8); |
| 165 | 177 | $this->cacheFile = $this->setup->cachePath("string.$stringId.hamle.php"); |
| 166 | - if(!is_file($this->cacheFile)) |
|
| 167 | - $this->parse($hamleString); |
|
| 178 | + if(!is_file($this->cacheFile)) { |
|
| 179 | + $this->parse($hamleString); |
|
| 180 | + } |
|
| 168 | 181 | } |
| 169 | 182 | |
| 170 | 183 | /** |
@@ -179,9 +192,13 @@ discard block |
||
| 179 | 192 | $baseModel = $this->baseModel; |
| 180 | 193 | $this->baseModel = null; |
| 181 | 194 | $currentModel = $baseModel == Scope::getTopScope(); |
| 182 | - if(!$currentModel && $baseModel) Scope::add($baseModel); |
|
| 195 | + if(!$currentModel && $baseModel) { |
|
| 196 | + Scope::add($baseModel); |
|
| 197 | + } |
|
| 183 | 198 | require $this->cacheFile; |
| 184 | - if(!$currentModel && $baseModel) Scope::done(); |
|
| 199 | + if(!$currentModel && $baseModel) { |
|
| 200 | + Scope::done(); |
|
| 201 | + } |
|
| 185 | 202 | $this->baseModel = $baseModel; |
| 186 | 203 | $out = ob_get_contents(); |
| 187 | 204 | ob_end_clean(); |
@@ -198,8 +215,9 @@ discard block |
||
| 198 | 215 | * @return int The line number being passed by the parser |
| 199 | 216 | */ |
| 200 | 217 | static function getLineNo() { |
| 201 | - if(!isset(self::$me)) |
|
| 202 | - return 0; |
|
| 218 | + if(!isset(self::$me)) { |
|
| 219 | + return 0; |
|
| 220 | + } |
|
| 203 | 221 | return self::$me->parse->getLineNo(); |
| 204 | 222 | } |
| 205 | 223 | |