You are here

public function ArchiverManager::getInstance in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Archiver/ArchiverManager.php \Drupal\Core\Archiver\ArchiverManager::getInstance()

Gets a preconfigured instance of a plugin.

Parameters

array $options: An array of options that can be used to determine a suitable plugin to instantiate and how to configure it.

Return value

object|false A fully configured plugin instance. The interface of the plugin instance will depend on the plugin type. If no instance can be retrieved, FALSE will be returned.

Overrides PluginManagerBase::getInstance

File

core/lib/Drupal/Core/Archiver/ArchiverManager.php, line 63

Class

ArchiverManager
Provides an Archiver plugin manager.

Namespace

Drupal\Core\Archiver

Code

public function getInstance(array $options) {
  $filepath = $options['filepath'];
  foreach ($this
    ->getDefinitions() as $plugin_id => $definition) {
    foreach ($definition['extensions'] as $extension) {

      // Because extensions may be multi-part, such as .tar.gz,
      // we cannot use simpler approaches like substr() or pathinfo().
      // This method isn't quite as clean but gets the job done.
      // Also note that the file may not yet exist, so we cannot rely
      // on fileinfo() or other disk-level utilities.
      if (strrpos($filepath, '.' . $extension) === strlen($filepath) - strlen('.' . $extension)) {
        return $this
          ->createInstance($plugin_id, $options);
      }
    }
  }
}