diff --git a/src/Actions/Action.php b/src/Actions/Action.php index 45d0f5a..826b31c 100644 --- a/src/Actions/Action.php +++ b/src/Actions/Action.php @@ -13,17 +13,14 @@ use Slim\Exception\HttpNotFoundException; abstract class Action { - protected LoggerInterface $logger; - protected Request $request; protected Response $response; protected array $args; - public function __construct(LoggerInterface $logger) + public function __construct(protected LoggerInterface $logger) { - $this->logger = $logger; $this->response = new \Slim\Psr7\Response(); } @@ -67,4 +64,11 @@ abstract class Action ->withHeader('Content-Type', 'application/json') ->withStatus($payload->getStatusCode()); } + + protected function redirect(string $redirectUrl) : Response + { + return $this->response + ->withHeader('Location', $redirectUrl) + ->withStatus(302); + } } diff --git a/src/Services/EnvironmentService.php b/src/Services/EnvironmentService.php index 5f781a7..3e74299 100644 --- a/src/Services/EnvironmentService.php +++ b/src/Services/EnvironmentService.php @@ -58,4 +58,15 @@ class EnvironmentService $this->get('HTTP_HOST') ); } + + public function getPublicPath(): string + { + return $this->get('REQUEST_URI'); + } + + public function getPublicUrl(): string + { + return $this->getPublicHostname() . $this->getPublicPath(); + } + }