137b5e76 |
<?php
class Url
{
public $page;
|
aed8ee26 |
public function __construct(){
|
137b5e76 |
|
aed8ee26 |
$page = array();
$page['name'] = 'accueil';
$page['description'] = "";
$page['params'] = array();
$url = parse_url($_SERVER['REQUEST_URI']);
$urlTrim = trim( $url['path'] , '/' );
|
137b5e76 |
$urlParts = explode('/' , $urlTrim );
|
aed8ee26 |
//Récupération du nom de la page
($urlParts[0] == 'index' || $urlParts[0] == '' ) ? $page['name']='accueil' : $page['name']=$urlParts[0];
unset($urlParts[0]);
//vérification du nombre de parametres: s'il n'existe pas autant de clé que
// de valeurs on sort de la fonction et on renvoie une page d'erreur.
$numParts = count($urlParts);
if ( $numParts%2 != 0 ) {
$page['name'] = 'error';
$page['params'] = array();
return $page;
}else if ( $numParts != 0 ){
$values = array();
$keys = array();
foreach( $urlParts as $key => $value ){
if($key%2 == 0) {
$values[] = $value;
} else {
$keys[] = $value;
}
}
$page['params'] = array_combine($keys, $values);
}
|
137b5e76 |
//verification de l'existence de la page dans les controlleurs
|
aed8ee26 |
$pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php';
if(!file_exists($pageFile)){
$page['name'] = 'error';
|
137b5e76 |
}
|
aed8ee26 |
$this->page = $page;
|
137b5e76 |
}
}
|