You are here

protected function FeaturesGenerationArchive::generateFile in Features 8.3

Same name and namespace in other branches
  1. 8.4 src/Plugin/FeaturesGeneration/FeaturesGenerationArchive.php \Drupal\features\Plugin\FeaturesGeneration\FeaturesGenerationArchive::generateFile()

Writes a file to the file system, creating its directory as needed.

Parameters

string $directory: The extension's directory.

array $file: Array with the following keys:

  • 'filename': the name of the file.
  • 'subdirectory': any subdirectory of the file within the extension directory.
  • 'string': the contents of the file.

\Drupal\Core\Archiver\ArchiveTar $archiver: The archiver.

Throws

Exception

1 call to FeaturesGenerationArchive::generateFile()
FeaturesGenerationArchive::generatePackage in src/Plugin/FeaturesGeneration/FeaturesGenerationArchive.php
Writes a package or profile's files to an archive.

File

src/Plugin/FeaturesGeneration/FeaturesGenerationArchive.php, line 285

Class

FeaturesGenerationArchive
Class for generating a compressed archive of packages.

Namespace

Drupal\features\Plugin\FeaturesGeneration

Code

protected function generateFile($directory, array $file, ArchiveTar $archiver) {
  $filename = $directory;
  if (!empty($file['subdirectory'])) {
    $filename .= '/' . $file['subdirectory'];
  }
  $filename .= '/' . $file['filename'];

  // Set the mode to 0644 rather than the default of 0600.
  if ($archiver
    ->addString($filename, $file['string'], FALSE, [
    'mode' => 0644,
  ]) === FALSE) {
    throw new \Exception($this
      ->t('Failed to archive file @filename.', [
      '@filename' => $file['filename'],
    ]));
  }
}