/** * Searches for a file in the [Cascading Filesystem](kohana/files), and * returns the path to the file that has the highest precedence, so that it * can be included. * * When searching the "config", "messages", or "i18n" directories, or when * the `$array` flag is set to true, an array of all the files that match * that path in the [Cascading Filesystem](kohana/files) will be returned. * These files will return arrays which must be merged together. * * If no extension is given, the default extension (`EXT` set in * `index.php`) will be used. * * // Returns an absolute path to views/template.php * Kohana::find_file('views', 'template'); * * // Returns an absolute path to media/css/style.css * Kohana::find_file('media', 'css/style', 'css'); * * // Returns an array of all the "mimes" configuration files * Kohana::find_file('config', 'mimes'); * * @param string $dir directory name (views, i18n, classes, extensions, etc.) * @param string $file filename with subdirectory * @param string $ext extension to search for * @param boolean $array return an array of files? * @param string $theme theme name or defaults to active * @return array a list of files when $array is TRUE * @return string single file path */ public static function find_file($dir, $file, $ext = NULL, $array = FALSE, $theme = NULL) { if ($ext === NULL) { // Use the default extension $ext = EXT; } elseif ($ext) { // Prefix the extension with a period $ext = ".{$ext}"; } else { // Use no extension $ext = ''; } //theme class may not be available during initial init phase if ($theme === NULL and class_exists('Theme')) { // Use the active theme $theme = Theme::$active; } // Create a partial path of the filename $path = $dir . DS . $file . $ext; if (Kohana::$caching === TRUE and isset(Kohana::$_files[$path . ($array ? '_array' : '_path')][$theme])) { // This path has been cached return Kohana::$_files[$path . ($array ? '_array' : '_path')][$theme]; } if (Kohana::$profiling === TRUE and class_exists('Profiler', FALSE)) { // Start a new benchmark $benchmark = Profiler::start('Kohana', __FUNCTION__); } if ($array or $dir === 'config' or $dir === 'i18n' or $dir === 'messages') { // Include paths must be searched in reverse $paths = array_reverse(Kohana::$_paths); // Array of files that have been found $found = array(); foreach ($paths as $dir) { if (is_file($dir . $path)) { // This path has a file, add it to the list $found[] = $dir . $path; } } } else { // The file has not been found yet $found = FALSE; foreach (Kohana::$_paths as $dir) { if (is_file($dir . $path)) { // A path has been found $found = $dir . $path; // Stop searching break; } } } if (Kohana::$caching === TRUE) { // Add the path to the cache Kohana::$_files[$path . ($array ? '_array' : '_path')][$theme] = $found; // Files have been changed Kohana::$_files_changed = TRUE; } if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } return $found; }
/** * Finds the path of a file by directory, filename, and extension. * If no extension is given, the default EXT extension will be used. * * When searching the "config" or "i18n" directories, or when the * $aggregate_files flag is set to true, 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 * Kohana::find_file('views', 'template'); * * // Returns an absolute path to media/css/style.css * Kohana::find_file('media', 'css/style', 'css'); * * // Returns an array of all the "mimes" configuration file * Kohana::find_file('config', 'mimes'); * * @param string directory name (views, i18n, classes, extensions, etc.) * @param string filename with subdirectory * @param string extension to search for * @param boolean return an array of files? * @return array a list of files when $array is TRUE * @return string single file path */ public static function find_file($dir, $file, $ext = NULL, $array = FALSE) { // Use the defined extension by default $ext = $ext === NULL ? EXT : '.' . $ext; // Create a partial path of the filename $path = $dir . DIRECTORY_SEPARATOR . $file . $ext; if (Kohana::$caching === TRUE and isset(Kohana::$_files[$path])) { // This path has been cached return Kohana::$_files[$path]; } if (Kohana::$profiling === TRUE and class_exists('Profiler', FALSE)) { // Start a new benchmark $benchmark = Profiler::start('Kohana', __FUNCTION__); } if ($array or $dir === 'config' or $dir === 'i18n' or $dir === 'messages') { // Include paths must be searched in reverse $paths = array_reverse(Kohana::$_paths); // Array of files that have been found $found = array(); foreach ($paths as $dir) { if (is_file($dir . $path)) { // This path has a file, add it to the list $found[] = $dir . $path; } } } else { // The file has not been found yet $found = FALSE; foreach (Kohana::$_paths as $dir) { if (is_file($dir . $path)) { // A path has been found $found = $dir . $path; // Stop searching break; } } } if (Kohana::$caching === TRUE) { // Add the path to the cache Kohana::$_files[$path] = $found; // Files have been changed Kohana::$_files_changed = TRUE; } if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } return $found; }
/** * Searches for a file in the [Cascading Filesystem](kohana/files), and * returns the path to the file that has the highest precedence, so that it * can be included. * * When searching the "config", "messages", or "i18n" directories, or when * the `$array` flag is set to true, an array of all the files that match * that path in the [Cascading Filesystem](kohana/files) will be returned. * These files will return arrays which must be merged together. * * If no extension is given, the default extension (`EXT` set in * `index.php`) will be used. * * // Returns an absolute path to views/template.php * Kohana::find_file('views', 'template'); * * // Returns an absolute path to media/css/style.scss * Kohana::find_file('media', 'css/style', 'css'); * * // Returns an array of all the "mimes" configuration files * Kohana::find_file('config', 'mimes'); * * @param string $dir directory name (views, i18n, classes, extensions, etc.) * @param string $file filename with subdirectory * @param string $ext extension to search for * @param boolean $array return an array of files? * * @return array a list of files when $array is TRUE * @return string single file path */ public static function find_file($dir, $file, $ext = null, $array = false) { if ($ext === null) { // Use the default extension $ext = EXT; } elseif ($ext) { // Prefix the extension with a period $ext = ".{$ext}"; } else { // Use no extension $ext = ''; } // Create a partial path of the filename $path = $dir . DIRECTORY_SEPARATOR . $file . $ext; if (Kohana::$caching === true and isset(Kohana::$_files[$path . ($array ? '_array' : '_path')])) { // This path has been cached return Kohana::$_files[$path . ($array ? '_array' : '_path')]; } if (Kohana::$profiling === true and class_exists('Profiler', false)) { // Start a new benchmark $benchmark = Profiler::start('Kohana', __FUNCTION__); } if ($array or $dir === 'config' or $dir === 'i18n' or $dir === 'messages') { // Include paths must be searched in reverse $paths = array_reverse(Kohana::$_paths); // Array of files that have been found $found = []; foreach ($paths as $dir) { if (is_file($dir . $path)) { // This path has a file, add it to the list $found[] = $dir . $path; } } } else { // The file has not been found yet $found = false; foreach (Kohana::$_paths as $dir) { if (is_file($dir . $path)) { // A path has been found $found = $dir . $path; // Stop searching break; } } } if (Kohana::$caching === true) { // Add the path to the cache Kohana::$_files[$path . ($array ? '_array' : '_path')] = $found; // Files have been changed Kohana::$_files_changed = true; } if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } return $found; }