ArchiverManager::getInstance

public ArchiverManager::getInstance(array $options)

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 depends 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 48

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);
      }
    }
  }
}
doc_Drupal
2016-10-29 08:44:43
Comments
Leave a Comment

Please login to continue.