class BootstrapManager

Namespace

Drush\Boot

Hierarchy

Expanded class hierarchy of BootstrapManager

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
BootstrapManager::$bootstrap protected property
BootstrapManager::$bootstrapCandidates protected property
BootstrapManager::$defaultBootstrapObject protected property
BootstrapManager::$root protected property
BootstrapManager::$uri protected property
BootstrapManager::add public function Add a bootstrap object to the list of candidates
BootstrapManager::bootstrap public function Return the bootstrap object in use. This will be the latched bootstrap object if we have started bootstrapping; otherwise, it will be whichever bootstrap object is best for the selected root.
BootstrapManager::bootstrapObjectForRoot public function Look up the best bootstrap class for the given location from the set of available candidates.
BootstrapManager::getRoot public function Return the framework root selected by the user.
BootstrapManager::getUri public function Return the framework root selected by the user.
BootstrapManager::latch public function Once bootstrapping has started, we stash the bootstrap object being used, and do not allow it to change any longer.
BootstrapManager::selectBootstrapClass protected function Select the bootstrap class to use. If this is called multiple times, the bootstrap class returned might change on subsequent calls, if the root directory changes. Once the bootstrap object starts changing the state of the system, however, it will be…
BootstrapManager::setRoot public function
BootstrapManager::setUri public function
BootstrapManager::__construct public function Constructor.

File

lib/Drush/Boot/BootstrapManager.php, line 9

View source
class BootstrapManager implements LoggerAwareInterface {
  use LoggerAwareTrait;

  /**
   * @var \Drush\Boot\Boot[]
   */
  protected $bootstrapCandidates =[];

  /**
   * @var \Drush\Boot\Boot
   */
  protected $defaultBootstrapObject;

  /**
   * @var \Drush\Boot\Boot
   */
  protected $bootstrap;

  /**
   * @var string
   */
  protected $root;

  /**
   * @var string
   */
  protected $uri;

  /**
   * Constructor.
   *
   * @param \Drush\Boot\Boot
   *   The default bootstrap object to use when there are
   *   no viable candidates to use (e.g. no selected site)
   */
  public function __construct(Boot $default) {
    $this->defaultBootstrapObject = $default;
  }

  /**
   * Add a bootstrap object to the list of candidates
   *
   * @param \Drush\Boot\Boot|Array
   *   List of boot candidates
   */
  public function add($candidateList) {
    foreach (func_get_args() as $candidate) {
      $this->bootstrapCandidates[] = $candidate;
    }
  }

  /**
   * Return the framework root selected by the user.
   */
  public function getRoot() {
    return $this->root;
  }

  public function setRoot($root) {
    // TODO: Throw if we already bootstrapped a framework?
    $this->root = $root;
  }

  /**
   * Return the framework root selected by the user.
   */
  public function getUri() {
    return $this->uri;
  }

  public function setUri($uri) {
    // TODO: Throw if we already bootstrapped a framework?
    $this->uri = $root;
  }

  /**
   * Return the bootstrap object in use.  This will
   * be the latched bootstrap object if we have started
   * bootstrapping; otherwise, it will be whichever bootstrap
   * object is best for the selected root.
   *
   * @return \Drush\Boot\Boot
   */
  public function bootstrap() {
    if ($this->bootstrap) {
      return $this->bootstrap;
    }
    return $this->selectBootstrapClass();
  }

  /**
   * Look up the best bootstrap class for the given location
   * from the set of available candidates.
   *
   * @return \Drush\Boot\Boot
   */
  public function bootstrapObjectForRoot($path) {
    foreach ($this->bootstrapCandidates as $candidate) {
      if ($candidate->valid_root($path)) {
        return $candidate;
      }
    }
    return NULL;
  }

  /**
   * Select the bootstrap class to use.  If this is called multiple
   * times, the bootstrap class returned might change on subsequent
   * calls, if the root directory changes.  Once the bootstrap object
   * starts changing the state of the system, however, it will
   * be 'latched', and further calls to \Drush::bootstrapf()
   * will always return the same object.
   */
  protected function selectBootstrapClass() {
    // Once we have selected a Drupal root, we will reduce our bootstrap
    // candidates down to just the one used to select this site root.
    $bootstrap = $this->bootstrapObjectForRoot($this->root);
    // If we have not found a bootstrap class by this point,
    // then return our default bootstrap object.  The default bootstrap object
    // should pass through all calls without doing anything that
    // changes state in a CMS-specific way.
    if ($bootstrap == NULL) {
      $bootstrap = $this->defaultBootstrapObject;
    }

    return $bootstrap;
  }

  /**
   * Once bootstrapping has started, we stash the bootstrap
   * object being used, and do not allow it to change any
   * longer.
   */
  public function latch($bootstrap) {
    $this->bootstrap = $bootstrap;
  }

}