function Composer::ensureHtaccess

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Composer/Composer.php \Drupal\Core\Composer\Composer::ensureHtaccess()

Ensures that .htaccess and web.config files are present in Composer root.

Parameters

\Composer\Script\Event $event: The event.

Deprecated

in drupal:9.5.0 and is removed from drupal:10.0.0. Any "scripts" section mentioning this in composer.json can be removed and replaced with the drupal/core-vendor-hardening Composer plugin, as needed.

See also

https://www.drupal.org/node/3260624

1 call to Composer::ensureHtaccess()
ComposerDeprecationTest::testEnsureHtaccess in core/tests/Drupal/Tests/Core/Composer/ComposerDeprecationTest.php
@covers ::ensureHtaccess @group legacy

File

core/lib/Drupal/Core/Composer/Composer.php, line 165

Class

Composer
Provides static functions for composer script events.

Namespace

Drupal\Core\Composer

Code

public static function ensureHtaccess(Event $event) {
    trigger_error('Calling ' . __METHOD__ . ' from composer.json is deprecated in drupal:9.5.0 and is removed from drupal:10.0.0. Any "scripts" section mentioning this in composer.json can be removed and replaced with the drupal/core-vendor-hardening Composer plugin, as needed. See https://www.drupal.org/node/3260624', E_USER_DEPRECATED);
    // The current working directory for composer scripts is where you run
    // composer from.
    $vendor_dir = $event->getComposer()
        ->getConfig()
        ->get('vendor-dir');
    // Prevent access to vendor directory on Apache servers.
    FileSecurity::writeHtaccess($vendor_dir);
    // Prevent access to vendor directory on IIS servers.
    FileSecurity::writeWebConfig($vendor_dir);
}

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