You are here

DbServerHandlerFactory.php in DB Maintenance 8

DbServerHandlerFactory class.

File

src/Module/Db/DbServer/DbServerHandlerFactory.php
View source
<?php

/**
 * @file
 * DbServerHandlerFactory class.
 */
namespace Drupal\db_maintenance\Module\Db\DbServer;

use Drupal\db_maintenance\Module\Db\DbServer\MySql\MySqlHandler;
use Drupal\db_maintenance\Module\Db\DbServer\PgSql\PgSqlHandler;

/**
 * DbServerHandlerFactory class.
 */
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;
  }

}

Classes

Namesort descending Description
DbServerHandlerFactory DbServerHandlerFactory class.