src\Controller\Routes.php line 140

  1. <?php
  2. namespace App\Controller;
  3. use LogicException;
  4. use App\Objects\User\User;
  5. use App\Objects\Redirection;
  6. use Klio\KlioBundle\Security\Hash;
  7. use Klio\KlioBundle\Security\Sanitizer;
  8. use Klio\KlioBundle\Symfony\Controller;
  9. use Klio\KlioBundle\Symfony\RouteController;
  10. use Psr\Container\NotFoundExceptionInterface;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Psr\Container\ContainerExceptionInterface;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
  16. use Symfony\Component\HtmlSanitizer\HtmlSanitizerInterface;
  17. class Routes extends RouteController
  18. {
  19.     /**
  20.      * @param HtmlSanitizerInterface $htmlSanitizer
  21.      * @param Request $request 
  22.      * @return Response 
  23.      * @throws LogicException 
  24.      * @throws NotFoundExceptionInterface 
  25.      * @throws ContainerExceptionInterface 
  26.      */
  27.     #[Route(
  28.         '/FW7/{subpath}',
  29.         name'FW7',
  30.         methods: ['GET''HEAD''POST'],
  31.         requirements: ['subpath' => '.*']
  32.     )]
  33.     public function FW7(Request $requestHtmlSanitizerInterface $sanitizer): Response
  34.     {
  35.         ob_clean();
  36.         // initialize l'object RouteController 
  37.         // defini les constantes avec un fichier de config en option
  38.         $this->init(); // $this->init("/private/Config.php");
  39.         //$Sanitizer = new Sanitizer("body");
  40.         global $FW;
  41.         require_once($_ENV['PACKAGES_FOLDER'] . '/frameworks/FW7/prepend_FW7.php');
  42.         /* === la logique propre à ce groupe de routes === */
  43.         // on force toutes ces routes à utiliser le même controller spécifique
  44.         $this->setController('/FW7/Controller7.php');
  45.         /* === la logique propre à ce groupe de routes === */
  46.         // On renvoie le résultat
  47.         return new Response($this->getResponse(), $this->getStatus());
  48.     }
  49.     /**
  50.      * @param HtmlSanitizerInterface $htmlSanitizer
  51.      * @param Request $request 
  52.      * @return Response 
  53.      * @throws LogicException 
  54.      * @throws NotFoundExceptionInterface 
  55.      * @throws ContainerExceptionInterface 
  56.      */
  57.     #[Route(
  58.         '/admin{subpath}',
  59.         name'admin',
  60.         methods: ['GET''HEAD''POST'],
  61.         requirements: ['subpath' => '^.{0}|/.*$']
  62.     )]
  63.     public function admin(Request $requestHtmlSanitizerInterface $sanitizer): Response
  64.     {
  65.         // les varaibales de base
  66.         $this->init();
  67.         // authentifiction
  68.         global $USER;
  69.         $USER = new User();
  70.         if (!$USER->auth()) $this->setController('/_login/Controller.php');
  71.         //$this->setController('/FW7/admin/Controller7.php');
  72.         /* === la logique propre à ce groupe de routes === */
  73.         // On renvoie le résultat
  74.         return new Response($this->getResponse(), $this->getStatus());
  75.     }
  76.     /**
  77.      * @param Request $request 
  78.      * @return Response 
  79.      * @throws LogicException 
  80.      * @throws NotFoundExceptionInterface 
  81.      * @throws ContainerExceptionInterface 
  82.      */
  83.     #[Route(
  84.         '/actualites/{subpath}',
  85.         name'actualites',
  86.         methods: ['GET''HEAD''POST'],
  87.         requirements: ['subpath' => '.+$']
  88.     )]
  89.     public function actualites(HtmlSanitizerInterface $sanitizerRequest $request): Response
  90.     {
  91.         // initialize l'object RouteController 
  92.         $this->init(); // $this->init("/private/Config.php");
  93.         // Redirection
  94.         Redirection::verifHost();
  95.         /* === la logique propre à ce groupe de routes === */
  96.         // on force toutes ces routes à utiliser le même controller spécifique
  97.         $this->setController('/actualites/Controller.php');
  98.         // On renvoie le résultat
  99.         return new Response($this->getResponse(), $this->getStatus());
  100.     }
  101.     /**
  102.      * @param Request $request 
  103.      * @return Response 
  104.      * @throws LogicException 
  105.      * @throws NotFoundExceptionInterface 
  106.      * @throws ContainerExceptionInterface 
  107.      */
  108.     #[Route(
  109.         '/{subpath}',
  110.         name'page',
  111.         methods: ['GET''HEAD''POST'],
  112.         requirements: ['subpath' => ".*(?:formation|paie|conseil|cooperative|mediation|bureau_danse|mentions_legales)\b(\/.*|.{0})"],
  113.     )]
  114.     public function page(Request $requestHtmlSanitizerInterface $sanitizer): Response
  115.     {
  116.         // initialize l'object RouteController 
  117.         // defini les constantes avec un fichier de config en option
  118.         $this->init(); // $this->init("/private/Config.php");
  119.         // Redirection
  120.         Redirection::verifHost();
  121.         /* === la logique propre à ce groupe de routes === */
  122.         // on ajoute un controller au controller /path/Controller.php
  123.         $this->setController('/page/Controller.php');
  124.         /* === la logique propre à ce groupe de routes === */
  125.         // On renvoie le résultat
  126.         return new Response($this->getResponse(), $this->getStatus());
  127.     }
  128.     /**
  129.      * @param Request $request 
  130.      * @return Response 
  131.      * @throws LogicException 
  132.      * @throws NotFoundExceptionInterface 
  133.      * @throws ContainerExceptionInterface 
  134.      */
  135.     #[Route(
  136.         '/{subpath}',
  137.         name'formations',
  138.         methods: ['GET''HEAD''POST'],
  139.         requirements: ['subpath' => ".*formations"],
  140.     )]
  141.     public function formations(Request $requestHtmlSanitizerInterface $sanitizer): Response
  142.     {
  143.         // initialize l'object RouteController 
  144.         // defini les constantes avec un fichier de config en option
  145.         $this->init(); // $this->init("/private/Config.php");
  146.         // Redirection
  147.         Redirection::verifHost();
  148.         /* === la logique propre à ce groupe de routes === */
  149.         // on ajoute un controller au controller /path/Controller.php
  150.         $this->setController('/formations/Controller.php');
  151.         /* === la logique propre à ce groupe de routes === */
  152.         // On renvoie le résultat
  153.         return new Response($this->getResponse(), $this->getStatus());
  154.     }
  155.     /**
  156.      * @param Request $request 
  157.      * @return Response 
  158.      * @throws LogicException 
  159.      * @throws NotFoundExceptionInterface 
  160.      * @throws ContainerExceptionInterface 
  161.      */
  162.     #[Route(
  163.         '/formations/{subpath}',
  164.         name'formation',
  165.         methods: ['GET''HEAD''POST'],
  166.         requirements: ['subpath' => ".+$"],
  167.     )]
  168.     public function formation(Request $requestHtmlSanitizerInterface $sanitizer): Response
  169.     {
  170.         $subpath $request->attributes->get('_route_params')["subpath"];
  171.         // initialize l'object RouteController 
  172.         // defini les constantes avec un fichier de config en option
  173.         $this->init(); // $this->init("/private/Config.php");
  174.         // Redirection
  175.         Redirection::verifHost();
  176.         /* === la logique propre à ce groupe de routes === */
  177.         // on ajoute un controller au controller /path/Controller.php
  178.         if ($subpath === "detail")
  179.             $this->setController('/formations/detail/Controller.php');
  180.         else
  181.             $this->setController('/formations/formation/Controller.php');
  182.         /* === la logique propre à ce groupe de routes === */
  183.         // On renvoie le résultat
  184.         return new Response($this->getResponse(), $this->getStatus());
  185.     }
  186.     /**
  187.      * @param Request $request 
  188.      * @return Response 
  189.      * @throws LogicException 
  190.      * @throws NotFoundExceptionInterface 
  191.      * @throws ContainerExceptionInterface 
  192.      */
  193.     #[Route(
  194.         '/formations_partenaires/{subpath}',
  195.         name'formation-partenaire',
  196.         methods: ['GET''HEAD''POST'],
  197.         requirements: ['subpath' => ".+$"],
  198.     )]
  199.     public function formationPartenaire(Request $requestHtmlSanitizerInterface $sanitizer): Response
  200.     {
  201.         $subpath $request->attributes->get('_route_params')["subpath"];
  202.         // initialize l'object RouteController 
  203.         // defini les constantes avec un fichier de config en option
  204.         $this->init(); // $this->init("/private/Config.php");
  205.         // Redirection
  206.         Redirection::verifHost();
  207.         /* === la logique propre à ce groupe de routes === */
  208.         // on ajoute un controller au controller /path/Controller.php
  209.         if ($subpath === "detail")
  210.             $this->setController('/formations_partenaires/detail/Controller.php');
  211.         else
  212.             $this->setController('/formations_partenaires/formation/Controller.php');
  213.         /* === la logique propre à ce groupe de routes === */
  214.         // On renvoie le résultat
  215.         return new Response($this->getResponse(), $this->getStatus());
  216.     }
  217.     /**
  218.      * @param Request $request 
  219.      * @return Response 
  220.      * @throws LogicException 
  221.      * @throws NotFoundExceptionInterface 
  222.      * @throws ContainerExceptionInterface 
  223.      */
  224.     #[Route(
  225.         '/{subpath}',
  226.         name'all',
  227.         methods: ['GET''HEAD''POST'],
  228.         requirements: ['subpath' => ".*"],
  229.     )]
  230.     public function all(Request $requestHtmlSanitizerInterface $sanitizer): Response
  231.     {
  232.         // initialize l'object RouteController 
  233.         // defini les constantes avec un fichier de config en option
  234.         $this->init(); // $this->init("/private/Config.php");
  235.         // Redirection
  236.         Redirection::verifHost();
  237.         /* === la logique propre à ce groupe de routes === */
  238.         // on ajoute un controller au controller /path/Controller.php
  239.         //$this->setController('/page/Controller.php');
  240.         /* === la logique propre à ce groupe de routes === */
  241.         // On renvoie le résultat
  242.         return new Response($this->getResponse(), $this->getStatus());
  243.     }
  244.     /**
  245.      * Routes::notFound(Controller) défini le comportement du site en cas de d'erreur 404
  246.      * on peut renvoyer certaines infos, choisir d'inclure un Template404.twig spécifique, ou inclure une ogique pour des 404 différenciés
  247.      * on renvoyer en général un $CONTROLLER->setTemplate(string) (on peut ajouter des variables twig $CONTROLLER->setTwig(array)) et un $CONTROLLER->setStatus(404)
  248.      * Mais on peut aussi renvoyer un $CONTROLLER->setResponse(string) pour certaines routes de type API
  249.      *
  250.      * @param Controller $CONTROLLER
  251.      * @return void
  252.      */
  253.     public static function notFound(Controller &$CONTROLLER)
  254.     {
  255.         $CONTROLLER->setStatus(404);
  256.         if (str_contains(__URL__"/formations/") || str_contains(__URL__"/formations_partenaires/"))
  257.             $CONTROLLER->setTemplate('/404formation.twig');
  258.         else
  259.             $CONTROLLER->setTemplate('/404.twig');
  260.     }
  261. }