Exemple #1
0
 /**
  * Find given Template View file in defined Views Directories
  *
  * @param string|optional $file
  *   Template View File
  *
  * @return string
  *   Template View Filepath
  *
  * @throws Next\View\ViewException
  *   There are no directories assigned to iterate and search the file
  *
  * @throws Next\View\ViewException
  *   No file could be found
  */
 private function findFile($file = NULL)
 {
     // Do we have a Default Template? So let's use it!
     $file = !empty($this->_defaultTemplate) ? $this->_defaultTemplate : $file;
     // Cleaning dots and slashes around Template View Filename
     $file = trim($file, './');
     // If still empty, let's check if FileSpec detection is enabled
     if (empty($file) && !$this->_useFileSpec) {
         throw ViewException::disabledFileSpec();
     }
     // No paths to iterate?
     if (count($this->_paths) == 0 && is_null($this->_basepath)) {
         throw ViewException::noPaths($file);
     }
     // If we don't have a Template View Name, we will use the FileSpec ability
     $file = !empty($file) ? $file : $this->findFileBySpec();
     // Adding File extension, if no one was defined yet
     if (strrpos($file, $added = sprintf('.%s', $this->_extension)) === FALSE) {
         $file .= $added;
     }
     // Do we have more than one View Path?
     /**
      * @internal
      * Test if this separation is REALLY necessary
      */
     if (count($this->_paths) == 0) {
         // Building the Filename
         $templateFile = sprintf('%s/%s%s', $this->_basepath, $this->_subpath, $file);
         // And a cleaned version (without basepath) for possible Exceptions
         $file = sprintf('%s%s', $this->_subpath, $file);
         // Checking if the file exists and if it is readable
         if (file_exists($templateFile) && is_readable($templateFile)) {
             return $templateFile;
         }
     } else {
         foreach ($this->_paths as $path) {
             // Building the Filename
             $templateFile = sprintf('%s/%s/%s%s', $this->_basepath, $path, $this->_subpath, $file);
             // And a cleaned version (without basepath) for possible Exceptions
             $file = sprintf('%s/%s%s', $path, $this->_subpath, $file);
             // Checking if the file exists and if it is readable
             if (file_exists($templateFile) && is_readable($templateFile)) {
                 return $templateFile;
             }
         }
     }
     // No file could be found, let's condition Exceptions' Messages
     if ($this->_useFileSpec) {
         if (!empty($this->_subpath)) {
             throw ViewException::wrongUseOfSubpath($file);
         } else {
             throw ViewException::unableToFindUnderFileSpec($file);
         }
     } else {
         throw ViewException::missingFile($file);
     }
 }