function Commandfiles::add

8.0.x Commandfiles.php Commandfiles::add($commandfile)
7.x Commandfiles.php Commandfiles::add($commandfile)
master Commandfiles.php Commandfiles::add($commandfile)

Overrides CommandfilesInterface::add

File

lib/Drush/Command/Commandfiles.php, line 37
Definition of Drush\Command\Commandfiles.

Namespace

Drush\Command

Class

Commandfiles
Default commandfiles implementation.

Code

function add($commandfile) {
  $load_command = FALSE;

  $module = basename($commandfile);
  $module = preg_replace('/\.*drush[0-9]*\.inc/', '', $module);
  $module_versionless = preg_replace('/\.d([0-9]+)$/', '', $module);
  if (!isset($this->cache[$module_versionless])) {
    $drupal_version = '';
    if (preg_match('/\.d([0-9]+)$/', $module, $matches)) {
      $drupal_version = $matches[1];
    }
    if (empty($drupal_version)) {
      $load_command = TRUE;
    }
    else {
      if (function_exists('drush_drupal_major_version') && ($drupal_version == drush_drupal_major_version())) {
        $load_command = TRUE;
      }
      else {
        // Signal that we should try again on
        // the next bootstrap phase.
        $this->deferred[$module] = $commandfile;
      }
    }
    if ($load_command) {
      $this->cache[$module_versionless] = $commandfile;
      require_once $commandfile;
      unset($this->deferred[$module]);
    }
  }
  return $load_command;
}