file ProviderManager.php

Namespace

Drupal\bootstrap\Plugin
  1. <?php
  2. namespace Drupal\bootstrap\Plugin;
  3. use Drupal\bootstrap\Bootstrap;
  4. use Drupal\bootstrap\Theme;
  5. use Drupal\Component\Plugin\FallbackPluginManagerInterface;
  6. /**
  7. * Manages discovery and instantiation of Bootstrap CDN Providers.
  8. *
  9. * @ingroup plugins_provider
  10. */
  11. class ProviderManager extends PluginManager implements FallbackPluginManagerInterface {
  12. /**
  13. * The base file system path for CDN Providers.
  14. *
  15. * @var string
  16. */
  17. const FILE_PATH = 'public://bootstrap/provider';
  18. /**
  19. * The Broken CDN Provider.
  20. *
  21. * @var \Drupal\bootstrap\Plugin\Provider\Broken
  22. */
  23. protected static $broken;
  24. /**
  25. * Constructs a new \Drupal\bootstrap\Plugin\ProviderManager object.
  26. *
  27. * @param \Drupal\bootstrap\Theme $theme
  28. * The theme to use for discovery.
  29. */
  30. public function __construct(Theme $theme) {
  31. parent::__construct($theme, 'Plugin/Provider', 'Drupal\bootstrap\Plugin\Provider\ProviderInterface', 'Drupal\bootstrap\Annotation\BootstrapProvider');
  32. $this->setCacheBackend(\Drupal::cache('discovery'), 'theme:' . $theme->getName() . ':provider', $this->getCacheTags());
  33. }
  34. /**
  35. * Retrieves a CDN Provider.
  36. *
  37. * @param string $provider
  38. * Optional. The ID of the provider to load. If not set or an invalid
  39. * provider was specified, the base provider will be returned.
  40. * @param array $configuration
  41. * Optional. An array of configuration relevant to the plugin instance.
  42. *
  43. * @return \Drupal\bootstrap\Plugin\Provider\ProviderInterface
  44. * A CDN Provider instance.
  45. */
  46. public function get($provider, array $configuration = []) {
  47. return $this->createInstance($provider, $configuration + ['theme' => $this->theme]);
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function getFallbackPluginId($plugin_id, array $configuration = []) {
  53. return '_broken';
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function processDefinition(&$definition, $plugin_id) {
  59. parent::processDefinition($definition, $plugin_id);
  60. /** @var \Drupal\bootstrap\Plugin\Provider\ProviderInterface $provider */
  61. $provider = new $definition['class'](['theme' => $this->theme], $plugin_id, $definition);
  62. $provider->processDefinition($definition, $plugin_id);
  63. }
  64. /**
  65. * Returns the Broken CDN Provider instance.
  66. *
  67. * @return \Drupal\bootstrap\Plugin\Provider\Broken
  68. * The Broken CDN Provider.
  69. */
  70. public static function broken() {
  71. if (!isset(static::$broken)) {
  72. static::$broken = (new static(Bootstrap::getTheme()))->get('_broken');
  73. }
  74. return static::$broken;
  75. }
  76. /**
  77. * Loads a CDN Provider.
  78. *
  79. * @param \Drupal\bootstrap\Theme|string $theme
  80. * Optional. A theme to associate with the provider. If not set, the
  81. * active theme will be used.
  82. * @param string $provider
  83. * Optional. The ID of the provider to load. If not set, the provider set
  84. * on the supplied or active $theme will be used.
  85. * @param array $configuration
  86. * Optional. An array of configuration relevant to the plugin instance.
  87. *
  88. * @return \Drupal\bootstrap\Plugin\Provider\ProviderInterface
  89. * A CDN Provider instance.
  90. */
  91. public static function load($theme = NULL, $provider = NULL, array $configuration = []) {
  92. $theme = Bootstrap::getTheme($theme);
  93. return (new static($theme))->get(isset($provider) ? $provider : $theme->getSetting('cdn_provider'), $configuration + ['theme' => $theme]);
  94. }
  95. }

Classes

Name Description
ProviderManager Manages discovery and instantiation of Bootstrap CDN Providers.