Example #1
0
 /**
  * Finds the path of a file by directory, filename, and extension.
  * If no extension is given, the default extension will be used.
  *
  * When searching the "config" directory, an array of files
  * will be returned. These files will return arrays which must be
  * merged together.
  *
  *     // Returns an absolute path to views/template.php
  *     Ko::findFile('views', 'template');
  *
  *     // Returns an absolute path to media/css/style.css
  *     Ko::findFile('media', 'css/style', 'css');
  *
  *     // Returns an array of all the "mimes" configuration file
  *     Ko::findFile('config', 'mimes');
  *
  * @param   string   directory name (views, extensions, etc.)
  * @param   string   filename with subdirectory
  * @param   string   extension to search for
  * @return  array    file list from the "config" or "messages" directories
  * @return  string   single file path
  */
 public static function findFile($dir, $file, $ext = NULL)
 {
     $ext = $ext === NULL ? '.php' : '.' . $ext;
     $path = $dir . DIRECTORY_SEPARATOR . $file . $ext;
     if (self::$caching === TRUE and isset(self::$_files[$path])) {
         return self::$_files[$path];
     }
     if ($dir === 'controllers' || $dir === 'views' || $dir === 'models') {
         $found = FALSE;
         if (is_file(APP_PATH . $path)) {
             $found = APP_PATH . $path;
         }
     } elseif ($dir === 'config' || $dir === 'i18n') {
         $found = array();
         if (is_file(DATA_PATH . $path)) {
             $found[] = DATA_PATH . $path;
         }
     } else {
         // The file has not been found yet
         $found = FALSE;
         foreach (self::$_paths as $dir) {
             if (is_file($dir . $path)) {
                 // A path has been found
                 $found = $dir . $path;
                 // Stop searching
                 break;
             }
         }
     }
     if (self::$caching === TRUE) {
         // Add the path to the cache
         self::$_files[$path] = $found;
         // Files have been changed
         self::$_files_changed = TRUE;
     }
     return $found;
 }