function Zip::__construct

Same name in other branches
  1. 9 core/lib/Drupal/Core/Archiver/Zip.php \Drupal\Core\Archiver\Zip::__construct()
  2. 8.9.x core/lib/Drupal/Core/Archiver/Zip.php \Drupal\Core\Archiver\Zip::__construct()
  3. 11.x core/lib/Drupal/Core/Archiver/Zip.php \Drupal\Core\Archiver\Zip::__construct()

Constructs a Zip object.

Parameters

string $file_path: The full system path of the archive to manipulate. Only local files are supported. If the file does not yet exist, it will be created if appropriate.

array $configuration: (Optional) settings to open the archive with the following keys:

  • 'flags': The mode to open the archive with \ZipArchive::open().

Throws

\Drupal\Core\Archiver\ArchiverException

File

core/lib/Drupal/Core/Archiver/Zip.php, line 32

Class

Zip
Defines an archiver implementation for .zip files.

Namespace

Drupal\Core\Archiver

Code

public function __construct($file_path, array $configuration = []) {
    $this->zip = new \ZipArchive();
    if ($this->zip
        ->open($file_path, $configuration['flags'] ?? 0) !== TRUE) {
        throw new ArchiverException("Cannot open '{$file_path}'");
    }
}

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