function FileSecurity::writeHtaccess

Same name in this branch
  1. 9 composer/Plugin/VendorHardening/FileSecurity.php \Drupal\Composer\Plugin\VendorHardening\FileSecurity::writeHtaccess()
Same name in other branches
  1. 8.9.x composer/Plugin/VendorHardening/FileSecurity.php \Drupal\Composer\Plugin\VendorHardening\FileSecurity::writeHtaccess()
  2. 8.9.x core/lib/Drupal/Component/FileSecurity/FileSecurity.php \Drupal\Component\FileSecurity\FileSecurity::writeHtaccess()
  3. 10 composer/Plugin/VendorHardening/FileSecurity.php \Drupal\Composer\Plugin\VendorHardening\FileSecurity::writeHtaccess()
  4. 10 core/lib/Drupal/Component/FileSecurity/FileSecurity.php \Drupal\Component\FileSecurity\FileSecurity::writeHtaccess()
  5. 11.x composer/Plugin/VendorHardening/FileSecurity.php \Drupal\Composer\Plugin\VendorHardening\FileSecurity::writeHtaccess()
  6. 11.x core/lib/Drupal/Component/FileSecurity/FileSecurity.php \Drupal\Component\FileSecurity\FileSecurity::writeHtaccess()

Writes an .htaccess file in the given directory, if it doesn't exist.

Parameters

string $directory: The directory.

bool $deny_public_access: (optional) Set to FALSE to ensure an .htaccess file for an open and public directory. Default is TRUE.

bool $force: (optional) Set to TRUE to force overwrite an existing file.

Return value

bool TRUE if the file already exists or was created. FALSE otherwise.

9 calls to FileSecurity::writeHtaccess()
Composer::ensureHtaccess in core/lib/Drupal/Core/Composer/Composer.php
Ensures that .htaccess and web.config files are present in Composer root.
FileSecurityTest::testWriteHtaccessFailure in core/tests/Drupal/Tests/Component/FileSecurity/FileSecurityTest.php
@covers ::writeHtaccess
FileSecurityTest::testWriteHtaccessForceOverwrite in core/tests/Drupal/Tests/Component/FileSecurity/FileSecurityTest.php
@covers ::writeHtaccess
FileSecurityTest::testWriteHtaccessPrivate in core/tests/Drupal/Tests/Component/FileSecurity/FileSecurityTest.php
@covers ::writeHtaccess
FileSecurityTest::testWriteHtaccessPublic in core/tests/Drupal/Tests/Component/FileSecurity/FileSecurityTest.php
@covers ::writeHtaccess

... See full list

File

core/lib/Drupal/Component/FileSecurity/FileSecurity.php, line 28

Class

FileSecurity
Provides file security functions.

Namespace

Drupal\Component\FileSecurity

Code

public static function writeHtaccess($directory, $deny_public_access = TRUE, $force = FALSE) {
    return self::writeFile($directory, '.htaccess', self::htaccessLines($deny_public_access), $force);
}

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