You are here

class DbServerHandlerFactory in DB Maintenance 2.0.x

Same name and namespace in other branches
  1. 8 src/Module/Db/DbServer/DbServerHandlerFactory.php \Drupal\db_maintenance\Module\Db\DbServer\DbServerHandlerFactory
  2. 7.2 src/Module/Db/DbServer/DbServerHandlerFactory.php \Drupal\db_maintenance\Module\Db\DbServer\DbServerHandlerFactory

DbServerHandlerFactory class.

Hierarchy

Expanded class hierarchy of DbServerHandlerFactory

1 file declares its use of DbServerHandlerFactory
DbHandler.php in src/Module/Db/DbHandler.php
DbHandler class.

File

src/Module/Db/DbServer/DbServerHandlerFactory.php, line 17
DbServerHandlerFactory class.

Namespace

Drupal\db_maintenance\Module\Db\DbServer
View source
class DbServerHandlerFactory {

  /**
   * Returns proper DbServerHandler.
   */
  public static function getDbServerHandler() {
    if (\Drupal::database()
      ->driver() == 'mysql') {
      $handler = new MySqlHandler();
    }
    elseif (\Drupal::database()
      ->driver() == 'pgsql') {
      $handler = new PgSqlHandler();
    }
    else {
      throw new \Exception(t('Unsupported DB server type.'));
    }
    return self::cast($handler);
  }

  /**
   * Returns typed $handler as DbServerHandlerInterface.
   */
  public static function cast(DbServerHandlerInterface &$object = NULL) {
    return $object;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DbServerHandlerFactory::cast public static function Returns typed $handler as DbServerHandlerInterface.
DbServerHandlerFactory::getDbServerHandler public static function Returns proper DbServerHandler.