Further modules included.
[yaffs-website] / web / modules / contrib / libraries / src / Plugin / libraries / Locator / ChainLocator.php
1 <?php
2
3 namespace Drupal\libraries\Plugin\libraries\Locator;
4
5 use Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface;
6 use Drupal\libraries\ExternalLibrary\Local\LocatorInterface;
7
8 /**
9  * Provides a locator utilizing a chain of other individual locators.
10  *
11  * @Locator("chain")
12  *
13  * @see \Drupal\libraries\ExternalLibrary\Local\LocatorInterface
14  */
15 class ChainLocator implements LocatorInterface {
16
17   /**
18    * The locators to check.
19    *
20    * @var \Drupal\libraries\ExternalLibrary\Local\LocatorInterface[]
21    */
22   protected $locators = [];
23
24   /**
25    * Add a locator to the chain.
26    *
27    * @param \Drupal\libraries\ExternalLibrary\Local\LocatorInterface $locator
28    *   A locator to add to the chain.
29    */
30   public function addLocator(LocatorInterface $locator) {
31     $this->locators[] = $locator;
32     return $this;
33   }
34
35   /**
36    * Locates a library.
37    *
38    * @param \Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface $library
39    *   The library to locate.
40    *
41    * @see \Drupal\libraries\ExternalLibrary\Local\LocatorInterface::locate()
42    */
43   public function locate(LocalLibraryInterface $library) {
44     foreach ($this->locators as $locator) {
45       $locator->locate($library);
46       if ($library->isInstalled()) {
47         return;
48       }
49     }
50     $library->setUninstalled();
51   }
52
53 }