CAU-Web-Fall-2018-Project-1/index.php

48 lines
1.3 KiB
PHP
Raw Normal View History

2017-04-14 12:31:29 +00:00
<?php
2017-12-19 22:42:09 +00:00
2017-04-14 12:31:29 +00:00
namespace base;
use base\API\APIRouter;
use base\Controller\Error;
use base\Controller\Site\SiteRouter;
use base\Model\BDD;
session_start();
2017-12-19 22:42:09 +00:00
date_default_timezone_set( 'Europe/Paris' );
setlocale( LC_TIME, "fr_FR.UTF-8" );
error_reporting( E_ALL );
2017-04-14 12:31:29 +00:00
2017-12-19 22:42:09 +00:00
require( 'src/lib/functions.php' );
require( 'src/config.php' );
2017-04-14 12:31:29 +00:00
require 'src/Autoloader.php';
Autoloader::register();
new BDD();
2017-12-19 22:42:09 +00:00
$parts = explode( '?', $_SERVER['REQUEST_URI'] );
$urlA = ltrim( $parts[0], '/' );
$pages = explode( '/', $urlA );
2017-04-14 12:31:29 +00:00
//Si il y a un / en fin d'url on redirige vers la meme page sans le /
2017-12-19 22:42:09 +00:00
if ( count( $pages ) > 1 && $pages[ count( $pages ) - 1 ] == '' ) {
$args = ( count( $parts ) > 1 ? '?' . $parts[1] : '' );
header( $_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently' );
header( 'Location: /' . rtrim( $urlA, '/' ) . $args );
exit();
2017-04-14 12:31:29 +00:00
}
2017-12-19 22:42:09 +00:00
if ( $pages[0] == 'api' && isset( $pages[1] ) && preg_match( '#^([a-z]+)$#', $pages[1], $api1 ) && isset( $pages[2] ) && preg_match( '#^([a-z-]+)$#', $pages[2], $api2 ) ) {
new APIRouter( $api1[0], $api2[0] );
2017-04-14 12:31:29 +00:00
2017-12-19 22:42:09 +00:00
} else if ( preg_match( '#^test\.dev$#', $_SERVER['SERVER_NAME'] ) ) {
new SiteRouter( $pages );
2017-04-14 12:31:29 +00:00
} else {
2017-12-19 22:42:09 +00:00
new Error( 404 );
2017-04-14 12:31:29 +00:00
}
/*
} elseif (preg_match('#^(www\.)?mvc\.eldotravo\.dev$#', $_SERVER['SERVER_NAME'])) {
new SiteRouter($pages);
*/
?>