-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
87 lines (76 loc) · 2.57 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
require __DIR__ . '/vendor/autoload.php'; #Cargar todas las dependencias
use Parzibyte\Servicios\Comun;
use Parzibyte\Servicios\Seguridad;
use Parzibyte\Servicios\SesionService;
use Parzibyte\Servicios\Twig;
use Phroute\Phroute\Dispatcher;
use Phroute\Phroute\Exception\HttpMethodNotAllowedException;
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
use Valitron\Validator as V;
const ID_ACORTADOR_ADFLY = 1,
ID_ACORTADOR_OUO = 2,
ID_ACORTADOR_SHINK_ME = 3,
ID_ACORTADOR_SHORTEST = 4,
ID_ACORTADOR_SHORTZON = 5,
ID_ACORTADOR_SHRINKMEIO = 6;
V::langDir(__DIR__ . "/vendor/vlucas/valitron/lang");
V::lang('es');
define("DIRECTORIO_RAIZ", __DIR__);
define("DIRECTORIO_APLICACION", DIRECTORIO_RAIZ . "/app");
define("RUTA_LOGS", __DIR__ . DIRECTORY_SEPARATOR . "logs");
define("URL_RAIZ", Comun::env("URL_RAIZ"));
define("PERMITIR_REGISTRO_USUARIOS", Comun::env("PERMITIR_REGISTRO_USUARIOS", true));
define("URL_DIRECTORIO_PUBLICO", URL_RAIZ . "/public");
define("RUTA_API", URL_RAIZ . "/api");
define("NOMBRE_APLICACION", "Acortadores");
define("AUTOR", "parzibyte");
define("WEB_AUTOR", "https://parzibyte.me/blog");
ini_set('display_errors', 0);
ini_set("log_errors", 1);
ini_set("error_log", __DIR__ . "/logs/" . date("Y-m-d") . ".log");
if (!file_exists(RUTA_LOGS)) {
mkdir(RUTA_LOGS);
}
function view($nombre, $datos = [])
{
echo Twig::obtener()->render("$nombre.twig", $datos);
return;
}
function getview($nombre, $datos = [])
{
return Twig::obtener()->render("$nombre.twig", $datos);
}
function json($datos)
{
header("Content-type: application/json");
echo json_encode($datos);
return;
}
function getJsonRequest()
{
return json_decode(file_get_contents("php://input"));
}
$enrutador = require_once "rutas.php";
$despachador = new Dispatcher($enrutador->getData());
$rutaCompleta = $_SERVER["REQUEST_URI"];
$metodo = $_SERVER['REQUEST_METHOD'];
$rutaLimpia = parsearUrl($rutaCompleta);
try {
$despachador->dispatch($metodo, $rutaLimpia);
} catch (HttpRouteNotFoundException $e) {
echo "Error: Ruta [ $rutaLimpia ] no encontrada";
} catch (HttpMethodNotAllowedException $e) {
echo "Error: Ruta [ $rutaLimpia ] encontrada pero método [ $metodo ] no permitido";
}
function parsearUrl($uri)
{
// Para eliminar la query string pero seguir accediendo a ella a través de $_GET
$posicionSignoDeInterrogacion = strpos($uri, "?");
if ($posicionSignoDeInterrogacion !== false) {
$uri = substr($uri, 0, $posicionSignoDeInterrogacion);
}
return implode('/',
array_slice(
explode('/', $uri), Comun::env("OFFSET_RUTAS")));
}