@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Viewer; |
4 | 4 | |
5 | -trait HelperTrait{ |
|
5 | +trait HelperTrait { |
|
6 | 6 | use CheckTrait; |
7 | 7 | |
8 | 8 | protected function getOB(string $require): string |
@@ -12,15 +12,15 @@ discard block |
||
12 | 12 | $response = ob_get_contents(); |
13 | 13 | ob_end_clean(); |
14 | 14 | |
15 | - $response = explode(PHP_EOL,$response); |
|
16 | - foreach($response as $index => $value){ |
|
15 | + $response = explode(PHP_EOL, $response); |
|
16 | + foreach ($response as $index => $value) { |
|
17 | 17 | $response[$index] = ltrim($value); |
18 | 18 | } |
19 | 19 | |
20 | - return implode('',$response); |
|
20 | + return implode('', $response); |
|
21 | 21 | } |
22 | 22 | |
23 | - protected function getVars(string $buffer,string $prefix = null, ?array $values = null): string |
|
23 | + protected function getVars(string $buffer, string $prefix = null, ?array $values = null): string |
|
24 | 24 | { |
25 | 25 | $_SESSION['data'] = (empty($_SESSION['data'])) ? null : $_SESSION['data']; |
26 | 26 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | protected function replace_vars($buffer, $vars, $prefix): string |
33 | 33 | { |
34 | 34 | foreach ($vars as $key => $value) { |
35 | - switch(gettype($value)){ |
|
35 | + switch (gettype($value)) { |
|
36 | 36 | case 'array': |
37 | 37 | $buffer = $this->replace_Array($buffer, $value, $prefix, $key); |
38 | 38 | break; |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | |
51 | 51 | protected function replace_value(string $buffer, $value, string $prefix, string $key): string |
52 | 52 | { |
53 | - if(gettype($value)!=='array' && gettype($value)!=='object'){ |
|
54 | - while(strstr($buffer,'{{ '.$prefix.$key.' }}')){ |
|
55 | - $buffer = str_replace('{{ '.$prefix.$key.' }}', $value ,$buffer); |
|
53 | + if (gettype($value)!=='array' && gettype($value)!=='object') { |
|
54 | + while (strstr($buffer, '{{ '.$prefix.$key.' }}')) { |
|
55 | + $buffer = str_replace('{{ '.$prefix.$key.' }}', $value, $buffer); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | return $buffer; |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | |
61 | 61 | protected function replace_Object(string $buffer, object $obj, string $prefix, string $key): string |
62 | 62 | { |
63 | - foreach($obj->getFields() as $field => $val){ |
|
63 | + foreach ($obj->getFields() as $field => $val) { |
|
64 | 64 | |
65 | - $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field); |
|
65 | + $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field); |
|
66 | 66 | |
67 | - while(strstr($buffer,'{{ '.$prefix.$key.'.'.$field.' }}')){ |
|
68 | - $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}',$val[$field] ,$buffer); |
|
67 | + while (strstr($buffer, '{{ '.$prefix.$key.'.'.$field.' }}')) { |
|
68 | + $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}', $val[$field], $buffer); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | return $buffer; |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | |
74 | 74 | protected function replace_Array(string $buffer, array $array, string $prefix, string $key): string |
75 | 75 | { |
76 | - foreach($array as $field => $val){ |
|
77 | - $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field); |
|
76 | + foreach ($array as $field => $val) { |
|
77 | + $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field); |
|
78 | 78 | |
79 | - while(strstr($buffer,'{{ '.$prefix.$key.'.'.$field.' }}')){ |
|
80 | - $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}',$val,$buffer); |
|
79 | + while (strstr($buffer, '{{ '.$prefix.$key.'.'.$field.' }}')) { |
|
80 | + $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}', $val, $buffer); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | return $buffer; |
@@ -85,39 +85,39 @@ discard block |
||
85 | 85 | |
86 | 86 | protected function removeComments(string $buffer): string |
87 | 87 | { |
88 | - while(strstr($buffer,'<!--')){ |
|
88 | + while (strstr($buffer, '<!--')) { |
|
89 | 89 | $comment = substr( |
90 | 90 | $buffer, |
91 | - strpos($buffer,'<!--'), |
|
92 | - strpos(strstr($buffer,'<!--'),'-->')+3 |
|
91 | + strpos($buffer, '<!--'), |
|
92 | + strpos(strstr($buffer, '<!--'), '-->')+3 |
|
93 | 93 | ); |
94 | - $buffer = str_replace($comment,'',$buffer); |
|
94 | + $buffer = str_replace($comment, '', $buffer); |
|
95 | 95 | } |
96 | 96 | return $buffer; |
97 | 97 | } |
98 | 98 | |
99 | 99 | protected function getImport(string $buffer): string |
100 | 100 | { |
101 | - while(strstr($buffer,'@import')){ |
|
101 | + while (strstr($buffer, '@import')) { |
|
102 | 102 | $buffer = $this->getVars($buffer); |
103 | 103 | |
104 | 104 | $import = substr( |
105 | 105 | $buffer, |
106 | - strpos($buffer,'@import(\''), |
|
107 | - strpos(strstr($buffer,'@import'),'\')')+2 |
|
106 | + strpos($buffer, '@import(\''), |
|
107 | + strpos(strstr($buffer, '@import'), '\')')+2 |
|
108 | 108 | ); |
109 | 109 | |
110 | 110 | $tpl = $this->check_importExist($import); |
111 | 111 | |
112 | - try{ |
|
113 | - $buffer_tpl = $this->getOB($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php'); |
|
114 | - }catch(\Exception $er){ |
|
112 | + try { |
|
113 | + $buffer_tpl = $this->getOB($this->path.DIRECTORY_SEPARATOR.$tpl.'.tpl.php'); |
|
114 | + }catch (\Exception $er) { |
|
115 | 115 | var_dump($er); |
116 | 116 | die(); |
117 | 117 | } |
118 | 118 | |
119 | 119 | $buffer_tpl = $this->getVars($buffer_tpl); |
120 | - $buffer = str_replace($import,$buffer_tpl,$buffer); |
|
120 | + $buffer = str_replace($import, $buffer_tpl, $buffer); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | return $buffer; |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | |
126 | 126 | protected function saveData(): bool |
127 | 127 | { |
128 | - if(session_status() !== PHP_SESSION_ACTIVE){ |
|
128 | + if (session_status()!==PHP_SESSION_ACTIVE) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | unset($_SESSION['data']); |
132 | 132 | |
133 | - if(!empty($_SESSION['save'])){ |
|
133 | + if (!empty($_SESSION['save'])) { |
|
134 | 134 | foreach ($_SESSION['save'] as $key => $value) { |
135 | 135 | $_SESSION['data'][$key] = $value; |
136 | 136 | } |