Chris@0: alterInfo('archiver_info'); Chris@0: $this->setCacheBackend($cache_backend, 'archiver_info_plugins'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function createInstance($plugin_id, array $configuration = []) { Chris@0: $plugin_definition = $this->getDefinition($plugin_id); Chris@0: $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition, 'Drupal\Core\Archiver\ArchiverInterface'); Chris@0: return new $plugin_class($configuration['filepath']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getInstance(array $options) { Chris@0: $filepath = $options['filepath']; Chris@0: foreach ($this->getDefinitions() as $plugin_id => $definition) { Chris@0: foreach ($definition['extensions'] as $extension) { Chris@0: // Because extensions may be multi-part, such as .tar.gz, Chris@0: // we cannot use simpler approaches like substr() or pathinfo(). Chris@0: // This method isn't quite as clean but gets the job done. Chris@0: // Also note that the file may not yet exist, so we cannot rely Chris@0: // on fileinfo() or other disk-level utilities. Chris@0: if (strrpos($filepath, '.' . $extension) === strlen($filepath) - strlen('.' . $extension)) { Chris@0: return $this->createInstance($plugin_id, $options); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: }