ArchiverManager.php

Namespace

Drupal\Core\Archiver

File

drupal/core/lib/Drupal/Core/Archiver/ArchiverManager.php
View source
  1. <?php
  2. /**
  3. * Contains \Drupal\Core\Archiver\ArchiverManager.
  4. */
  5. namespace Drupal\Core\Archiver;
  6. use Drupal\Component\Plugin\Factory\DefaultFactory;
  7. use Drupal\Component\Plugin\PluginManagerBase;
  8. use Drupal\Core\Plugin\Discovery\AlterDecorator;
  9. use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
  10. use Drupal\Core\Plugin\Discovery\CacheDecorator;
  11. /**
  12. * Archiver plugin manager.
  13. */
  14. class ArchiverManager extends PluginManagerBase {
  15. /**
  16. * Constructs a ArchiverManager object.
  17. *
  18. * @param \Traversable $namespaces
  19. * An object that implements \Traversable which contains the root paths
  20. * keyed by the corresponding namespace to look for plugin implementations,
  21. */
  22. public function __construct(\Traversable $namespaces) {
  23. $this->discovery = new AnnotatedClassDiscovery('Archiver', $namespaces);
  24. $this->discovery = new AlterDecorator($this->discovery, 'archiver_info');
  25. $this->discovery = new CacheDecorator($this->discovery, 'archiver_info');
  26. }
  27. /**
  28. * Overrides \Drupal\Component\Plugin\PluginManagerBase::createInstance().
  29. */
  30. public function createInstance($plugin_id, array $configuration = array()) {
  31. $plugin_definition = $this->discovery->getDefinition($plugin_id);
  32. $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
  33. return new $plugin_class($configuration['filepath']);
  34. }
  35. /**
  36. * Implements \Drupal\Core\PluginManagerInterface::getInstance().
  37. */
  38. public function getInstance(array $options) {
  39. $filepath = $options['filepath'];
  40. foreach ($this->getDefinitions() as $plugin_id => $definition) {
  41. foreach ($definition['extensions'] as $extension) {
  42. // Because extensions may be multi-part, such as .tar.gz,
  43. // we cannot use simpler approaches like substr() or pathinfo().
  44. // This method isn't quite as clean but gets the job done.
  45. // Also note that the file may not yet exist, so we cannot rely
  46. // on fileinfo() or other disk-level utilities.
  47. if (strrpos($filepath, '.' . $extension) === strlen($filepath) - strlen('.' . $extension)) {
  48. return $this->createInstance($plugin_id, $options);
  49. }
  50. }
  51. }
  52. }
  53. }

Classes

Namesort descending Description
ArchiverManager Archiver plugin manager.