Example #1
0
 /**
  * Finds a file in the given directory.  It allows for a cascading filesystem.
  *
  * @access	public
  * @param	string	The directory to look in.
  * @param	string	The name of the file
  * @param	string	The file extension
  * @return	string	The path to the file
  */
 public static function find_file($directory, $file, $ext = '.php', $multiple = false)
 {
     $path = $directory . DS . strtolower($file) . $ext;
     if (static::$path_cache !== null && array_key_exists($path, static::$path_cache)) {
         return static::$path_cache[$path];
     }
     $paths = static::$_paths;
     // get the paths of the active request, and search them first
     if (class_exists('Request', false) and $active = \Request::active()) {
         $paths = array_merge($active->paths, $paths);
     }
     $found = $multiple ? array() : false;
     foreach ($paths as $dir) {
         $file_path = $dir . $path;
         if (is_file($file_path)) {
             if (!$multiple) {
                 $found = $file_path;
                 break;
             }
             $found[] = $file_path;
         }
     }
     static::$path_cache[$path] = $found;
     static::$paths_changed = true;
     return $found;
 }
Example #2
0
 /**
  * Finds a file in the given directory.  It allows for a cascading filesystem.
  *
  * @param   string   The directory to look in.
  * @param   string   The name of the file
  * @param   string   The file extension
  * @param   boolean  if true return an array of all files found
  * @param   boolean  if false do not cache the result
  * @return  string   the path to the file
  */
 public static function find_file($directory, $file, $ext = '.php', $multiple = false, $cache = true)
 {
     $cache_id = '';
     $paths = static::$_paths;
     // get extra information of the active request
     if (class_exists('Request', false) and $active = \Request::active()) {
         $cache_id = md5($active->uri->uri);
         $paths = array_merge($active->paths, $paths);
     }
     $path = $directory . DS . strtolower($file) . $ext;
     if (static::$path_cache !== null && array_key_exists($cache_id . $path, static::$path_cache)) {
         return static::$path_cache[$cache_id . $path];
     }
     $found = $multiple ? array() : false;
     foreach ($paths as $dir) {
         $file_path = $dir . $path;
         if (is_file($file_path)) {
             if (!$multiple) {
                 $found = $file_path;
                 break;
             }
             $found[] = $file_path;
         }
     }
     if (!empty($found)) {
         $cache and static::$path_cache[$cache_id . $path] = $found;
         static::$paths_changed = true;
     }
     return $found;
 }
Example #3
0
 /**
  * Finds a file in the given directory.  It allows for a cascading filesystem.
  *
  * @param   string   The directory to look in.
  * @param   string   The name of the file
  * @param   string   The file extension
  * @param   boolean  if true return an array of all files found
  * @param   boolean  if false do not cache the result
  * @return  string   the path to the file
  */
 public static function find_file($directory, $file, $ext = '.php', $multiple = false, $cache = true)
 {
     // absolute path requested?
     if (strpos($file, '/') === 0 or strpos($file, ':') === 1) {
         return is_file($file) ? $file : false;
     }
     $cache_id = '';
     $paths = array();
     $found = $multiple ? array() : false;
     // the file requested namespaced?
     if ($pos = strripos($file, '::')) {
         // get the namespace path
         if ($path = \Autoloader::namespace_path('\\' . ucfirst(substr($file, 0, $pos)))) {
             $cache_id .= substr($file, 0, $pos);
             // and strip the classes directory as we need the module root
             $paths = array(substr($path, 0, -8));
             // strip the namespace from the filename
             $file = substr($file, $pos + 2);
         }
     }
     // if not found, use the cascading filesystem to find the file
     if (empty($cache_id)) {
         $paths = static::$_paths;
         // get extra information of the active request
         if (class_exists('Request', false) and $active = \Request::active()) {
             $cache_id = $active->uri->uri;
             $paths = array_merge($active->paths, $paths);
         }
     }
     $paths = array_merge(static::$volatile_paths, $paths);
     $path = $directory . DS . strtolower($file) . $ext;
     $cache_id = md5(($multiple ? 'M.' : 'S.') . $cache_id);
     if (static::$path_cache !== null and array_key_exists($cache_id . $path, static::$path_cache)) {
         static::$volatile_paths = array();
         return static::$path_cache[$cache_id . $path];
     }
     foreach ($paths as $dir) {
         $file_path = $dir . $path;
         if (is_file($file_path)) {
             if (!$multiple) {
                 $found = $file_path;
                 break;
             }
             $found[] = $file_path;
         }
     }
     if (!empty($found)) {
         $cache and static::$path_cache[$cache_id . $path] = $found;
         static::$paths_changed = true;
     }
     static::$volatile_paths = array();
     return $found;
 }
Example #4
0
File: fuel.php Project: ralf57/fuel
	/**
	 * Finds a file in the given directory.  It allows for a cascading filesystem.
	 *
	 * @access	public
	 * @param	string	The directory to look in.
	 * @param	string	The name of the file
	 * @param	string	The file extension
	 * @return	string	The path to the file
	 */
	public static function find_file($directory, $file, $ext = '.php', $multiple = false)
	{
		$path = $directory.DS.strtolower($file).$ext;

		if (static::$path_cache !== null && array_key_exists($path, static::$path_cache))
		{
			return static::$path_cache[$path];
		}

		$found = $multiple ? array() : false;
		foreach (static::$_paths as $dir)
		{
			$file_path = $dir.$path;
			if (is_file($file_path))
			{
				if ($multiple)
				{
					$found[] = $file_path;
				}
				else
				{
					$found = $file_path;
					break;
				}
			}
		}

		static::$path_cache[$path] = $found;
		static::$paths_changed = true;

		return $found;
	}