3 namespace Drupal\libraries\Plugin\libraries\Type;
5 use Drupal\Component\Plugin\Factory\FactoryInterface;
6 use Drupal\libraries\ExternalLibrary\LibraryInterface;
7 use Drupal\libraries\ExternalLibrary\Type\LibraryLoadingListenerInterface;
8 use Drupal\libraries\ExternalLibrary\PhpFile\PhpFileLibrary;
9 use Drupal\libraries\ExternalLibrary\PhpFile\PhpFileLoaderInterface;
10 use Drupal\libraries\ExternalLibrary\Type\LibraryTypeBase;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
14 * @LibraryType("php_file")
16 class PhpFileLibraryType extends LibraryTypeBase implements LibraryLoadingListenerInterface {
19 * The PHP file loader.
21 * @var \Drupal\libraries\ExternalLibrary\PhpFile\PhpFileLoaderInterface
23 protected $phpFileLoader;
26 * Constructs the PHP file library type.
28 * @param string $plugin_id
29 * The plugin ID taken from the class annotation.
30 * @param \Drupal\Component\Plugin\Factory\FactoryInterface $locator_factory
31 * The locator factory.
32 * @param \Drupal\Component\Plugin\Factory\FactoryInterface $detector_factory
33 * The version detector factory.
34 * @param \Drupal\libraries\ExternalLibrary\PhpFile\PhpFileLoaderInterface $php_file_loader
35 * The PHP file loader.
37 public function __construct($plugin_id, FactoryInterface $locator_factory, FactoryInterface $detector_factory, PhpFileLoaderInterface $php_file_loader) {
38 parent::__construct($plugin_id, $locator_factory, $detector_factory);
39 $this->phpFileLoader = $php_file_loader;
45 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
48 $container->get('plugin.manager.libraries.locator'),
49 $container->get('plugin.manager.libraries.version_detector'),
50 $container->get('libraries.php_file_loader')
57 public function getLibraryClass() {
58 return PhpFileLibrary::class;
64 public function onLibraryLoad(LibraryInterface $library) {
65 /** @var \Drupal\libraries\ExternalLibrary\PhpFile\PhpFileLibraryInterface $library */
66 // @todo Prevent loading a library multiple times.
67 foreach ($library->getPhpFiles() as $file) {
68 $this->phpFileLoader->load($file);