예제 #1
0
 /**
  * Ajout une route nommé.
  *
  * @param string $uri  L'url pointant sur la route.
  * @param string $name Le nom de la routes
  */
 private function namedRoute($uri, $name)
 {
     $route[$name] = $uri;
     $routes = $this->config->getApplicationRoutes();
     $routes = array_merge($routes, $route);
     $this->config->setApplicationRoutes($routes);
 }
예제 #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()]);
 }
예제 #3
0
파일: helper.php 프로젝트: papac/framework
 /**
  * Application configuration
  * @param string|array $param
  * @param mixed $newConfig
  * @return AppConfiguration
  */
 function config($param = null, $newConfig = null)
 {
     $app_dir = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
     $config = AppConfiguration::configure(require $app_dir . '/config/bootstrap.php');
     if ($param === null) {
         return $config;
     }
     if (!in_array($param, ['name', 'engine', 'root', 'public', 'view path', 'logger', 'local', 'key', null])) {
         throw new InvalidArgumentException('Paramètre invalide.', E_USER_ERROR);
     }
     switch (true) {
         case $param === 'public':
             if ($newConfig === null) {
                 return $config->getPublicPath();
             }
             $config->setPublicPath($newConfig);
             break;
         case $param === 'engine':
             if ($newConfig === null) {
                 return $config->getTemplateEngine();
             }
             $config->setTemplateEngine($newConfig);
             break;
         case $param === 'root':
             if ($newConfig === null) {
             }
             return $config->getApproot();
             break;
         case $param === 'name':
             if ($newConfig === null) {
                 return $config->getAppname();
             }
             $config->setAppname($newConfig);
             break;
         case $param === 'route':
             return $config->getApplicationRoutes();
             break;
         case $param === 'view path':
             if ($newConfig === null) {
                 return $config->getViewpath();
             }
             $config->setViewpath($newConfig);
             break;
         case $param === 'logger':
             if ($newConfig === null) {
                 return $config->getLoggerMode();
             }
             $config->setLoggerMode($newConfig);
             break;
         case $param === 'mail':
             return $config->getMailConfiguration();
             break;
         case $param === 'db':
             return $config->getDatabaseConfiguration();
             break;
         case $param === 'key':
             if ($newConfig === null) {
                 return $config->getAppkey();
             }
             return $config->setAppkey($newConfig);
             break;
     }
     return $config;
 }