Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 29, 2019 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/50eae5fda39172da5fe556d685c093c4 to your computer and use it in GitHub Desktop.
Save parzibyte/50eae5fda39172da5fe556d685c093c4 to your computer and use it in GitHub Desktop.
<?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