@@ -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; |
@@ -44,8 +44,9 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | function toHTML($escape = false) { |
47 | - if($escape) |
|
48 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
47 | + if($escape) { |
|
48 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
49 | + } |
|
49 | 50 | return "<?=" . $this->toPHP() . "?>"; |
50 | 51 | } |
51 | 52 | |
@@ -67,8 +68,9 @@ discard block |
||
67 | 68 | */ |
68 | 69 | function setValue($value) { |
69 | 70 | $model = $this->getOrCreateModel(); |
70 | - if(!$model instanceof WriteModel) |
|
71 | - throw new \RuntimeException('Can only write to model that implements WriteModel'); |
|
71 | + if(!$model instanceof WriteModel) { |
|
72 | + throw new \RuntimeException('Can only write to model that implements WriteModel'); |
|
73 | + } |
|
72 | 74 | $model->hamleSet($this->var, $value); |
73 | 75 | return $model; |
74 | 76 | } |
@@ -54,10 +54,11 @@ discard block |
||
54 | 54 | */ |
55 | 55 | static function popInstance() { |
56 | 56 | array_pop(self::$hamleList); |
57 | - if (self::$hamleList) |
|
58 | - self::$hamle = self::$hamleList[count(self::$hamleList) - 1]; |
|
59 | - else |
|
60 | - self::$hamle = NULL; |
|
57 | + if (self::$hamleList) { |
|
58 | + self::$hamle = self::$hamleList[count(self::$hamleList) - 1]; |
|
59 | + } else { |
|
60 | + self::$hamle = NULL; |
|
61 | + } |
|
61 | 62 | } |
62 | 63 | |
63 | 64 | /** |
@@ -113,7 +114,9 @@ discard block |
||
113 | 114 | */ |
114 | 115 | static function modelId($id, $sort = [], $limit = 0, $offset = 0) { |
115 | 116 | $o = self::$hamle->setup->getModelDefault($id, $sort, $limit, $offset); |
116 | - if (!$o instanceOf Model) throw new RunTime("Application must return instance of hamleModel"); |
|
117 | + if (!$o instanceOf Model) { |
|
118 | + throw new RunTime("Application must return instance of hamleModel"); |
|
119 | + } |
|
117 | 120 | return $o; |
118 | 121 | } |
119 | 122 |
@@ -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 | } |
@@ -39,17 +39,25 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct($s) { |
41 | 41 | $m = array(); |
42 | - if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) |
|
43 | - throw new ParseError("Unable to read \$ sub func in '$s'"); |
|
44 | - if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT; |
|
45 | - elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD; |
|
46 | - else $this->dir = Hamle\Hamle::REL_ANY; |
|
42 | + if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) { |
|
43 | + throw new ParseError("Unable to read \$ sub func in '$s'"); |
|
44 | + } |
|
45 | + if ($m[1] == "<") { |
|
46 | + $this->dir = Hamle\Hamle::REL_PARENT; |
|
47 | + } elseif ($m[1] == ">") { |
|
48 | + $this->dir = Hamle\Hamle::REL_CHILD; |
|
49 | + } else { |
|
50 | + $this->dir = Hamle\Hamle::REL_ANY; |
|
51 | + } |
|
47 | 52 | $this->sortlimit = $this->attSortLimit($m[2]); |
48 | 53 | $this->filt = $this->attIdTag($m[2]); |
49 | 54 | $this->grouptype = $this->attGroupType($m[2]); |
50 | - if ($this->filt['id']) throw new ParseError("Unable to select by id"); |
|
51 | - if (trim($m[3])) |
|
52 | - $this->sub = new FuncSub($m[3]); |
|
55 | + if ($this->filt['id']) { |
|
56 | + throw new ParseError("Unable to select by id"); |
|
57 | + } |
|
58 | + if (trim($m[3])) { |
|
59 | + $this->sub = new FuncSub($m[3]); |
|
60 | + } |
|
53 | 61 | } |
54 | 62 | |
55 | 63 | /** |
@@ -69,13 +77,15 @@ discard block |
||
69 | 77 | $model = $parent->hamleRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'], |
70 | 78 | $this->sortlimit['limit'], $this->sortlimit['offset']); |
71 | 79 | if(!$model->valid()) { |
72 | - if(!$parent instanceof Hamle\WriteModel) |
|
73 | - throw new \Exception('Cant create model, ' . get_class($parent) . ' must implement Hamle\\WriteModel.'); |
|
80 | + if(!$parent instanceof Hamle\WriteModel) { |
|
81 | + throw new \Exception('Cant create model, ' . get_class($parent) . ' must implement Hamle\\WriteModel.'); |
|
82 | + } |
|
74 | 83 | $model = $parent->current()->hamleCreateRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'], |
75 | 84 | $this->sortlimit['limit'], $this->sortlimit['offset']); |
76 | 85 | } |
77 | - if($this->sub) |
|
78 | - return $this->sub->getOrCreateModel($model)->current(); |
|
86 | + if($this->sub) { |
|
87 | + return $this->sub->getOrCreateModel($model)->current(); |
|
88 | + } |
|
79 | 89 | return $model->current(); |
80 | 90 | } |
81 | 91 |
@@ -41,47 +41,47 @@ 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(method_exists(Filter::class, $this->filter)) { |
|
55 | + if (method_exists(Filter::class, $this->filter)) { |
|
56 | 56 | $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}"; |
57 | - } elseif(!in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst', 'json'])) { |
|
57 | + } elseif (!in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst', 'json'])) { |
|
58 | 58 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
59 | 59 | } |
60 | 60 | $mapFilter = ['json'=>'json_encode']; |
61 | - if(isset($mapFilter[$this->filter])) |
|
61 | + if (isset($mapFilter[$this->filter])) |
|
62 | 62 | $this->filter = $mapFilter[$this->filter]; |
63 | 63 | $this->what = $what; |
64 | 64 | } |
65 | 65 | |
66 | 66 | function toHTML($escape = false) { |
67 | - if($escape) |
|
68 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
69 | - return "<?=" . $this->toPHP() . "?>"; |
|
67 | + if ($escape) |
|
68 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
69 | + return "<?=".$this->toPHP()."?>"; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | function toPHPpre() { |
73 | 73 | $pre = ''; |
74 | - if($this->chained) |
|
74 | + if ($this->chained) |
|
75 | 75 | $pre = $this->chained->toPHPpre(); |
76 | 76 | return "$pre{$this->filter}("; |
77 | 77 | } |
78 | 78 | |
79 | 79 | function toPHPpost() { |
80 | 80 | $post = ''; |
81 | - if($this->chained) |
|
81 | + if ($this->chained) |
|
82 | 82 | $post = $this->chained->toPHPpost(); |
83 | 83 | $o = ''; |
84 | - foreach($this->vars as $v) |
|
84 | + foreach ($this->vars as $v) |
|
85 | 85 | $o .= ','.$this->varToCode($v); |
86 | 86 | return "$o)$post"; |
87 | 87 | } |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | |
97 | 97 | static function itersplit($v, $sep = ",") { |
98 | 98 | $o = []; |
99 | - foreach(explode($sep, $v) as $k=>$i) { |
|
100 | - if($i) |
|
101 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
99 | + foreach (explode($sep, $v) as $k=>$i) { |
|
100 | + if ($i) |
|
101 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k]; |
|
102 | 102 | } |
103 | 103 | return new WrapArray($o); |
104 | 104 | } |
105 | 105 | |
106 | 106 | static function newlinebr($v) { |
107 | - return str_replace("\n","<br />\n",$v); |
|
107 | + return str_replace("\n", "<br />\n", $v); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | static function replace($v, $src, $dst) { |
111 | - return str_replace($src,$dst,$v); |
|
111 | + return str_replace($src, $dst, $v); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | static function ascents($v) { |
115 | - $v = str_replace(['$',' ',','],'', $v); |
|
116 | - return (int) round($v * 100,0); |
|
115 | + $v = str_replace(['$', ' ', ','], '', $v); |
|
116 | + return (int) round($v * 100, 0); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | } |
120 | 120 | \ No newline at end of file |
@@ -44,8 +44,9 @@ discard block |
||
44 | 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); |
|
47 | + foreach($this->vars as $k=>$v) { |
|
48 | + $this->vars[$k] = str_replace(",",',',$v); |
|
49 | + } |
|
49 | 50 | if(isset($m['chained']) && strlen($m['chained'])) { |
50 | 51 | $this->chained = new Filter($m['chained'],$what); |
51 | 52 | } |
@@ -58,31 +59,36 @@ discard block |
||
58 | 59 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
59 | 60 | } |
60 | 61 | $mapFilter = ['json'=>'json_encode']; |
61 | - if(isset($mapFilter[$this->filter])) |
|
62 | - $this->filter = $mapFilter[$this->filter]; |
|
62 | + if(isset($mapFilter[$this->filter])) { |
|
63 | + $this->filter = $mapFilter[$this->filter]; |
|
64 | + } |
|
63 | 65 | $this->what = $what; |
64 | 66 | } |
65 | 67 | |
66 | 68 | function toHTML($escape = false) { |
67 | - if($escape) |
|
68 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
69 | + if($escape) { |
|
70 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
71 | + } |
|
69 | 72 | return "<?=" . $this->toPHP() . "?>"; |
70 | 73 | } |
71 | 74 | |
72 | 75 | function toPHPpre() { |
73 | 76 | $pre = ''; |
74 | - if($this->chained) |
|
75 | - $pre = $this->chained->toPHPpre(); |
|
77 | + if($this->chained) { |
|
78 | + $pre = $this->chained->toPHPpre(); |
|
79 | + } |
|
76 | 80 | return "$pre{$this->filter}("; |
77 | 81 | } |
78 | 82 | |
79 | 83 | function toPHPpost() { |
80 | 84 | $post = ''; |
81 | - if($this->chained) |
|
82 | - $post = $this->chained->toPHPpost(); |
|
85 | + if($this->chained) { |
|
86 | + $post = $this->chained->toPHPpost(); |
|
87 | + } |
|
83 | 88 | $o = ''; |
84 | - foreach($this->vars as $v) |
|
85 | - $o .= ','.$this->varToCode($v); |
|
89 | + foreach($this->vars as $v) { |
|
90 | + $o .= ','.$this->varToCode($v); |
|
91 | + } |
|
86 | 92 | return "$o)$post"; |
87 | 93 | } |
88 | 94 | |
@@ -97,8 +103,9 @@ discard block |
||
97 | 103 | static function itersplit($v, $sep = ",") { |
98 | 104 | $o = []; |
99 | 105 | foreach(explode($sep, $v) as $k=>$i) { |
100 | - if($i) |
|
101 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
106 | + if($i) { |
|
107 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
108 | + } |
|
102 | 109 | } |
103 | 110 | return new WrapArray($o); |
104 | 111 | } |
@@ -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($this->setup->getMinify()))) |
|
153 | + if (FALSE === file_put_contents($this->cacheFile, $this->parse->output($this->setup->getMinify()))) |
|
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 | |
@@ -183,9 +183,9 @@ discard block |
||
183 | 183 | $baseModel = $this->baseModel; |
184 | 184 | $this->baseModel = null; |
185 | 185 | $currentModel = $baseModel == Scope::getTopScope(); |
186 | - if(!$currentModel && $baseModel) Scope::add($baseModel); |
|
186 | + if (!$currentModel && $baseModel) Scope::add($baseModel); |
|
187 | 187 | require $this->cacheFile; |
188 | - if(!$currentModel && $baseModel) Scope::done(); |
|
188 | + if (!$currentModel && $baseModel) Scope::done(); |
|
189 | 189 | $this->baseModel = $baseModel; |
190 | 190 | $out = ob_get_contents(); |
191 | 191 | ob_end_clean(); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @return int The line number being passed by the parser |
203 | 203 | */ |
204 | 204 | static function getLineNo() { |
205 | - if(!isset(self::$me)) |
|
205 | + if (!isset(self::$me)) |
|
206 | 206 | return 0; |
207 | 207 | return self::$me->parse->getLineNo(); |
208 | 208 | } |
@@ -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($this->setup->getMinify()))) |
|
154 | - throw new Exception\ParseError( |
|
164 | + if(FALSE === file_put_contents($this->cacheFile, $this->parse->output($this->setup->getMinify()))) { |
|
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 | function getCacheFileName() { |
@@ -183,9 +196,13 @@ discard block |
||
183 | 196 | $baseModel = $this->baseModel; |
184 | 197 | $this->baseModel = null; |
185 | 198 | $currentModel = $baseModel == Scope::getTopScope(); |
186 | - if(!$currentModel && $baseModel) Scope::add($baseModel); |
|
199 | + if(!$currentModel && $baseModel) { |
|
200 | + Scope::add($baseModel); |
|
201 | + } |
|
187 | 202 | require $this->cacheFile; |
188 | - if(!$currentModel && $baseModel) Scope::done(); |
|
203 | + if(!$currentModel && $baseModel) { |
|
204 | + Scope::done(); |
|
205 | + } |
|
189 | 206 | $this->baseModel = $baseModel; |
190 | 207 | $out = ob_get_contents(); |
191 | 208 | ob_end_clean(); |
@@ -202,8 +219,9 @@ discard block |
||
202 | 219 | * @return int The line number being passed by the parser |
203 | 220 | */ |
204 | 221 | static function getLineNo() { |
205 | - if(!isset(self::$me)) |
|
206 | - return 0; |
|
222 | + if(!isset(self::$me)) { |
|
223 | + return 0; |
|
224 | + } |
|
207 | 225 | return self::$me->parse->getLineNo(); |
208 | 226 | } |
209 | 227 |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | */ |
48 | 48 | function __construct($tag, $parentTag = null) { |
49 | 49 | parent::__construct(); |
50 | - $this->o = "\$o" . self::$instCount++; |
|
50 | + $this->o = "\$o".self::$instCount++; |
|
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; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | function renderStTag() { |
70 | - $out = "<" . "?php "; |
|
70 | + $out = "<"."?php "; |
|
71 | 71 | $scopeName = ""; |
72 | 72 | if (preg_match('/ as ([a-zA-Z]+)$/', $this->var, $m)) { |
73 | 73 | $scopeName = $m[1]; |
@@ -78,20 +78,20 @@ discard block |
||
78 | 78 | switch ($this->type) { |
79 | 79 | case "each": |
80 | 80 | if ($this->var) |
81 | - $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
81 | + $out .= "foreach(".$hsv->toPHP()." as {$this->o}) { \n"; |
|
82 | 82 | else |
83 | 83 | $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
84 | 84 | $out .= "Hamle\\Scope::add({$this->o}); "; |
85 | 85 | break; |
86 | 86 | case "if": |
87 | 87 | $hsvcomp = new H\Text\Comparison($this->var); |
88 | - $out .= "if(" . $hsvcomp->toPHP() . ") {"; |
|
88 | + $out .= "if(".$hsvcomp->toPHP().") {"; |
|
89 | 89 | break; |
90 | 90 | case "with": |
91 | 91 | if ($scopeName) |
92 | - $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
92 | + $out .= "Hamle\\Scope::add(".$hsv->toPHP().", \"$scopeName\");\n;"; |
|
93 | 93 | else { |
94 | - $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " . |
|
94 | + $out .= "if(({$this->o} = ".$hsv->toPHP().") && ". |
|
95 | 95 | "{$this->o}->valid()) {\n"; |
96 | 96 | $out .= "Hamle\\Scope::add({$this->o});\n;"; |
97 | 97 | } |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | break; |
102 | 102 | case "include": |
103 | 103 | $file = $hsv->toHTML(); |
104 | - if($file[0] == "#") |
|
104 | + if ($file[0] == "#") |
|
105 | 105 | $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
106 | 106 | else |
107 | - $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
107 | + $out .= "echo Hamle\\Run::includeFile(".$hsv->toPHP().");"; |
|
108 | 108 | break; |
109 | 109 | } |
110 | - return $out . "\n?>"; |
|
110 | + return $out."\n?>"; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | function renderEnTag() { |
121 | - $out = '<' . '?php '; |
|
121 | + $out = '<'.'?php '; |
|
122 | 122 | switch ($this->type) { |
123 | 123 | case "each"; |
124 | 124 | $out .= 'Hamle\\Scope::done(); '; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | break; |
142 | 142 | } |
143 | 143 | if ($this->else) $out .= "else{"; |
144 | - return $out . "\n?>"; |
|
144 | + return $out."\n?>"; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | function render($indent = 0, $minify = false) { |
@@ -73,14 +73,16 @@ discard block |
||
73 | 73 | $scopeName = $m[1]; |
74 | 74 | $lookup = substr($this->var, 0, strlen($this->var) - strlen($m[0])); |
75 | 75 | $hsv = new H\Text(trim($lookup), H\Text::TOKEN_CONTROL); |
76 | - } else |
|
77 | - $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL); |
|
76 | + } else { |
|
77 | + $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL); |
|
78 | + } |
|
78 | 79 | switch ($this->type) { |
79 | 80 | case "each": |
80 | - if ($this->var) |
|
81 | - $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
82 | - else |
|
83 | - $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
|
81 | + if ($this->var) { |
|
82 | + $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
83 | + } else { |
|
84 | + $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
|
85 | + } |
|
84 | 86 | $out .= "Hamle\\Scope::add({$this->o}); "; |
85 | 87 | break; |
86 | 88 | case "if": |
@@ -88,9 +90,9 @@ discard block |
||
88 | 90 | $out .= "if(" . $hsvcomp->toPHP() . ") {"; |
89 | 91 | break; |
90 | 92 | case "with": |
91 | - if ($scopeName) |
|
92 | - $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
93 | - else { |
|
93 | + if ($scopeName) { |
|
94 | + $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
95 | + } else { |
|
94 | 96 | $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " . |
95 | 97 | "{$this->o}->valid()) {\n"; |
96 | 98 | $out .= "Hamle\\Scope::add({$this->o});\n;"; |
@@ -101,10 +103,11 @@ discard block |
||
101 | 103 | break; |
102 | 104 | case "include": |
103 | 105 | $file = $hsv->toHTML(); |
104 | - if($file[0] == "#") |
|
105 | - $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
106 | - else |
|
107 | - $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
106 | + if($file[0] == "#") { |
|
107 | + $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
108 | + } else { |
|
109 | + $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
110 | + } |
|
108 | 111 | break; |
109 | 112 | } |
110 | 113 | return $out . "\n?>"; |
@@ -123,8 +126,9 @@ discard block |
||
123 | 126 | case "each"; |
124 | 127 | $out .= 'Hamle\\Scope::done(); '; |
125 | 128 | $out .= '}'; |
126 | - if (!$this->var) |
|
127 | - $out .= "Hamle\\Scope::get()->rewind();\n"; |
|
129 | + if (!$this->var) { |
|
130 | + $out .= "Hamle\\Scope::get()->rewind();\n"; |
|
131 | + } |
|
128 | 132 | break; |
129 | 133 | case "if": |
130 | 134 | case "else": |
@@ -140,7 +144,9 @@ discard block |
||
140 | 144 | return ""; |
141 | 145 | break; |
142 | 146 | } |
143 | - if ($this->else) $out .= "else{"; |
|
147 | + if ($this->else) { |
|
148 | + $out .= "else{"; |
|
149 | + } |
|
144 | 150 | return $out . "\n?>"; |
145 | 151 | } |
146 | 152 | |
@@ -148,9 +154,12 @@ discard block |
||
148 | 154 | $ind = $minify ? '' : str_pad('', $indent); |
149 | 155 | $oneliner = (!(count($this->content) > 1 || $this->tags)); |
150 | 156 | $out = $this->renderStTag(); |
151 | - if ($this->content) $out .= $this->renderContent($ind, $oneliner || $minify); |
|
152 | - foreach ($this->tags as $tag) |
|
153 | - $out .= $tag->render($indent, $minify); |
|
157 | + if ($this->content) { |
|
158 | + $out .= $this->renderContent($ind, $oneliner || $minify); |
|
159 | + } |
|
160 | + foreach ($this->tags as $tag) { |
|
161 | + $out .= $tag->render($indent, $minify); |
|
162 | + } |
|
154 | 163 | $out .= $this->renderEnTag(); |
155 | 164 | return $out; |
156 | 165 | } |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | function render($indent = 0, $minify = false) { |
144 | 144 | $ind = $minify ? '' : str_pad('', $indent); |
145 | 145 | $oneliner = (!(count($this->content) > 1 || $this->tags)); |
146 | - $out = $ind . $this->renderStTag() . ($oneliner || $minify ? '' : "\n"); |
|
146 | + $out = $ind.$this->renderStTag().($oneliner || $minify ? '' : "\n"); |
|
147 | 147 | if ($this->content) $out .= $this->renderContent($ind, $oneliner || $minify); |
148 | 148 | foreach ($this->tags as $tag) |
149 | 149 | $out .= $tag->render($indent + self::INDENT_SIZE, $minify); |
150 | - $out .= ($minify || $oneliner ? '' : $ind) . $this->renderEnTag() . ($minify ? '' : "\n"); |
|
150 | + $out .= ($minify || $oneliner ? '' : $ind).$this->renderEnTag().($minify ? '' : "\n"); |
|
151 | 151 | return $out; |
152 | 152 | } |
153 | 153 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | function renderContent($pad = "", $oneliner = false) { |
162 | 162 | $out = ""; |
163 | 163 | foreach ($this->content as $c) |
164 | - $out .= ($oneliner ? '' : $pad) . $c . ($oneliner ? '' : "\n"); |
|
164 | + $out .= ($oneliner ? '' : $pad).$c.($oneliner ? '' : "\n"); |
|
165 | 165 | return $out; |
166 | 166 | } |
167 | 167 |
@@ -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 | /** |
@@ -144,9 +152,12 @@ discard block |
||
144 | 152 | $ind = $minify ? '' : str_pad('', $indent); |
145 | 153 | $oneliner = (!(count($this->content) > 1 || $this->tags)); |
146 | 154 | $out = $ind . $this->renderStTag() . ($oneliner || $minify ? '' : "\n"); |
147 | - if ($this->content) $out .= $this->renderContent($ind, $oneliner || $minify); |
|
148 | - foreach ($this->tags as $tag) |
|
149 | - $out .= $tag->render($indent + self::INDENT_SIZE, $minify); |
|
155 | + if ($this->content) { |
|
156 | + $out .= $this->renderContent($ind, $oneliner || $minify); |
|
157 | + } |
|
158 | + foreach ($this->tags as $tag) { |
|
159 | + $out .= $tag->render($indent + self::INDENT_SIZE, $minify); |
|
160 | + } |
|
150 | 161 | $out .= ($minify || $oneliner ? '' : $ind) . $this->renderEnTag() . ($minify ? '' : "\n"); |
151 | 162 | return $out; |
152 | 163 | } |
@@ -160,8 +171,9 @@ discard block |
||
160 | 171 | */ |
161 | 172 | function renderContent($pad = "", $oneliner = false) { |
162 | 173 | $out = ""; |
163 | - foreach ($this->content as $c) |
|
164 | - $out .= ($oneliner ? '' : $pad) . $c . ($oneliner ? '' : "\n"); |
|
174 | + foreach ($this->content as $c) { |
|
175 | + $out .= ($oneliner ? '' : $pad) . $c . ($oneliner ? '' : "\n"); |
|
176 | + } |
|
165 | 177 | return $out; |
166 | 178 | } |
167 | 179 |
@@ -61,8 +61,7 @@ discard block |
||
61 | 61 | if($mode === self::TOKEN_CONTROL) { |
62 | 62 | if(preg_match('/^"(.*)"$/', trim($s), $m)) { |
63 | 63 | $this->nodes[] = new Text($m[1]); |
64 | - } |
|
65 | - else { |
|
64 | + } else { |
|
66 | 65 | $this->nodes[] = new Text\Complex(trim($s)); |
67 | 66 | } |
68 | 67 | return; |
@@ -76,8 +75,7 @@ discard block |
||
76 | 75 | } |
77 | 76 | $this->nodes[] = new Text\Complex(substr($match[2][0], 1, -1)); |
78 | 77 | $pos = $match[2][1] + strlen($match[2][0]); |
79 | - } |
|
80 | - else if($mode & self::FIND_DOLLARVAR) { |
|
78 | + } else if($mode & self::FIND_DOLLARVAR) { |
|
81 | 79 | if($match[1][1] > 0 && $s[$match[1][1] - 1] === '\\') { |
82 | 80 | continue; |
83 | 81 | } |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | $pos = 0; |
55 | 55 | $this->nodes = []; |
56 | 56 | $rFlag = PREG_OFFSET_CAPTURE + PREG_SET_ORDER; |
57 | - if(trim($s) === '') { |
|
57 | + if (trim($s) === '') { |
|
58 | 58 | $this->nodes[] = new Text\Plain($s, $mode); |
59 | 59 | return; |
60 | 60 | } |
61 | - if($mode === self::TOKEN_CONTROL) { |
|
62 | - if(preg_match('/^"(.*)"$/', trim($s), $m)) { |
|
61 | + if ($mode === self::TOKEN_CONTROL) { |
|
62 | + if (preg_match('/^"(.*)"$/', trim($s), $m)) { |
|
63 | 63 | $this->nodes[] = new Text($m[1]); |
64 | 64 | } |
65 | 65 | else { |
@@ -68,20 +68,20 @@ discard block |
||
68 | 68 | return; |
69 | 69 | } |
70 | 70 | preg_match_all(self::REGEX_HTML, $s, $m, $rFlag); |
71 | - foreach($m as $match) { |
|
72 | - if($mode & self::FIND_BARDOLLAR && isset($match[2])) { |
|
73 | - if($match[2][1] != $pos) { |
|
71 | + foreach ($m as $match) { |
|
72 | + if ($mode & self::FIND_BARDOLLAR && isset($match[2])) { |
|
73 | + if ($match[2][1] != $pos) { |
|
74 | 74 | $this->nodes[] = new Text\Plain( |
75 | 75 | substr($s, $pos, $match[2][1] - $pos), $mode); |
76 | 76 | } |
77 | 77 | $this->nodes[] = new Text\Complex(substr($match[2][0], 1, -1)); |
78 | 78 | $pos = $match[2][1] + strlen($match[2][0]); |
79 | 79 | } |
80 | - else if($mode & self::FIND_DOLLARVAR) { |
|
81 | - if($match[1][1] > 0 && $s[$match[1][1] - 1] === '\\') { |
|
80 | + else if ($mode & self::FIND_DOLLARVAR) { |
|
81 | + if ($match[1][1] > 0 && $s[$match[1][1] - 1] === '\\') { |
|
82 | 82 | continue; |
83 | 83 | } |
84 | - if($match[1][1] != $pos) { |
|
84 | + if ($match[1][1] != $pos) { |
|
85 | 85 | $this->nodes[] = new Text\Plain( |
86 | 86 | substr($s, $pos, $match[1][1] - $pos), $mode); |
87 | 87 | } |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | $pos = $match[1][1] + strlen($match[1][0]); |
90 | 90 | } |
91 | 91 | } |
92 | - if($pos != strlen($s)) { |
|
92 | + if ($pos != strlen($s)) { |
|
93 | 93 | $this->nodes[] = new Text\Plain(substr($s, $pos), $mode); |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | 97 | function toHTML($escape = false) { |
98 | 98 | $out = []; |
99 | - foreach($this->nodes as $string) { |
|
99 | + foreach ($this->nodes as $string) { |
|
100 | 100 | $out[] = $string->toHTML($escape); |
101 | 101 | } |
102 | 102 | return implode('', $out); |
@@ -108,34 +108,34 @@ discard block |
||
108 | 108 | |
109 | 109 | function toPHP() { |
110 | 110 | $out = []; |
111 | - foreach($this->nodes as $string) { |
|
111 | + foreach ($this->nodes as $string) { |
|
112 | 112 | $out[] = $string->toPHP(); |
113 | 113 | } |
114 | 114 | return implode(".", $out); |
115 | 115 | } |
116 | 116 | |
117 | 117 | function doEval() { |
118 | - return eval('use Seufert\Hamle; return ' . $this->toPHP() . ';'); |
|
118 | + return eval('use Seufert\Hamle; return '.$this->toPHP().';'); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | static function varToCode($var) { |
122 | - if(is_array($var)) { |
|
122 | + if (is_array($var)) { |
|
123 | 123 | $code = []; |
124 | - foreach($var as $key => $value) { |
|
125 | - $code[] = self::varToCode($key) . '=>' . self::varToCode($value); |
|
124 | + foreach ($var as $key => $value) { |
|
125 | + $code[] = self::varToCode($key).'=>'.self::varToCode($value); |
|
126 | 126 | } |
127 | - return 'array(' . implode(',', $code) . ')'; //remove unnecessary coma |
|
127 | + return 'array('.implode(',', $code).')'; //remove unnecessary coma |
|
128 | 128 | } |
129 | - if(is_bool($var)) { |
|
129 | + if (is_bool($var)) { |
|
130 | 130 | return ($var ? 'TRUE' : 'FALSE'); |
131 | 131 | } |
132 | - if(is_int($var) || is_float($var) || is_numeric($var)) { |
|
132 | + if (is_int($var) || is_float($var) || is_numeric($var)) { |
|
133 | 133 | return $var; |
134 | 134 | } |
135 | - if($var instanceof Text) { |
|
135 | + if ($var instanceof Text) { |
|
136 | 136 | return $var->toPHP(); |
137 | 137 | } |
138 | - return "'" . str_replace(['$', "'"], ['$', "\\'"], $var) . "'"; |
|
138 | + return "'".str_replace(['$', "'"], ['$', "\\'"], $var)."'"; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |