1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,28 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+namespace MVC\Classe; |
|
4 |
+ |
|
5 |
+class ModularRegister{ |
|
6 |
+ |
|
7 |
+ public $registry = array(); |
|
8 |
+ public $index = array(); |
|
9 |
+ |
|
10 |
+ public function __construct(){ |
|
11 |
+ |
|
12 |
+ $fichier = file(MODULES_PATH.DIRECTORY_SEPARATOR."setup" . DIRECTORY_SEPARATOR ."registre.model"); |
|
13 |
+ foreach ($fichier as $ligne_num => $ligne) { |
|
14 |
+ if (preg_match("#[ ]*([a-zA-Z-_+]*)[ ]*[:][ ]*([0-9a-zA-Z-_+ ']*[ ]*)#", $ligne, $matches)) { |
|
15 |
+ $this->registry[$matches[1]] = $matches[2]; |
|
16 |
+ $this->index[] = $matches[1]; |
|
17 |
+ } |
|
18 |
+ } |
|
19 |
+ } |
|
20 |
+ |
|
21 |
+ public function getRegistre(){ |
|
22 |
+ return $this->index; |
|
23 |
+ } |
|
24 |
+ |
|
25 |
+ public function getIndex(){ |
|
26 |
+ return $this->registry; |
|
27 |
+ } |
|
28 |
+} |
|
0 | 29 |
\ No newline at end of file |
... | ... |
@@ -5,74 +5,80 @@ namespace MVC\Classe; |
5 | 5 |
class Url |
6 | 6 |
{ |
7 | 7 |
public $page; |
8 |
+ public $registre; |
|
8 | 9 |
|
9 | 10 |
|
10 | 11 |
public function __construct(){ |
11 | 12 |
|
12 |
- $page = array(); |
|
13 |
- $page['name'] = 'accueil'; |
|
14 |
- $page['description'] = ""; |
|
15 |
- $page['params'] = array(); |
|
16 |
- $page['control'] = false; |
|
13 |
+ $this->registre = new \MVC\Classe\ModularRegister(); |
|
17 | 14 |
|
15 |
+ $page = array(); |
|
16 |
+ $page['name'] = 'accueil'; |
|
17 |
+ $page['description'] = ""; |
|
18 |
+ $page['params'] = array(); |
|
19 |
+ $page['control'] = false; |
|
18 | 20 |
|
19 | 21 |
|
20 |
- $url = parse_url($_SERVER['REQUEST_URI']); |
|
21 |
- $urlTrim = trim( $url['path'] , '/' ); |
|
22 |
- $urlParts = explode('/' , $urlTrim ); |
|
23 | 22 |
|
24 |
- //print_r($urlParts); |
|
25 |
- if(isset($urlParts[0])) { |
|
26 |
- //Récupération du nom de la page |
|
27 |
- ($urlParts[0] == 'index' || $urlParts[0] == '') ? $page['name'] = 'accueil' : $page['name'] = $urlParts[0]; |
|
28 |
- //array_shift($urlParts); |
|
29 |
- unset($urlParts[0]); |
|
30 |
- }else{ |
|
31 |
- $page['name'] = 'accueil'; |
|
32 |
- } |
|
23 |
+ $url = parse_url($_SERVER['REQUEST_URI']); |
|
24 |
+ $urlTrim = trim( $url['path'] , '/' ); |
|
25 |
+ $urlParts = explode('/' , $urlTrim ); |
|
26 |
+ |
|
27 |
+ //print_r($urlParts); |
|
28 |
+ if(isset($urlParts[0])) { |
|
29 |
+ //Récupération du nom de la page |
|
30 |
+ ($urlParts[0] == 'index' || $urlParts[0] == '') ? $page['name'] = 'accueil' : $page['name'] = $urlParts[0]; |
|
31 |
+ //array_shift($urlParts); |
|
32 |
+ unset($urlParts[0]); |
|
33 |
+ }else{ |
|
34 |
+ $page['name'] = 'accueil'; |
|
35 |
+ } |
|
33 | 36 |
|
34 |
- if($page['name'] == 'control'){ |
|
35 |
- $page['control'] = true; |
|
36 |
- ($urlParts[1] == 'index' || $urlParts[1] == '' ) ? $page['name']='accueil' : $page['name']=$urlParts[1]; |
|
37 |
- //array_shift($urlParts); |
|
38 |
- unset($urlParts[1]); |
|
37 |
+ if($page['name'] == 'control'){ |
|
38 |
+ $page['control'] = true; |
|
39 |
+ ($urlParts[1] == 'index' || $urlParts[1] == '' ) ? $page['name']='accueil' : $page['name']=$urlParts[1]; |
|
40 |
+ //array_shift($urlParts); |
|
41 |
+ unset($urlParts[1]); |
|
39 | 42 |
|
40 |
- } |
|
43 |
+ } |
|
41 | 44 |
|
42 |
- //vérification du nombre de parametres: s'il n'existe pas autant de clé que |
|
43 |
- // de valeurs on sort de la fonction et on renvoie une page d'erreur. |
|
44 |
- $numParts = count($urlParts); |
|
45 |
- if ( $numParts%2 != 0 ) { |
|
46 |
- $page['name'] = 'error'; |
|
47 |
- $page['params'] = array(); |
|
48 |
- return $page; |
|
49 |
- }else if ( $numParts != 0 ){ |
|
50 |
- $values = array(); |
|
51 |
- $keys = array(); |
|
52 |
- foreach( $urlParts as $key => $value ){ |
|
53 |
- if($key%2 == 0) { |
|
54 |
- $values[] = $value; |
|
55 |
- } else { |
|
56 |
- $keys[] = $value; |
|
57 |
- } |
|
58 |
- } |
|
59 |
- if($page['control']){ |
|
60 |
- $page['params'] = array_combine($values, $keys); |
|
45 |
+ //vérification du nombre de parametres: s'il n'existe pas autant de clé que |
|
46 |
+ // de valeurs on sort de la fonction et on renvoie une page d'erreur. |
|
47 |
+ $numParts = count($urlParts); |
|
48 |
+ if ( $numParts%2 != 0 ) { |
|
49 |
+ if( !in_array($page['name'], $this->registre->getIndex()) ){ |
|
50 |
+ $page['name'] = 'error'; |
|
51 |
+ $page['params'] = array(); |
|
52 |
+ return $page; |
|
53 |
+ } |
|
54 |
+ }else if ( $numParts != 0 ){ |
|
55 |
+ $values = array(); |
|
56 |
+ $keys = array(); |
|
57 |
+ foreach( $urlParts as $key => $value ){ |
|
58 |
+ if($key%2 == 0) { |
|
59 |
+ $values[] = $value; |
|
60 |
+ } else { |
|
61 |
+ $keys[] = $value; |
|
62 |
+ } |
|
63 |
+ } |
|
64 |
+ if($page['control']){ |
|
65 |
+ $page['params'] = array_combine($values, $keys); |
|
66 |
+ }else { |
|
67 |
+ $page['params'] = array_combine($keys, $values); |
|
68 |
+ } |
|
69 |
+ } |
|
70 |
+ |
|
71 |
+ //verification de l'existence de la page dans les controlleurs |
|
72 |
+ if($page['control']){ |
|
73 |
+ $pageFile = TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
61 | 74 |
}else { |
62 |
- $page['params'] = array_combine($keys, $values); |
|
75 |
+ $pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
63 | 76 |
} |
64 |
- } |
|
65 |
- |
|
66 |
- //verification de l'existence de la page dans les controlleurs |
|
67 |
- if($page['control']){ |
|
68 |
- $pageFile = TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
69 |
- }else { |
|
70 |
- $pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
71 |
- } |
|
72 |
- |
|
73 |
- if(!file_exists($pageFile)){ |
|
74 |
- $page['name'] = 'error'; |
|
75 |
- } |
|
76 |
- $this->page = $page; |
|
77 |
- } |
|
77 |
+ |
|
78 |
+ if(!file_exists($pageFile)){ |
|
79 |
+ $page['name'] = 'error'; |
|
80 |
+ } |
|
81 |
+ $this->page = $page; |
|
82 |
+ |
|
83 |
+ } |
|
78 | 84 |
} |