Return the realpath of the given file or look for the first matching database option

@param string $file  File to try to find, or null to try the databases in turn on the current file's path
@return string
@throws \Exception
356754
private static function findFile($file = null) {
    if (null !== $file) {
      // Get actual file path
      $rfile = realpath($file);

      // If the file cannot be found, except away
      if (false === $rfile) {
        throw new \Exception(__CLASS__ . ": Database file '{$file}' does not seem to exist.", self::EXCEPTION_DBFILE_NOT_FOUND);
      }

      return $rfile;
    } else {
      // Try to get current path
      $current = realpath(dirname(__FILE__));

	  if (false === $current) {
        throw new \Exception(__CLASS__ . ": Cannot determine current path.", self::EXCEPTION_NO_PATH);
      }
      // Try each database in turn
      foreach (self::$databases as $database) {
        $rfile = realpath("{$current}/{$database}.BIN");
        if (false !== $rfile) {
          return $rfile;
        }
      }
      // No candidates found
      throw new \Exception(__CLASS__ . ": No candidate database files found.", self::EXCEPTION_NO_CANDIDATES);
    }
  }
212748
public function get($type, $file = null)
    {
        if (!isset($this->paths[$type])) {
            $method = 'get'.Utils::camelize($type).'Dir';

            if (!method_exists($this, $method)) {
                return null;
            }

            $this->set($type, $this->$method());
        }

        $path = $this->paths[$type];
        if ($file) {
            if ($path instanceof pathmanager\FallbackInterface) {
                $path = $path->resolve($file);
            } else {
                $path .= '/' . ltrim($file, '/');
            }
        }

        return $path;
    }
1273228
protected function readFile(string $file) : string
    {
        if (is_file($file) === false) {
            throw new BadFileException("The file \"{$file}\" is not a file.", $file);
        }

        if (is_readable($file) === false) {
            throw new BadFileException("Unable to open \"{$file}\" as the file is not readable.", $file);
        }

        return file_get_contents($file);
    }
165094
public function real_to_url(string $file){

    foreach ( $this->repositories() as $i => $d ){
      if (
        // Repository's root path
        ($root = $this->get_root_path($d)) &&
        (strpos($file, $root) === 0)
      ){
				$res = $i;
        $bits = explode('/', substr($file, \strlen($root)));

        // MVC
        if ( !empty($d['tabs']) ){
          $tab_path = array_shift($bits);
          $fn = array_pop($bits);
          $ext = \bbn\str::file_ext($fn);
          $fn = \bbn\str::file_ext($fn, 1)[0];
          $res .= implode('/', $bits);
          foreach ( $d['tabs'] as $k => $t ){
            if (
              empty($t['fixed']) &&
              ($t['path'] === $tab_path . '/')
            ){
              $res .= "/$fn/$t[url]";
              break;
            }
          }
        }
        // Normal file
        else {
          $res .= implode('/', $bits);

        }
        return \bbn\str::parse_path($res);
      }
    }
    return false;
  }
368359
public static function readFile(string $file): string
    {
        $contents = @\file_get_contents($file);
        
        if ($contents === false) {
            throw new \RuntimeException(\sprintf('File not found: "%s"', $file));
        }
        
        return $contents;
    }
1010430
protected function getFilePath(string $file, ?string $extension = null, ?string $suffix = null): string
	{
		if(strpos($file, '::') === false)
		{
			// No namespace so we'll just use the default path

			$path = $this->path;
		}
		else
		{
			// The file is namespaced so we'll use the namespace path

			[$namespace, $file] = explode('::', $file, 2);

			if(!isset($this->namespaces[$namespace]))
			{
				throw new RuntimeException(vsprintf('The [ %s ] namespace does not exist.', [$namespace]));
			}

			$path = $this->namespaces[$namespace];
		}

		// Append suffix to path if needed

		if($suffix !== null)
		{
			$path .= DIRECTORY_SEPARATOR . $suffix;
		}

		// Return full path to file

		return $path . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $file) . ($extension ?? $this->extension);
	}
914603
public function locate($file, $first = true)
    {
        $paths = array();

        foreach ($this->locators as $locator) {
            if (null !== ($found = $locator->locate($file, $first))) {
                if ($first) {
                    return $found;
                }

                $paths = array_merge($paths, $found);
            }
        }

        return $first ? null : array_values(array_unique($paths));
    }
52141
public function findRealPath($file_path)
    {
        if (@file_exists($file_path)) {
            return realpath($file_path);
        }
        if (@file_exists($this->web_root_path.$file_path)) {
            return $this->web_root_path.$file_path;
        }
        return null;
    }
139169
private function getRelativeFilePath($file)
    {
        $realPath = $file->getRealPath();
        $pathPrefix = $this->baseDir.'/';
        $pos = strpos($realPath, $pathPrefix);
        $relativePath = (false !== $pos) ? substr_replace($realPath, '', $pos, strlen($pathPrefix)) : $realPath;

        return strtr($relativePath, '\\', '/');
    }
930192
public static function getRealPath(string $path) : string
    {
        $exception = null;

        try {
            $result = ErrorCatcher::run(static function() use ($path) {
                return realpath($path);
            });

            if ($result !== false) {
                return $result;
            }
        } catch (\ErrorException $e) {
            $exception = $e;
        }

        throw new IoException('Error getting real path of ' . $path . ', check that the path exists', 0, $exception);
    }
1364022
static function find($file, $prefix_cdn_config = "cdn")
	{
		if (!$real_path = \Fw\Find::in("assets", $file)) throw new \Exception("$file not found");
		$so = strlen(\Fw\Config::get("docroot")) - 1;
		return \Fw\Config::get($prefix_cdn_config) . substr($real_path, $so);
	}
962083
public function getFilesystemPath(FileAbstraction $file, $includeFilename = true, $forcePath = null)
	{
		if ( ! $file instanceof FileAbstraction) {
			throw new Exception\RuntimeException('File or folder entity expected');
		}

		$path = $this->getInternalPath();

		if ($forcePath != self::FILE_INFO_INTERNAL) {
			if ($file->isPublic() || $forcePath == self::FILE_INFO_EXTERNAL) {
				$path = $this->getExternalPath();
			}
		}

		$path .= $file->getPath(DIRECTORY_SEPARATOR, $includeFilename);
		
		if ( ! $includeFilename) {
			$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
		}
	
		return $path;
	}
932749
private function getRealFilename(string $file): string
    {
        if (strpos($file, 'vfs://') !== false) {
            return $file;
        }

        return $this->loader->getSourceContext($file)->getPath();
    }
280732
public static function base_path(?string $file = null)
  {
    $file = (substr($file, 0, 1) == DIRECTORY_SEPARATOR ? substr($file, 1) : $file);
    return config('app.dir') . $file;
  }
1129815
protected function getFileUploadPath($file)
    {
        // check if path override is defined for current file
        $pathOverrideMethod = camel_case(strtolower($this->uploadFieldName) . 'UploadFilePath');

        if (method_exists($this, $pathOverrideMethod)) {
            return $this->getImageUploadPath() . '/' . $this->$pathOverrideMethod($file);
        }

        return $this->getImageUploadPath() . '/' . $file->hashName();
    }
438959
public function fetch($file)
    {
        $templateFile = $this->findTemplateFile($file);

        if (empty($templateFile)) {
            throw new Exception("Template file does not exists: $file");            
        }

        extract($this->vars);
        ob_start();
        include $templateFile;
        $buffer = ob_get_contents();
        ob_end_clean();
        return $buffer;
    }
1287821
public function find($file)
    {
        $found = false;
        $expanded = $this->_expandPrefix($file);
        if (file_exists($expanded)) {
            return $expanded;
        }
        foreach ($this->_paths as $path) {
            $file = $this->_normalizePath($file, DIRECTORY_SEPARATOR);
            $fullPath = $path . $file;

            if (file_exists($fullPath)) {
                $found = $fullPath;
                break;
            }
        }
        return $found;
    }