You are here

private static function Database::findFile in Smart IP 7.2

Same name and namespace in other branches
  1. 6.2 includes/vendor/ip2location/ip2location-php/IP2Location.php \IP2Location\Database::findFile()

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

Parameters

string $file File to try to find, or null to try the databases in turn on the current file's path:

Return value

string

Throws

\Exception

1 call to Database::findFile()
Database::__construct in includes/vendor/ip2location/ip2location-php/IP2Location.php
Constructor

File

includes/vendor/ip2location/ip2location-php/IP2Location.php, line 863

Class

Database
IP2Location database class

Namespace

IP2Location

Code

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);
  }
}