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

50 lines
1.5 KiB
PHP
Raw Normal View History

2017-04-14 12:31:29 +00:00
<?php
2017-12-19 22:42:09 +00:00
2018-10-16 00:19:07 +00:00
namespace WebProjectFitness;
2017-04-14 12:31:29 +00:00
2018-10-16 00:19:07 +00:00
use WebProjectFitness\API\APIRouter;
use WebProjectFitness\Controller\Error;
use WebProjectFitness\Controller\Site\SiteRouter;
use WebProjectFitness\Model\BDD;
2017-04-14 12:31:29 +00:00
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
2018-12-16 07:05:08 +00:00
require( 'src/Lib/Functions.php' );
2018-12-12 06:04:47 +00:00
require( 'src/Config.php' );
2017-04-14 12:31:29 +00:00
require 'src/Autoloader.php';
Autoloader::register();
new BDD();
2018-12-12 06:04:47 +00:00
$parts = explode( '?', $_SERVER[ 'REQUEST_URI' ] );
$urlA = ltrim( $parts[ 0 ], '/' );
2017-12-19 22:42:09 +00:00
$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 ] == '' ) {
2018-12-12 06:04:47 +00:00
$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
}
2018-12-12 06:04:47 +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
2018-12-13 05:42:08 +00:00
} else if ( preg_match( '#^fitness.sanchez-mathieu\.test$#', $_SERVER[ 'SERVER_NAME' ] )
|| preg_match( '#^fitness.sanchez-mathieu\.fr$#', $_SERVER[ 'SERVER_NAME' ] )
|| preg_match( '#^cauweb\.fr$#', $_SERVER[ 'SERVER_NAME' ] )) {
2018-12-12 06:04:47 +00:00
new SiteRouter( $pages );
2017-04-14 12:31:29 +00:00
} else {
2018-12-12 06:04:47 +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);
*/
?>