Пример #1
0
 /**
  * create_csrf, fonction permetant de récupérer le token généré
  *
  * @param int $time [optional]
  * @return \StdClass
  */
 function create_csrf_token($time = null)
 {
     Security::createCsrfToken($time);
     return Security::getCsrfToken();
 }
Пример #2
0
 /**
  * templateLoader, charge le moteur template à utiliser.
  *
  * @throws ErrorException
  * @return \Twig_Environment|\Mustache_Engine|\Jade\Jade
  */
 private function templateLoader()
 {
     if ($this->config->getTemplateEngine() !== null) {
         if (!in_array($this->config->getTemplateEngine(), ['twig', 'mustache', 'jade'], true)) {
             throw new ErrorException('Le moteur de template n\'est pas implementé.', E_USER_ERROR);
         }
     } else {
         throw new ResponseException('Le moteur de template non défini.', E_USER_ERROR);
     }
     $tpl = null;
     if ($this->config->getTemplateEngine() == 'twig') {
         $loader = new \Twig_Loader_Filesystem($this->config->getViewpath());
         $tpl = new \Twig_Environment($loader, ['cache' => $this->config->getCachepath(), 'auto_reload' => $this->config->getCacheAutoReload(), 'debug' => $this->config->getLoggerMode() == 'develepment' ? true : false]);
         /**
          * - Ajout de variable globale
          * dans le cadre de l'utilisation de Twig
          */
         $tpl->addGlobal('public', $this->config->getPublicPath());
         $tpl->addGlobal('root', $this->config->getApproot());
         /**
          * - Ajout de fonction global
          *  dans le cadre de l'utilisation de Twig
          */
         $tpl->addFunction(new \Twig_SimpleFunction('secure', function ($data) {
             return Security::sanitaze($data, true);
         }));
         $tpl->addFunction(new \Twig_SimpleFunction('sanitaze', function ($data) {
             return Security::sanitaze($data);
         }));
         $tpl->addFunction(new \Twig_SimpleFunction('csrf_field', function () {
             return Security::getCsrfToken()->field;
         }));
         $tpl->addFunction(new \Twig_SimpleFunction('csrf_token', function () {
             return Security::getCsrfToken()->token;
         }));
         $tpl->addFunction(new \Twig_SimpleFunction('slugify', [Str::class, 'slugify']));
         return $tpl;
     }
     if ($this->config->getTemplateEngine() == 'mustache') {
         return new \Mustache_Engine(['cache' => $this->config->getCachepath(), 'loader' => new \Mustache_Loader_FilesystemLoader($this->config->getViewpath()), 'helpers' => ['secure' => function ($data) {
             return Security::sanitaze($data, true);
         }, 'sanitaze' => function ($data) {
             return Security::sanitaze($data);
         }, 'slugify' => function ($data) {
             return Str::slugify($data);
         }, 'csrf_token' => function () {
             return Security::getCsrfToken()->token;
         }, 'csrf_field' => function () {
             return Security::getCsrfToken()->field;
         }, 'public', $this->config->getPublicPath(), 'root', $this->config->getApproot()]]);
     }
     return new Jade(['cache' => $this->config->getCachepath(), 'prettyprint' => true, 'extension' => $this->config->getTemplateExtension()]);
 }