You are here

function archiver_get_archiver in Drupal 8

Same name and namespace in other branches
  1. 7 includes/common.inc \archiver_get_archiver()

Creates the appropriate archiver for the specified file.

Parameters

string $file: The full path of the archive file. Note that stream wrapper paths are supported, but not remote ones.

Return value

\Drupal\Core\Archiver\ArchiverInterface|false A newly created instance of the archiver class appropriate for the specified file, already bound to that file. If no appropriate archiver class was found, will return FALSE.

Throws

\Exception If a remote stream wrapper path was passed.

Deprecated

in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, get plugin.manager.archiver service from container and call getInstance() method on it. For example $archiver->getInstance(['filepath' => $file]);

See also

https://www.drupal.org/node/2999951

1 call to archiver_get_archiver()
LegacyFunctionsTest::testArchiverGetArchiver in core/tests/Drupal/KernelTests/Core/Common/LegacyFunctionsTest.php
@expectedDeprecation archiver_get_archiver() is deprecated in Drupal 8.8.0 and will be removed in Drupal 9.0.x. Instead, get plugin.manager.archiver service from container and call getInstance() method on it. For example…

File

core/includes/common.inc, line 1203
Common functions that many Drupal modules will need to reference.

Code

function archiver_get_archiver($file) {
  @trigger_error('archiver_get_archiver() is deprecated in Drupal 8.8.0 and will be removed in Drupal 9.0.x. Instead, get plugin.manager.archiver service from container and call getInstance() method on it. For example $archiver->getInstance(["filepath" => $file]); See https://www.drupal.org/node/2999951', E_USER_DEPRECATED);

  // Archivers can only work on local paths
  $filepath = \Drupal::service('file_system')
    ->realpath($file);
  if (!is_file($filepath)) {
    throw new Exception("Archivers can only operate on local files: '{$file}' not supported");
  }
  return \Drupal::service('plugin.manager.archiver')
    ->getInstance([
    'filepath' => $filepath,
  ]);
}