Composer::ensureHtaccess

public static Composer::ensureHtaccess(Event $event)

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

Parameters

\Composer\Script\Event $event:

File

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

Class

Composer
Provides static functions for composer script events.

Namespace

Drupal\Core\Composer

Code

public static function ensureHtaccess(Event $event) {

  // 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.
  $htaccess_file = $vendor_dir . '/.htaccess';
  if (!file_exists($htaccess_file)) {
    file_put_contents($htaccess_file, FileStorage::htaccessLines(TRUE) . "\n");
  }

  // Prevent access to vendor directory on IIS servers.
  $webconfig_file = $vendor_dir . '/web.config';
  if (!file_exists($webconfig_file)) {
    $lines = <<<EOT
<configuration>
  <system.webServer>
    <authorization>
      <deny users="*">
    </authorization>
  </system.webServer>
</configuration>
EOT;
    file_put_contents($webconfig_file, $lines . "\n");
  }
}
doc_Drupal
2016-10-29 08:51:40
Comments
Leave a Comment

Please login to continue.