function drush_get_class

8.0.x drush_get_class($class_name, $constructor_args = array(), $variations = array())
6.x drush_get_class($class_name, $constructor_args, $class_dir = NULL)
7.x drush_get_class($class_name, $constructor_args = array(), $variations = array())
master drush_get_class($class_name, $constructor_args = array(), $variations = array())

Provide a version-specific class instance.


$class_name: The name of the class to instantiate. Appends the Drupal major version number to the end of the class name before instantiation.

$constructor_args: An array of arguments to pass to the class constructor.

$class_dir: The directory where the commandfile stores its classes. For Drush Core, using the default value will search the 'classes' directory in the Drupal root. If the class file(s) are stored in the same directory as your commandfile, pass dirname(__FILE__) here.

Example wrapper class to instantiate a widget, called with the arguments for the WIDGET_CLASS constructor:

function drush_WIDGET_CLASS_get_class($widgetName, $widgetStyle) { retrun drush_get_class('Widget_Class', func_get_args())); }

1 call to drush_get_class()
drush_role_get_class in commands/core/
Wrapper for drush_get_class; instantiates an instance of the version-specific DrushRole class suitable for the current version of Drupal.


includes/, line 101
The drush API implementation and helpers.


function drush_get_class($class_name, $constructor_args, $class_dir = NULL) {
  if (!isset($class_dir)) {
    $class_dir = DRUSH_BASE_PATH . '/classes';
  $version = drush_drupal_major_version();
  drush_include($class_dir, $class_name, $version, 'php');
  $version_specific_class_name = $class_name . $version;
  if (class_exists($version_specific_class_name)) {
    $reflectionClass = new ReflectionClass($version_specific_class_name);
    return $reflectionClass->newInstanceArgs($constructor_args);
  else {
    return drush_set_error('DRUSH_GET_CLASS_ERROR', dt('Drupal %d not supported!', array('%d' => $version)));