diff options
| author | polo <ordipolo@gmx.fr> | 2026-10-23 00:47:32 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-10-23 00:47:32 +0200 |
| commit | f27cca08ff786ceff1870147f6d6bad14d71117f (patch) | |
| tree | d36597a72025313d6faf4ed228755fa267ebe2f6 /src/model/Path.php | |
| parent | c7309f900ef05bd5cb313110ec159b761af394ec (diff) | |
| download | cms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.gz cms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.bz2 cms-f27cca08ff786ceff1870147f6d6bad14d71117f.zip | |
dossiers avec majuscule, namespace pour toutes les classes, autoload psr-4, UserDataService::createZip déplacé dans Backup
Diffstat (limited to 'src/model/Path.php')
| -rw-r--r-- | src/model/Path.php | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/src/model/Path.php b/src/model/Path.php deleted file mode 100644 index 4303952..0000000 --- a/src/model/Path.php +++ /dev/null | |||
| @@ -1,76 +0,0 @@ | |||
| 1 | <?php | ||
| 2 | // src/model/Path.php | ||
| 3 | // | ||
| 4 | // attention, cette classe dépend de src/model/Menu.php | ||
| 5 | |||
| 6 | declare(strict_types=1); | ||
| 7 | |||
| 8 | use Doctrine\ORM\EntityManager; | ||
| 9 | use App\Entity\Page; | ||
| 10 | |||
| 11 | class Path extends Page | ||
| 12 | { | ||
| 13 | private array $current_page = []; // tableau d'objets Page | ||
| 14 | |||
| 15 | public function __construct() | ||
| 16 | { | ||
| 17 | $path_array = explode('/', CURRENT_PAGE); | ||
| 18 | try{ | ||
| 19 | // parcourir le menu de haut en bas pour obtenir un ou plusieurs objets Page | ||
| 20 | $this->findPage(Model::$menu, $path_array); // remplit $this->current_page | ||
| 21 | } | ||
| 22 | catch(Exception $e){} | ||
| 23 | } | ||
| 24 | |||
| 25 | // produit un tableau de Page en comparant le chemin demandé avec les données dans Menu | ||
| 26 | // succès => une exception est lancée pour sortir des fonctions imbriquées | ||
| 27 | // echec => redirection vers la page erreur 404 | ||
| 28 | private function findPage(Page|Menu $menu, array $path_array): void | ||
| 29 | { | ||
| 30 | // recherche dans les autres pages | ||
| 31 | if($menu instanceof Menu){ | ||
| 32 | foreach($menu->getOtherPages() as $page){ | ||
| 33 | if($path_array[0] === $page->getEndOfPath()){ | ||
| 34 | $this->current_page[] = $page; | ||
| 35 | throw new Exception(); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | // recherche dans le menu | ||
| 40 | foreach($menu->getChildren() as $page){ | ||
| 41 | if($path_array[0] === $page->getEndOfPath()){ | ||
| 42 | $this->current_page[] = $page; | ||
| 43 | if(count($path_array) > 1){ | ||
| 44 | array_shift($path_array); // $this->path_array n'est pas modifié, un tableau PHP est passé à une fonction par copie | ||
| 45 | $this->findPage($page, $path_array); | ||
| 46 | } | ||
| 47 | else{ | ||
| 48 | throw new Exception(); // sortir de tous les findPage() en même temps | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | // rien trouvé | ||
| 54 | header('Location: '. new URL(['page' => Model::$menu->getChildren()[0]->getEndOfPath()])); | ||
| 55 | die; | ||
| 56 | } | ||
| 57 | |||
| 58 | public function getString(): string | ||
| 59 | { | ||
| 60 | $path_string = ""; | ||
| 61 | foreach($this->current_page as $one_page){ | ||
| 62 | $path_string .= $one_page->getEndOfPath() . '/'; | ||
| 63 | } | ||
| 64 | return rtrim($path_string, '/'); | ||
| 65 | } | ||
| 66 | public function getArray(): array | ||
| 67 | { | ||
| 68 | return $this->current_page; | ||
| 69 | } | ||
| 70 | |||
| 71 | // c'est là qu'on est quoi | ||
| 72 | public function getLast(): Page | ||
| 73 | { | ||
| 74 | return $this->current_page[count($this->current_page) - 1]; | ||
| 75 | } | ||
| 76 | } \ No newline at end of file | ||
