From f27cca08ff786ceff1870147f6d6bad14d71117f Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 23 Oct 2026 00:47:32 +0200 Subject: =?UTF-8?q?dossiers=20avec=20majuscule,=20namespace=20pour=20toute?= =?UTF-8?q?s=20les=20classes,=20autoload=20psr-4,=20UserDataService::creat?= =?UTF-8?q?eZip=20d=C3=A9plac=C3=A9=20dans=20Backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model/Path.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/Model/Path.php (limited to 'src/Model/Path.php') diff --git a/src/Model/Path.php b/src/Model/Path.php new file mode 100644 index 0000000..91eb2ff --- /dev/null +++ b/src/Model/Path.php @@ -0,0 +1,80 @@ +findPage(Model::$menu, $path_array); // remplit $this->current_page + } + catch(\Exception $e){} + } + + // produit un tableau de Page en comparant le chemin demandé avec les données dans Menu + // succès => une exception est lancée pour sortir des fonctions imbriquées + // echec => redirection vers la page erreur 404 + private function findPage(Page|Menu $menu, array $path_array): void + { + // recherche dans les autres pages + if($menu instanceof Menu){ + foreach($menu->getOtherPages() as $page){ + if($path_array[0] === $page->getEndOfPath()){ + $this->current_page[] = $page; + throw new \Exception(); + } + } + } + // recherche dans le menu + foreach($menu->getChildren() as $page){ + if($path_array[0] === $page->getEndOfPath()){ + $this->current_page[] = $page; + if(count($path_array) > 1){ + array_shift($path_array); // $this->path_array n'est pas modifié, un tableau PHP est passé à une fonction par copie + $this->findPage($page, $path_array); + } + else{ + throw new \Exception(); // sortir de tous les findPage() en même temps + } + } + } + + // rien trouvé + header('Location: '. new URL(['page' => Model::$menu->getChildren()[0]->getEndOfPath()])); + die; + } + + public function getString(): string + { + $path_string = ""; + foreach($this->current_page as $one_page){ + $path_string .= $one_page->getEndOfPath() . '/'; + } + return rtrim($path_string, '/'); + } + public function getArray(): array + { + return $this->current_page; + } + + // c'est là qu'on est quoi + public function getLast(): Page + { + return $this->current_page[count($this->current_page) - 1]; + } +} \ No newline at end of file -- cgit v1.2.3