@@ -9,11 +9,11 @@ |
||
9 | 9 | |
10 | 10 | /* NOTE: in case of error an exception is thrown */ |
11 | 11 | |
12 | -try{ |
|
12 | +try { |
|
13 | 13 | |
14 | 14 | Router::create()->dispatch(); |
15 | 15 | |
16 | -}catch(Exception $er){ |
|
16 | +}catch (Exception $er) { |
|
17 | 17 | |
18 | 18 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
19 | 19 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | |
14 | 14 | Router::create()->dispatch(); |
15 | 15 | |
16 | -}catch(Exception $er){ |
|
16 | +} catch(Exception $er){ |
|
17 | 17 | |
18 | 18 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
19 | 19 |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace Example\Controllers; |
4 | 4 | |
5 | -class User{ |
|
5 | +class User { |
|
6 | 6 | |
7 | 7 | public function my_account(array $data): void |
8 | 8 | { |
@@ -2,15 +2,15 @@ |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Filter; |
4 | 4 | |
5 | -class User extends Filter{ |
|
5 | +class User extends Filter { |
|
6 | 6 | |
7 | 7 | public function user_in(): bool |
8 | 8 | { |
9 | - $this->addMessage('user_in','User required to be logged in.'); |
|
9 | + $this->addMessage('user_in', 'User required to be logged in.'); |
|
10 | 10 | |
11 | - $this->addTreat('user_in','report_notLogged'); |
|
11 | + $this->addTreat('user_in', 'report_notLogged'); |
|
12 | 12 | |
13 | - return (array_key_exists('user',$_SESSION)); |
|
13 | + return (array_key_exists('user', $_SESSION)); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | public function report_notLogged(): void |
@@ -3,30 +3,30 @@ |
||
3 | 3 | use HnrAzevedo\Router\Router; |
4 | 4 | |
5 | 5 | |
6 | -Router::get('/{teste}',function(){ |
|
6 | +Router::get('/{teste}', function() { |
|
7 | 7 | echo 'teste'; |
8 | 8 | }); |
9 | 9 | |
10 | -Router::get('/1',function(){ |
|
10 | +Router::get('/1', function() { |
|
11 | 11 | echo 1; |
12 | 12 | }); |
13 | 13 | |
14 | -Router::get('/3',function(){ |
|
14 | +Router::get('/3', function() { |
|
15 | 15 | echo 3; |
16 | 16 | }); |
17 | 17 | |
18 | 18 | /* Returning parameters passed via URL in anonymous functions */ |
19 | -Router::get('/{parameter}/{otherparameter}', function($data){ |
|
19 | +Router::get('/{parameter}/{otherparameter}', function($data) { |
|
20 | 20 | echo "Parameter 1:{$data['parameter']}, Parameter 2:{$data['otherparameter']}."; |
21 | 21 | }); |
22 | 22 | |
23 | 23 | /* Passing controller and/or method via parameter in URL */ |
24 | -Router::get('/{controller}/{method}','{controller}:{method}'); |
|
24 | +Router::get('/{controller}/{method}', '{controller}:{method}'); |
|
25 | 25 | |
26 | 26 | /* Passing value via parameter */ |
27 | -Router::get('/my-account/{teste}','User:my_account'); |
|
27 | +Router::get('/my-account/{teste}', 'User:my_account'); |
|
28 | 28 | |
29 | 29 | /* Filter example */ |
30 | -Router::get('/my-account','User:my_account')->filter('User:user_in'); |
|
30 | +Router::get('/my-account', 'User:my_account')->filter('User:user_in'); |
|
31 | 31 | |
32 | 32 |
@@ -122,7 +122,7 @@ |
||
122 | 122 | |
123 | 123 | try{ |
124 | 124 | $buffer_tpl = $this->getOB($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php'); |
125 | - }catch(\Exception $er){ |
|
125 | + } catch(\Exception $er){ |
|
126 | 126 | var_dump($er); |
127 | 127 | die(); |
128 | 128 | } |
@@ -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 'string': |
37 | 37 | case 'int': |
38 | 38 | case 'integer': |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | |
58 | 58 | protected function replace_value(string $buffer, $value, string $prefix, string $key): string |
59 | 59 | { |
60 | - if(gettype($value)!=='array' && gettype($value)!=='object'){ |
|
61 | - while(strstr($buffer,'{{ '.$prefix.$key.' }}')){ |
|
62 | - $buffer = str_replace('{{ '.$prefix.$key.' }}', $value ,$buffer); |
|
60 | + if (gettype($value)!=='array' && gettype($value)!=='object') { |
|
61 | + while (strstr($buffer, '{{ '.$prefix.$key.' }}')) { |
|
62 | + $buffer = str_replace('{{ '.$prefix.$key.' }}', $value, $buffer); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | return $buffer; |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | |
68 | 68 | protected function replace_Object(string $buffer, object $obj, string $prefix, string $key): string |
69 | 69 | { |
70 | - foreach($obj->getFields() as $field => $val){ |
|
70 | + foreach ($obj->getFields() as $field => $val) { |
|
71 | 71 | |
72 | - $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field); |
|
72 | + $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field); |
|
73 | 73 | |
74 | - while(strstr($buffer,'{{ '.$prefix.$key.'.'.$field.' }}')){ |
|
75 | - $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}',$val[$field] ,$buffer); |
|
74 | + while (strstr($buffer, '{{ '.$prefix.$key.'.'.$field.' }}')) { |
|
75 | + $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}', $val[$field], $buffer); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | return $buffer; |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | |
81 | 81 | protected function replace_Array(string $buffer, array $array, string $prefix, string $key): string |
82 | 82 | { |
83 | - foreach($array as $field => $val){ |
|
84 | - $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.' , $field); |
|
83 | + foreach ($array as $field => $val) { |
|
84 | + $buffer = $this->replace_value($buffer, $val, $key.'.'.$field.'.', $field); |
|
85 | 85 | |
86 | - while(strstr($buffer,'{{ '.$prefix.$key.'.'.$field.' }}')){ |
|
87 | - $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}',$val,$buffer); |
|
86 | + while (strstr($buffer, '{{ '.$prefix.$key.'.'.$field.' }}')) { |
|
87 | + $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}', $val, $buffer); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | return $buffer; |
@@ -92,39 +92,39 @@ discard block |
||
92 | 92 | |
93 | 93 | protected function removeComments(string $buffer): string |
94 | 94 | { |
95 | - while(strstr($buffer,'<!--')){ |
|
95 | + while (strstr($buffer, '<!--')) { |
|
96 | 96 | $comment = substr( |
97 | 97 | $buffer, |
98 | - strpos($buffer,'<!--'), |
|
99 | - strpos(strstr($buffer,'<!--'),'-->')+3 |
|
98 | + strpos($buffer, '<!--'), |
|
99 | + strpos(strstr($buffer, '<!--'), '-->')+3 |
|
100 | 100 | ); |
101 | - $buffer = str_replace($comment,'',$buffer); |
|
101 | + $buffer = str_replace($comment, '', $buffer); |
|
102 | 102 | } |
103 | 103 | return $buffer; |
104 | 104 | } |
105 | 105 | |
106 | 106 | protected function getImport(string $buffer): string |
107 | 107 | { |
108 | - while(strstr($buffer,'@import')){ |
|
108 | + while (strstr($buffer, '@import')) { |
|
109 | 109 | $buffer = $this->getVars($buffer); |
110 | 110 | |
111 | 111 | $import = substr( |
112 | 112 | $buffer, |
113 | - strpos($buffer,'@import(\''), |
|
114 | - strpos(strstr($buffer,'@import'),'\')')+2 |
|
113 | + strpos($buffer, '@import(\''), |
|
114 | + strpos(strstr($buffer, '@import'), '\')')+2 |
|
115 | 115 | ); |
116 | 116 | |
117 | 117 | $tpl = $this->check_importExist($import); |
118 | 118 | |
119 | - try{ |
|
120 | - $buffer_tpl = $this->getOB($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php'); |
|
121 | - }catch(\Exception $er){ |
|
119 | + try { |
|
120 | + $buffer_tpl = $this->getOB($this->path.DIRECTORY_SEPARATOR.$tpl.'.tpl.php'); |
|
121 | + }catch (\Exception $er) { |
|
122 | 122 | var_dump($er); |
123 | 123 | die(); |
124 | 124 | } |
125 | 125 | |
126 | 126 | $buffer_tpl = $this->getVars($buffer_tpl); |
127 | - $buffer = str_replace($import,$buffer_tpl,$buffer); |
|
127 | + $buffer = str_replace($import, $buffer_tpl, $buffer); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return $buffer; |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | |
133 | 133 | protected function saveData(): bool |
134 | 134 | { |
135 | - if(session_status() !== PHP_SESSION_ACTIVE){ |
|
135 | + if (session_status()!==PHP_SESSION_ACTIVE) { |
|
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | unset($_SESSION['data']); |
139 | 139 | |
140 | - if(!empty($_SESSION['save'])){ |
|
140 | + if (!empty($_SESSION['save'])) { |
|
141 | 141 | foreach ($_SESSION['save'] as $key => $value) { |
142 | 142 | $_SESSION['data'][$key] = $value; |
143 | 143 | } |
@@ -4,27 +4,27 @@ |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | |
7 | -trait CheckTrait{ |
|
7 | +trait CheckTrait { |
|
8 | 8 | |
9 | - protected function check_viewExist(string $viewfile){ |
|
10 | - if(!file_exists($this->path . DIRECTORY_SEPARATOR . $viewfile . '.view.php')){ |
|
11 | - $v = $this->path . DIRECTORY_SEPARATOR . $viewfile; |
|
9 | + protected function check_viewExist(string $viewfile) { |
|
10 | + if (!file_exists($this->path.DIRECTORY_SEPARATOR.$viewfile.'.view.php')) { |
|
11 | + $v = $this->path.DIRECTORY_SEPARATOR.$viewfile; |
|
12 | 12 | throw new Exception("Preview file {$v} not found"); |
13 | 13 | } |
14 | 14 | } |
15 | 15 | |
16 | 16 | protected function check_importExist($import): string |
17 | 17 | { |
18 | - $tpl = str_replace('.',DIRECTORY_SEPARATOR, |
|
18 | + $tpl = str_replace('.', DIRECTORY_SEPARATOR, |
|
19 | 19 | substr( |
20 | 20 | $import, |
21 | - strpos($import,'\'')+1, |
|
21 | + strpos($import, '\'')+1, |
|
22 | 22 | strlen($import)-11 |
23 | 23 | ) |
24 | 24 | ); |
25 | 25 | |
26 | - if(!file_exists($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php')){ |
|
27 | - throw new Exception('Import \''.str_replace(['@import(\'','\')'],'',$import).'\' não encontrado.'); |
|
26 | + if (!file_exists($this->path.DIRECTORY_SEPARATOR.$tpl.'.tpl.php')) { |
|
27 | + throw new Exception('Import \''.str_replace(['@import(\'', '\')'], '', $import).'\' não encontrado.'); |
|
28 | 28 | } |
29 | 29 | return $tpl; |
30 | 30 | } |
@@ -2,25 +2,25 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Viewer; |
4 | 4 | |
5 | -class Viewer{ |
|
5 | +class Viewer { |
|
6 | 6 | use HelperTrait, CheckTrait; |
7 | 7 | |
8 | 8 | private static $instance = null; |
9 | 9 | private string $path = ''; |
10 | 10 | |
11 | - public function __construct(string $path){ |
|
11 | + public function __construct(string $path) { |
|
12 | 12 | $this->path = $path; |
13 | 13 | return $this; |
14 | 14 | } |
15 | 15 | |
16 | - public static function getInstance(string $path){ |
|
17 | - if(is_null(self::$instance)){ |
|
16 | + public static function getInstance(string $path) { |
|
17 | + if (is_null(self::$instance)) { |
|
18 | 18 | self::$instance = new self($path); |
19 | 19 | } |
20 | 20 | return self::$instance; |
21 | 21 | } |
22 | 22 | |
23 | - public static function create(string $path){ |
|
23 | + public static function create(string $path) { |
|
24 | 24 | return self::getInstance($path); |
25 | 25 | } |
26 | 26 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | $this->check_viewExist($file); |
32 | 32 | |
33 | - $buffer = $this->getOB($this->path . DIRECTORY_SEPARATOR . $file . '.view.php'); |
|
33 | + $buffer = $this->getOB($this->path.DIRECTORY_SEPARATOR.$file.'.view.php'); |
|
34 | 34 | |
35 | 35 | $buffer = $this->getVars($buffer); |
36 | 36 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | $this->saveData(); |
42 | 42 | |
43 | - if(!$return){ |
|
43 | + if (!$return) { |
|
44 | 44 | echo $buffer; |
45 | 45 | return ''; |
46 | 46 | } |