function drush_autoload

8.0.x bootstrap.inc drush_autoload($commandfile)
6.x bootstrap.inc drush_autoload($commandfile)
7.x bootstrap.inc drush_autoload($commandfile)
master bootstrap.inc drush_autoload($commandfile)

Used by a Drush extension to request that its Composer autoload files be loaded by Drush, if they have not already been.

Usage:

function mycommandfile_drush_init() { drush_autoload(__FILE__) }

File

includes/bootstrap.inc, line 578

Code

function drush_autoload($commandfile) {
  $already_added = commandfiles_cache()->add($commandfile);

  $dir = dirname($commandfile);
  $candidates = array("vendor/autoload.php", "../../../vendor/autoload.php");
  $drush_autoload_file = drush_get_context('DRUSH_VENDOR_PATH', '');

  foreach ($candidates as $candidate) {
    $autoload = $dir . '/' . $candidate;
    if (file_exists($autoload) && (realpath($autoload) != $drush_autoload_file)) {
      include $autoload;
    }
  }
}