You are here

public function HtaccessWriter::ensure in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/File/HtaccessWriter.php \Drupal\Core\File\HtaccessWriter::ensure()

Creates a .htaccess file in each Drupal files directory if it is missing.

Overrides HtaccessWriterInterface::ensure

File

core/lib/Drupal/Core/File/HtaccessWriter.php, line 47

Class

HtaccessWriter
Provides functions to manage Apache .htaccess files.

Namespace

Drupal\Core\File

Code

public function ensure() {
  try {
    foreach ($this
      ->defaultProtectedDirs() as $protected_dir) {
      $this
        ->write($protected_dir
        ->getPath(), $protected_dir
        ->isPrivate());
    }
    $staging = Settings::get('config_sync_directory', FALSE);
    if ($staging) {

      // Note that we log an error here if we can't write the .htaccess file.
      // This can occur if the staging directory is read-only. If it is then
      // it is the user's responsibility to create the .htaccess file.
      $this
        ->write($staging, TRUE);
    }
  } catch (\Exception $e) {
    $this->logger
      ->error($e
      ->getMessage());
  }
}