function drush_get_class

8.0.x drush.inc drush_get_class($class_name, $constructor_args = array(), $variations = array())
6.x drush.inc drush_get_class($class_name, $constructor_args, $class_dir = NULL)
7.x drush.inc drush_get_class($class_name, $constructor_args = array(), $variations = array())
master drush.inc drush_get_class($class_name, $constructor_args = array(), $variations = array())
7 calls to drush_get_class()
drush_include_engine in includes/engines.inc
Include the engine code for a specific named engine of a certain type.
drush_queue_get_class in commands/core/queue.drush.inc
Return the appropriate queue class.
drush_role_get_class in commands/core/role.drush.inc
Get core version specific Role handler class.
drush_sql_get_class in commands/sql/sql.drush.inc
Wrapper for drush_get_class; instantiates an driver-specific instance of SqlBase class.
drush_sql_get_version in commands/sql/sql.drush.inc
Wrapper for drush_get_class; instantiates a Drupal version-specific instance of SqlVersion class.

... See full list

File

includes/drush.inc, line 107
The drush API implementation and helpers.

Code

function drush_get_class($class_name, $constructor_args = array(), $variations = array()) {
  if (empty($variations)) {
    $variations[] = drush_drupal_major_version();
  }
  $class_names = is_array($class_name) ? $class_name : array($class_name);
  foreach ($class_names as $class_name) {
    for ($i = count($variations); $i >= 0; $i--) {
      $variant_class_name = $class_name . implode('', array_slice($variations, 0, $i));
      if (class_exists($variant_class_name)) {
        $reflectionClass = new ReflectionClass($variant_class_name);
        return $reflectionClass->newInstanceArgs($constructor_args);
      }
    }
  }
  // Something bad happenned. TODO Exception?
  return drush_set_error('DRUSH_GET_CLASS_ERROR', dt('Unable to load class !class', array('!class' => $class_name)));
}