function 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\FileCode
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());
  }
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
