function ArchiverManager::getInstance

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Archiver/ArchiverManager.php \Drupal\Core\Archiver\ArchiverManager::getInstance()
  2. 10 core/lib/Drupal/Core/Archiver/ArchiverManager.php \Drupal\Core\Archiver\ArchiverManager::getInstance()
  3. 11.x core/lib/Drupal/Core/Archiver/ArchiverManager.php \Drupal\Core\Archiver\ArchiverManager::getInstance()

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);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.