コード例 #1
0
ファイル: Parser.php プロジェクト: patmtp35/Teleinfo
 /**
  * Check if the template exist and compile it if necessary
  *
  * @param string $template: name of the file of the template
  *
  * @throw \Rain\Tpl\NotFoundException the file doesn't exists
  * @return string: full filepath that php must use to include
  */
 protected function checkTemplate($template)
 {
     // set filename
     $templateName = basename($template);
     $templateBasedir = strpos($template, DIRECTORY_SEPARATOR) ? dirname($template) . DIRECTORY_SEPARATOR : null;
     $templateDirectory = null;
     $templateFilepath = null;
     $parsedTemplateFilepath = null;
     // Make directories to array for multiple template directory
     $templateDirectories = $this->config['tpl_dir'];
     if (!is_array($templateDirectories)) {
         $templateDirectories = array($templateDirectories);
     }
     $isFileNotExist = true;
     foreach ($templateDirectories as $templateDirectory) {
         $templateDirectory .= $templateBasedir;
         $templateFilepath = $templateDirectory . $templateName . '.' . $this->config['tpl_ext'];
         $parsedTemplateFilepath = $this->config['cache_dir'] . $templateName . "." . md5($templateDirectory . serialize($this->config['checksum'])) . '.rtpl.php';
         // For check templates are exists
         if (file_exists($templateFilepath)) {
             $isFileNotExist = false;
             break;
         }
     }
     // if the template doesn't exsist throw an error
     if ($isFileNotExist === true) {
         $e = new NotFoundException('Template ' . $templateName . ' not found!');
         throw $e->templateFile($templateFilepath);
     }
     // Compile the template if the original has been updated
     if ($this->config['debug'] || !file_exists($parsedTemplateFilepath) || filemtime($parsedTemplateFilepath) < filemtime($templateFilepath)) {
         $this->compileFile($templateName, $templateBasedir, $templateDirectory, $templateFilepath, $parsedTemplateFilepath);
     }
     return $parsedTemplateFilepath;
 }
コード例 #2
0
 /**
  * Check if the template exist and compile it if necessary
  *
  * @param string $filePath: the path to the template file
  *
  * @throw \Rain\NotFoundException the file doesn't exists
  */
 protected function checkTemplate($filePath)
 {
     $db = new Db();
     $filePath = $this->config['tpl_dir'] . $filePath . '.' . $this->config['tpl_ext'];
     // get template from Db
     list($html, $md5_stored) = $db->getTemplate($filePath);
     // in case of production option is true, the actual templates are not required
     // it is one step from here to removing templates after compilation
     if (!$this->config['production']) {
         // Check if template exists
         if (!file_exists($filePath)) {
             $e = new NotFoundException('Template ' . $filePath . ' not found!');
             throw $e->templateFile($filePath);
         }
         // Compile the template if the original has been updated
         $md5_current = md5_file($filePath);
         if ($this->config['debug'] || $md5_stored != $md5_current) {
             // compile the template
             $html = (new Parser())->compileFile($this->config, $filePath);
             // store the update in Db
             $db->storeTemplate($html, $filePath, $md5_current);
         }
     }
     return $html;
 }