@@ -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 |
@@ -114,10 +114,10 @@ |
||
114 | 114 | ); |
115 | 115 | |
116 | 116 | if(!file_exists($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php')){ |
117 | - $_SESSION['data'] = unserialize($_SESSION['data']); |
|
118 | - $_SESSION['data']['title'] = 'Arquivo tpl não localizado:'; |
|
119 | - $_SESSION['data']['message'] = 'Import \''.str_replace(['@import(\'','\')'],'',$import).'\' não encontrado.'; |
|
120 | - throw new \Exception('Import \''.str_replace(['@import(\'','\')'],'',$import).'\' não encontrado.'); |
|
117 | + $_SESSION['data'] = unserialize($_SESSION['data']); |
|
118 | + $_SESSION['data']['title'] = 'Arquivo tpl não localizado:'; |
|
119 | + $_SESSION['data']['message'] = 'Import \''.str_replace(['@import(\'','\')'],'',$import).'\' não encontrado.'; |
|
120 | + throw new \Exception('Import \''.str_replace(['@import(\'','\')'],'',$import).'\' não encontrado.'); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | try{ |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Viewer; |
4 | 4 | |
5 | -trait HelperTrait{ |
|
5 | +trait HelperTrait { |
|
6 | 6 | |
7 | 7 | protected function getOB(string $require): string |
8 | 8 | { |
@@ -11,27 +11,27 @@ discard block |
||
11 | 11 | $response = ob_get_contents(); |
12 | 12 | ob_end_clean(); |
13 | 13 | |
14 | - $response = explode(PHP_EOL,$response); |
|
15 | - foreach($response as $index => $value){ |
|
14 | + $response = explode(PHP_EOL, $response); |
|
15 | + foreach ($response as $index => $value) { |
|
16 | 16 | $response[$index] = ltrim($value); |
17 | 17 | } |
18 | 18 | |
19 | - return implode('',$response); |
|
19 | + return implode('', $response); |
|
20 | 20 | } |
21 | 21 | |
22 | - protected function getVars(string $buffer,string $prefix = null, $valuee = null): string |
|
22 | + protected function getVars(string $buffer, string $prefix = null, $valuee = null): string |
|
23 | 23 | { |
24 | 24 | //Recebe os valores a serem substituidos pela session caso não seja passado via parametro |
25 | 25 | |
26 | 26 | //$vars = (!empty($valuee)) ? $valuee : unserialize($_SESSION['data']); |
27 | 27 | $vars = (!empty($valuee)) ? $valuee : (empty($_SESSION['data']) ? null : $_SESSION['data']); |
28 | 28 | |
29 | - if(empty($vars)){ |
|
29 | + if (empty($vars)) { |
|
30 | 30 | return $buffer; |
31 | 31 | } |
32 | 32 | foreach ($vars as $key => $value) { |
33 | 33 | //Trabalha separadamente por tipo |
34 | - switch(gettype($value)){ |
|
34 | + switch (gettype($value)) { |
|
35 | 35 | case 'string': |
36 | 36 | case 'int': |
37 | 37 | case 'integer': |
@@ -40,37 +40,37 @@ discard block |
||
40 | 40 | case 'NULL': |
41 | 41 | |
42 | 42 | //Verifica se variável da session é solicitada no buffer |
43 | - while(strstr($buffer,'{{ '.$prefix.$key.' }}')){ |
|
44 | - $buffer = str_replace('{{ '.$prefix.$key.' }}', $value ,$buffer); |
|
43 | + while (strstr($buffer, '{{ '.$prefix.$key.' }}')) { |
|
44 | + $buffer = str_replace('{{ '.$prefix.$key.' }}', $value, $buffer); |
|
45 | 45 | } |
46 | 46 | break; |
47 | 47 | case 'array': |
48 | 48 | //Faz um loop nos campos do array |
49 | - foreach($value as $index => $val){ |
|
49 | + foreach ($value as $index => $val) { |
|
50 | 50 | //Verifica se conteudo do indice no loop é do tipo objeto ou outro array, se for, chama a mesma função para trabalhar nele |
51 | - if(gettype($val)==='array' or gettype($val)==='object'){ |
|
51 | + if (gettype($val)==='array' or gettype($val)==='object') { |
|
52 | 52 | |
53 | - $buffer = $this->getVars($buffer,$key.'.'.$index.'.',$val); |
|
53 | + $buffer = $this->getVars($buffer, $key.'.'.$index.'.', $val); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | //Caso não seja objeto ou array é trabalhado o conteudo a ser substituido |
57 | - while(strstr($buffer,'{{ '.$prefix.$key.'.'.$index.' }}')){ |
|
58 | - $buffer = str_replace('{{ '.$prefix.$key.'.'.$index.' }}',$val,$buffer); |
|
57 | + while (strstr($buffer, '{{ '.$prefix.$key.'.'.$index.' }}')) { |
|
58 | + $buffer = str_replace('{{ '.$prefix.$key.'.'.$index.' }}', $val, $buffer); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | break; |
62 | 62 | case 'object': |
63 | 63 | //Faz um loop nos campos do objeto |
64 | - foreach($value->getFields() as $field => $val){ |
|
64 | + foreach ($value->getFields() as $field => $val) { |
|
65 | 65 | //Verifica se o campo em loop é do tipo array ou um outro objetivo, se for, chama a mesma função para trabalhar enele |
66 | - if(gettype($val)==='array' or gettype($val)==='object'){ |
|
67 | - $buffer = $this->getVars($buffer,$key.'.'.$field.'.',$val); |
|
66 | + if (gettype($val)==='array' or gettype($val)==='object') { |
|
67 | + $buffer = $this->getVars($buffer, $key.'.'.$field.'.', $val); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | //Caso não seja objeto ou array é trabalhado o conteudo do campo |
71 | - while(strstr($buffer,'{{ '.$prefix.$key.'.'.$field.' }}')){ |
|
71 | + while (strstr($buffer, '{{ '.$prefix.$key.'.'.$field.' }}')) { |
|
72 | 72 | echo 1; |
73 | - $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}',$val[$field] ,$buffer); |
|
73 | + $buffer = str_replace('{{ '.$prefix.$key.'.'.$field.' }}', $val[$field], $buffer); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | break; |
@@ -84,51 +84,51 @@ discard block |
||
84 | 84 | |
85 | 85 | protected function removeComments(string $buffer): string |
86 | 86 | { |
87 | - while(strstr($buffer,'<!--')){ |
|
87 | + while (strstr($buffer, '<!--')) { |
|
88 | 88 | $comment = substr( |
89 | 89 | $buffer, |
90 | - strpos($buffer,'<!--'), |
|
91 | - strpos(strstr($buffer,'<!--'),'-->')+3 |
|
90 | + strpos($buffer, '<!--'), |
|
91 | + strpos(strstr($buffer, '<!--'), '-->')+3 |
|
92 | 92 | ); |
93 | - $buffer = str_replace($comment,'',$buffer); |
|
93 | + $buffer = str_replace($comment, '', $buffer); |
|
94 | 94 | } |
95 | 95 | return $buffer; |
96 | 96 | } |
97 | 97 | |
98 | 98 | protected function getImport(string $buffer): string |
99 | 99 | { |
100 | - while(strstr($buffer,'@import')){ |
|
100 | + while (strstr($buffer, '@import')) { |
|
101 | 101 | $buffer = $this->getVars($buffer); |
102 | 102 | |
103 | 103 | $import = substr( |
104 | 104 | $buffer, |
105 | - strpos($buffer,'@import(\''), |
|
106 | - strpos(strstr($buffer,'@import'),'\')')+2 |
|
105 | + strpos($buffer, '@import(\''), |
|
106 | + strpos(strstr($buffer, '@import'), '\')')+2 |
|
107 | 107 | ); |
108 | - $tpl = str_replace('.',DIRECTORY_SEPARATOR, |
|
108 | + $tpl = str_replace('.', DIRECTORY_SEPARATOR, |
|
109 | 109 | substr( |
110 | 110 | $import, |
111 | - strpos($import,'\'')+1, |
|
111 | + strpos($import, '\'')+1, |
|
112 | 112 | strlen($import)-11 |
113 | 113 | ) |
114 | 114 | ); |
115 | 115 | |
116 | - if(!file_exists($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php')){ |
|
116 | + if (!file_exists($this->path.DIRECTORY_SEPARATOR.$tpl.'.tpl.php')) { |
|
117 | 117 | $_SESSION['data'] = unserialize($_SESSION['data']); |
118 | 118 | $_SESSION['data']['title'] = 'Arquivo tpl não localizado:'; |
119 | - $_SESSION['data']['message'] = 'Import \''.str_replace(['@import(\'','\')'],'',$import).'\' não encontrado.'; |
|
120 | - throw new \Exception('Import \''.str_replace(['@import(\'','\')'],'',$import).'\' não encontrado.'); |
|
119 | + $_SESSION['data']['message'] = 'Import \''.str_replace(['@import(\'', '\')'], '', $import).'\' não encontrado.'; |
|
120 | + throw new \Exception('Import \''.str_replace(['@import(\'', '\')'], '', $import).'\' não encontrado.'); |
|
121 | 121 | } |
122 | 122 | |
123 | - try{ |
|
124 | - $buffer_tpl = $this->getOB($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php'); |
|
125 | - }catch(\Exception $er){ |
|
123 | + try { |
|
124 | + $buffer_tpl = $this->getOB($this->path.DIRECTORY_SEPARATOR.$tpl.'.tpl.php'); |
|
125 | + }catch (\Exception $er) { |
|
126 | 126 | var_dump($er); |
127 | 127 | die(); |
128 | 128 | } |
129 | 129 | |
130 | 130 | $buffer_tpl = $this->getVars($buffer_tpl); |
131 | - $buffer = str_replace($import,$buffer_tpl,$buffer); |
|
131 | + $buffer = str_replace($import, $buffer_tpl, $buffer); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | return $buffer; |
@@ -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,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 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | { |
29 | 29 | header('Content-Type: text/html; charset=utf-8'); |
30 | 30 | |
31 | - if(!empty($_SESSION['save'])){ |
|
31 | + if (!empty($_SESSION['save'])) { |
|
32 | 32 | foreach ($_SESSION['save'] as $key => $value) { |
33 | 33 | $_SESSION['data'][$key] = $value; |
34 | 34 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | $this->check_viewExist($file); |
38 | 38 | |
39 | - $buffer = $this->getOB($this->path . DIRECTORY_SEPARATOR . $file . '.view.php'); |
|
39 | + $buffer = $this->getOB($this->path.DIRECTORY_SEPARATOR.$file.'.view.php'); |
|
40 | 40 | |
41 | 41 | $buffer = $this->getVars($buffer); |
42 | 42 | |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | |
45 | 45 | $buffer = $this->removeComments($buffer); |
46 | 46 | |
47 | - if(is_null($return)){ |
|
47 | + if (is_null($return)) { |
|
48 | 48 | echo $buffer; |
49 | - }else{ |
|
49 | + }else { |
|
50 | 50 | return $buffer; |
51 | 51 | } |
52 | 52 | |
53 | 53 | unset($_SESSION['data']); |
54 | 54 | |
55 | - if(!empty($_SESSION['save'])){ |
|
55 | + if (!empty($_SESSION['save'])) { |
|
56 | 56 | foreach ($_SESSION['save'] as $key => $value) { |
57 | 57 | $_SESSION['data'][$key] = $value; |
58 | 58 | } |
@@ -46,7 +46,7 @@ |
||
46 | 46 | |
47 | 47 | if(is_null($return)){ |
48 | 48 | echo $buffer; |
49 | - }else{ |
|
49 | + } else{ |
|
50 | 50 | return $buffer; |
51 | 51 | } |
52 | 52 |
@@ -4,11 +4,11 @@ |
||
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 | } |