@@ -8,23 +8,23 @@ |
||
| 8 | 8 | use Psr\Http\Server\MiddlewareInterface; |
| 9 | 9 | use Psr\Http\Server\RequestHandlerInterface; |
| 10 | 10 | |
| 11 | -class Middleware implements MiddlewareInterface{ |
|
| 11 | +class Middleware implements MiddlewareInterface { |
|
| 12 | 12 | protected static array $data = []; |
| 13 | 13 | protected static Response $response; |
| 14 | 14 | |
| 15 | 15 | public function __get($key) |
| 16 | 16 | { |
| 17 | - return (array_key_exists($key,self::$data)) ? self::$data[$key] : null; |
|
| 17 | + return (array_key_exists($key, self::$data)) ? self::$data[$key] : null; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function __set($key,$value) |
|
| 20 | + public function __set($key, $value) |
|
| 21 | 21 | { |
| 22 | 22 | self::$data[$key] = $value; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 26 | 26 | { |
| 27 | - if(!isset(self::$response)){ |
|
| 27 | + if (!isset(self::$response)) { |
|
| 28 | 28 | self::$response = new Response(); |
| 29 | 29 | } |
| 30 | 30 | return self::$response; |
@@ -8,8 +8,8 @@ |
||
| 8 | 8 | use Psr\Http\Server\RequestHandlerInterface; |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | - * @property string $error |
|
| 12 | - */ |
|
| 11 | + * @property string $error |
|
| 12 | + */ |
|
| 13 | 13 | class Lasted extends Middleware{ |
| 14 | 14 | |
| 15 | 15 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
@@ -10,11 +10,11 @@ |
||
| 10 | 10 | /** |
| 11 | 11 | * @property string $error |
| 12 | 12 | */ |
| 13 | -class Lasted extends Middleware{ |
|
| 13 | +class Lasted extends Middleware { |
|
| 14 | 14 | |
| 15 | 15 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 16 | 16 | { |
| 17 | - if(!isset($this->error)){ |
|
| 17 | + if (!isset($this->error)) { |
|
| 18 | 18 | throw new Exception("Access not belonged: {$this->error}"); |
| 19 | 19 | } |
| 20 | 20 | |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | use Psr\Http\Server\RequestHandlerInterface; |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | - * @property string $error |
|
| 11 | - */ |
|
| 10 | + * @property string $error |
|
| 11 | + */ |
|
| 12 | 12 | class Auth extends Middleware{ |
| 13 | 13 | |
| 14 | 14 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
@@ -9,11 +9,11 @@ |
||
| 9 | 9 | /** |
| 10 | 10 | * @property string $error |
| 11 | 11 | */ |
| 12 | -class Auth extends Middleware{ |
|
| 12 | +class Auth extends Middleware { |
|
| 13 | 13 | |
| 14 | 14 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 15 | 15 | { |
| 16 | - if(!array_key_exists('user',$_SESSION)){ |
|
| 16 | + if (!array_key_exists('user', $_SESSION)) { |
|
| 17 | 17 | $this->error = 'The user must be logged in to the system'; |
| 18 | 18 | } |
| 19 | 19 | |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace HnrAzevedo\Router\Example\Controllers; |
| 4 | 4 | |
| 5 | -class User{ |
|
| 5 | +class User { |
|
| 6 | 6 | |
| 7 | 7 | public function requireLogin($param, $param2): void |
| 8 | 8 | { |
@@ -14,13 +14,13 @@ discard block |
||
| 14 | 14 | use HnrAzevedo\Router\Router; |
| 15 | 15 | use Psr\Http\Server\MiddlewareInterface; |
| 16 | 16 | |
| 17 | -try{ |
|
| 17 | +try { |
|
| 18 | 18 | $serverRequest = (new Factory())->createServerRequest($_SERVER['REQUEST_METHOD'], new Uri($_SERVER['REQUEST_URI'])); |
| 19 | 19 | |
| 20 | - class App implements MiddlewareInterface{ |
|
| 20 | + class App implements MiddlewareInterface { |
|
| 21 | 21 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 22 | 22 | { |
| 23 | - if(empty($request->getAttribute('route'))) |
|
| 23 | + if (empty($request->getAttribute('route'))) |
|
| 24 | 24 | { |
| 25 | 25 | throw new Exception('Page not found', 404); |
| 26 | 26 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - define('GLOBAL_MIDDLEWARES',[ |
|
| 34 | + define('GLOBAL_MIDDLEWARES', [ |
|
| 35 | 35 | Router::class, |
| 36 | 36 | App::class |
| 37 | 37 | ]); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | function runMiddlewares($serverRequest) |
| 69 | 69 | { |
| 70 | - nextExample(new class implements RequestHandlerInterface{ |
|
| 70 | + nextExample(new class implements RequestHandlerInterface { |
|
| 71 | 71 | public function handle(ServerRequestInterface $request): ResponseInterface |
| 72 | 72 | { |
| 73 | 73 | return (new Factory())->createResponse(200); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | runMiddlewares($serverRequest); |
| 79 | 79 | |
| 80 | -}catch(Exception $er){ |
|
| 80 | +}catch (Exception $er) { |
|
| 81 | 81 | |
| 82 | 82 | die("Code Error: {$er->getCode()}<br>Line: {$er->getLine()}<br>File: {$er->getFile()}<br>Message: {$er->getMessage()}."); |
| 83 | 83 | |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | use HnrAzevedo\Router\Router; |
| 9 | 9 | |
| 10 | -try{ |
|
| 10 | +try { |
|
| 11 | 11 | |
| 12 | 12 | Router::defineHost('https://localhost'); |
| 13 | 13 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | $action = Router::currentAction(); |
| 30 | 30 | |
| 31 | -}catch(Exception $er){ |
|
| 31 | +}catch (Exception $er) { |
|
| 32 | 32 | |
| 33 | 33 | die("Code Error: {$er->getCode()}<br>Line: {$er->getLine()}<br>File: {$er->getFile()}<br>Message: {$er->getMessage()}."); |
| 34 | 34 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace HnrAzevedo\Router; |
| 6 | 6 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | protected function setRoutes(array $routes): void |
| 56 | 56 | { |
| 57 | - $this->routes = $routes; |
|
| 57 | + $this->routes = $routes; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | protected function getGroup(): ?string |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace HnrAzevedo\Router; |
| 6 | 6 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace HnrAzevedo\Router; |
| 6 | 6 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | { |
| 20 | 20 | $this->hasRouteName($name); |
| 21 | 21 | |
| 22 | - if(!$this->loaded()){ |
|
| 22 | + if (!$this->loaded()) { |
|
| 23 | 23 | $this->loadIn($name); |
| 24 | 24 | } |
| 25 | 25 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | public function hasCurrentRoute(): void |
| 30 | 30 | { |
| 31 | - if(!isset($this->currentRoute)){ |
|
| 31 | + if (!isset($this->currentRoute)) { |
|
| 32 | 32 | throw new \RuntimeException('Route not yet loaded'); |
| 33 | 33 | } |
| 34 | 34 | } |