public static function 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\ComposerCode
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"); } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Composer!Composer.php/function/Composer::ensureHtaccess/8.1.x