ajout d'un registre pour les applications modulaires
This commit is contained in:
parent
dd7f486bf2
commit
6a2ded3c3e
28
application/class/ModularRegister.php
Normal file
28
application/class/ModularRegister.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace MVC\Classe;
|
||||
|
||||
class ModularRegister{
|
||||
|
||||
public $registry = array();
|
||||
public $index = array();
|
||||
|
||||
public function __construct(){
|
||||
|
||||
$fichier = file(MODULES_PATH.DIRECTORY_SEPARATOR."setup" . DIRECTORY_SEPARATOR ."registre.model");
|
||||
foreach ($fichier as $ligne_num => $ligne) {
|
||||
if (preg_match("#[ ]*([a-zA-Z-_+]*)[ ]*[:][ ]*([0-9a-zA-Z-_+ ']*[ ]*)#", $ligne, $matches)) {
|
||||
$this->registry[$matches[1]] = $matches[2];
|
||||
$this->index[] = $matches[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getRegistre(){
|
||||
return $this->index;
|
||||
}
|
||||
|
||||
public function getIndex(){
|
||||
return $this->registry;
|
||||
}
|
||||
}
|
|
@ -5,74 +5,80 @@ namespace MVC\Classe;
|
|||
class Url
|
||||
{
|
||||
public $page;
|
||||
public $registre;
|
||||
|
||||
|
||||
public function __construct(){
|
||||
|
||||
$page = array();
|
||||
$page['name'] = 'accueil';
|
||||
$page['description'] = "";
|
||||
$page['params'] = array();
|
||||
$page['control'] = false;
|
||||
$this->registre = new \MVC\Classe\ModularRegister();
|
||||
|
||||
|
||||
|
||||
$url = parse_url($_SERVER['REQUEST_URI']);
|
||||
$urlTrim = trim( $url['path'] , '/' );
|
||||
$urlParts = explode('/' , $urlTrim );
|
||||
|
||||
//print_r($urlParts);
|
||||
if(isset($urlParts[0])) {
|
||||
//Récupération du nom de la page
|
||||
($urlParts[0] == 'index' || $urlParts[0] == '') ? $page['name'] = 'accueil' : $page['name'] = $urlParts[0];
|
||||
//array_shift($urlParts);
|
||||
unset($urlParts[0]);
|
||||
}else{
|
||||
$page = array();
|
||||
$page['name'] = 'accueil';
|
||||
}
|
||||
$page['description'] = "";
|
||||
$page['params'] = array();
|
||||
$page['control'] = false;
|
||||
|
||||
if($page['name'] == 'control'){
|
||||
$page['control'] = true;
|
||||
($urlParts[1] == 'index' || $urlParts[1] == '' ) ? $page['name']='accueil' : $page['name']=$urlParts[1];
|
||||
//array_shift($urlParts);
|
||||
unset($urlParts[1]);
|
||||
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
if($page['control']){
|
||||
$page['params'] = array_combine($values, $keys);
|
||||
}else {
|
||||
$page['params'] = array_combine($keys, $values);
|
||||
$url = parse_url($_SERVER['REQUEST_URI']);
|
||||
$urlTrim = trim( $url['path'] , '/' );
|
||||
$urlParts = explode('/' , $urlTrim );
|
||||
|
||||
//print_r($urlParts);
|
||||
if(isset($urlParts[0])) {
|
||||
//Récupération du nom de la page
|
||||
($urlParts[0] == 'index' || $urlParts[0] == '') ? $page['name'] = 'accueil' : $page['name'] = $urlParts[0];
|
||||
//array_shift($urlParts);
|
||||
unset($urlParts[0]);
|
||||
}else{
|
||||
$page['name'] = 'accueil';
|
||||
}
|
||||
}
|
||||
|
||||
//verification de l'existence de la page dans les controlleurs
|
||||
if($page['control']){
|
||||
$pageFile = TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php';
|
||||
}else {
|
||||
$pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php';
|
||||
}
|
||||
|
||||
if(!file_exists($pageFile)){
|
||||
$page['name'] = 'error';
|
||||
}
|
||||
$this->page = $page;
|
||||
}
|
||||
|
||||
if($page['name'] == 'control'){
|
||||
$page['control'] = true;
|
||||
($urlParts[1] == 'index' || $urlParts[1] == '' ) ? $page['name']='accueil' : $page['name']=$urlParts[1];
|
||||
//array_shift($urlParts);
|
||||
unset($urlParts[1]);
|
||||
|
||||
}
|
||||
|
||||
//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 ) {
|
||||
if( !in_array($page['name'], $this->registre->getIndex()) ){
|
||||
$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;
|
||||
}
|
||||
}
|
||||
if($page['control']){
|
||||
$page['params'] = array_combine($values, $keys);
|
||||
}else {
|
||||
$page['params'] = array_combine($keys, $values);
|
||||
}
|
||||
}
|
||||
|
||||
//verification de l'existence de la page dans les controlleurs
|
||||
if($page['control']){
|
||||
$pageFile = TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php';
|
||||
}else {
|
||||
$pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php';
|
||||
}
|
||||
|
||||
if(!file_exists($pageFile)){
|
||||
$page['name'] = 'error';
|
||||
}
|
||||
$this->page = $page;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
1
application/modules/setup/registre.model
Normal file
1
application/modules/setup/registre.model
Normal file
|
@ -0,0 +1 @@
|
|||
sf43:Application permetttant de tester l'intégration d'un module avec symfony4.3
|
Loading…
Reference in a new issue