You are here

class ChainLocator in Libraries API 8.3

Provides a locator utilizing a chain of other individual locators.

Plugin annotation

@Locator("chain");

Hierarchy

Expanded class hierarchy of ChainLocator

See also

\Drupal\libraries\ExternalLibrary\Local\LocatorInterface

File

src/Plugin/libraries/Locator/ChainLocator.php, line 15

Namespace

Drupal\libraries\Plugin\libraries\Locator
View source
class ChainLocator implements LocatorInterface {

  /**
   * The locators to check.
   *
   * @var \Drupal\libraries\ExternalLibrary\Local\LocatorInterface[]
   */
  protected $locators = [];

  /**
   * Add a locator to the chain.
   *
   * @param \Drupal\libraries\ExternalLibrary\Local\LocatorInterface $locator
   *   A locator to add to the chain.
   */
  public function addLocator(LocatorInterface $locator) {
    $this->locators[] = $locator;
    return $this;
  }

  /**
   * Locates a library.
   *
   * @param \Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface $library
   *   The library to locate.
   *
   * @see \Drupal\libraries\ExternalLibrary\Local\LocatorInterface::locate()
   */
  public function locate(LocalLibraryInterface $library) {
    foreach ($this->locators as $locator) {
      $locator
        ->locate($library);
      if ($library
        ->isInstalled()) {
        return;
      }
    }
    $library
      ->setUninstalled();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ChainLocator::$locators protected property The locators to check.
ChainLocator::addLocator public function Add a locator to the chain.
ChainLocator::locate public function Locates a library. Overrides LocatorInterface::locate