/**
  * @param Settings $settings
  * @return DatabaseDriver
  * @throws NoDriverFoundException
  */
 public static function get(Settings $settings)
 {
     switch ($settings->getType()) {
         case self::MYSQL:
             return new MySQLDriver($settings);
             break;
     }
     throw new NoDriverFoundException($settings->getType());
 }
Exemple #2
0
 /**
  * @param string $path Relative path of the settings file.
  * @return Settings
  * @throws \Exception
  */
 public static function parse($path)
 {
     $absolutePath = $path;
     $workingFolder = getcwd();
     if (file_exists($absolutePath) == false) {
         $absolutePath = realpath(sprintf('%s/%s', $workingFolder, $path));
     }
     if (file_exists($absolutePath) === false) {
         throw new FileNotFoundException($absolutePath);
     }
     $array = parse_ini_file($absolutePath);
     foreach (SettingsFile::$KEYS as $key) {
         if (array_key_exists($key, $array) === false) {
             throw new SettingsKeyNotFoundException($key);
         }
     }
     $settings = new Settings();
     $settings->setDbName($array[SettingsFile::DB_NAME])->setHost($array[SettingsFile::HOST])->setPassword($array[SettingsFile::PASSWORD])->setUsername($array[SettingsFile::USERNAME])->setType($array[SettingsFile::TYPE]);
     return $settings;
 }