Commit 9d6c1051 authored by Jordan Breton's avatar Jordan Breton

Added : Absolute redirections

parent 4ccefcd2
......@@ -101,7 +101,7 @@ final class WebApp {
$response->getCode(),
$permission->getMessage()
);
}else $this->redirect($response->getUrl(),$response->getCode());
}else $this->redirect($response->getUrl(),$response->getCode(), $response->isAbsolute());
}
$responseRouter = $this->_context->getResponseRouter();
......@@ -149,14 +149,16 @@ final class WebApp {
}
/**
* @param string $url URL de redirection
* @param int|null $code Code de redirection
* @param string $url URL de redirection
* @param int|null $code Code de redirection
* @param bool|null $absolute
*/
private function redirect(string $url,?int $code = null){
private function redirect(string $url,?int $code = null, ?bool $absolute = false){
if(HTTPStatus::existsValue($code)){
http_response_code($code);
}
header("Location: ".$this->_context->getRouter()->url($url));
$url = $absolute ? $url : $this->_context->getRouter()->url($url);
header("Location: $url");
exit(0);
}
}
\ No newline at end of file
......@@ -11,16 +11,20 @@ final class Redirection implements IResponse {
private $_url;
/** @var null|int $code */
private $_code;
/** @var bool|null $_absolute */
private $_absolute;
/**
* RedirectionResponse constructor.
*
* @param string $url URL de redirection
* @param int|null $code Code de redirection
* @param string $url URL de redirection
* @param int|null $code Code de redirection
* @param bool|null $absolute If true, the given url is absolute and must not be parsed by the router.
*/
public function __construct(string $url,?int $code=null) {
public function __construct(string $url,?int $code=null, ?bool $absolute=false) {
$this->_url = $url;
$this->_code = $code;
$this->_absolute = $absolute;
}
/**
......@@ -37,6 +41,13 @@ final class Redirection implements IResponse {
return $this->_code;
}
/**
* @return bool
*/
public function isAbsolute():bool{
return $this->_absolute;
}
/**
* @return mixed Données de la réponse
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment