Created
July 29, 2019 21:12
-
-
Save parzibyte/50eae5fda39172da5fe556d685c093c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Parzibyte; | |
use Parzibyte\Servicios\SesionService; | |
class Redirect | |
{ | |
static $ruta = ""; | |
static $esto; | |
static $goBack; | |
private static function esto() | |
{ | |
if (!self::$esto) { | |
self::$esto = new self(); | |
} | |
return self::$esto; | |
} | |
private static function redirect($ruta, $absoluta = false) | |
{ | |
$verdaderaRuta = $absoluta ? $ruta : URL_RAIZ . $ruta; | |
header("Location: " . $verdaderaRuta); | |
exit; | |
} | |
public function do() { | |
if (self::$goBack) { | |
if (isset($_SERVER["HTTP_REFERER"])) { | |
self::redirect($_SERVER["HTTP_REFERER"], true); | |
} else { | |
echo '<script type="text/javascript">history.go(-1)</script>'; | |
exit; | |
} | |
} | |
self::redirect(self::$ruta); | |
} | |
public static function to($ruta) | |
{ | |
self::$ruta = $ruta; | |
return self::esto(); | |
} | |
public static function back() | |
{ | |
self::$goBack = true; | |
return self::esto(); | |
} | |
public static function with($datos) | |
{ | |
SesionService::flash($datos); | |
return self::esto(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment