Back to ChangeItem class

Method getInstance

public static \Joomla\CMS\Schema\ChangeItem
getInstance
(mixed $db, mixed $file, mixed $query)
Returns a reference to the ChangeItem object.
Parameters
  • \Joomla\Database\DatabaseDriver $db Database connector object
  • string $file Full path name of the sql file
  • string $query Text of the sql query (one line of the file)
Returns
  • \Joomla\CMS\Schema\ChangeItem instance based on the database driver
Since
  • 2.5
-
  • \RuntimeException if class for database driver not found
Class: ChangeItem
Project: Joomla

Method getInstance - Source code

/**
 * Returns a reference to the ChangeItem object.
 *
 * @param   DatabaseDriver  $db     Database connector object
 * @param   string          $file   Full path name of the sql file
 * @param   string          $query  Text of the sql query (one line of the file)
 *
 * @return  ChangeItem  instance based on the database driver
 *
 * @since   2.5
 * @throws  \RuntimeException if class for database driver not found
 */
public static function getInstance($db, $file, $query)
{
    // Get the class name
    $serverType = $db->getServerType();
    // For `mssql` server types, convert the type to `sqlsrv`
    if ($serverType === 'mssql') {
        $serverType = 'sqlsrv';
    }
    $class = '\\Joomla\\CMS\\Schema\\ChangeItem\\' . ucfirst($serverType) . 'ChangeItem';
    // If the class exists, return it.
    if (class_exists($class)) {
        return new $class($db, $file, $query);
    }
    throw new \RuntimeException(sprintf('ChangeItem child class not found for the %s database driver', $serverType), 500);
}