This commit is contained in:
me
2026-07-23 14:28:32 +07:00
commit bf3495dea6
2 changed files with 51 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
{
"name": "nightmare/php-composer-plugin",
"description": "php plugin for composer",
"type": "composer-plugin",
"require": {
"php": ">=7.4",
"composer-plugin-api": "^2.0"
},
"autoload": {
"psr-4": {
"Nightmare\\ComposerPlugin\\": "src/"
}
},
"extra": {
"class": "Nightmare\\ComposerPlugin\\ComposerPlugin"
}
}
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace Nightmare\ComposerPlugin;
use Composer\Plugin\PluginInterface;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Installer\PackageEvent;
use Composer\Script\Event;
class ComposerPlugin implements PluginInterface, EventSubscriberInterface
{
public function activate(\Composer\Composer $composer, \Composer\IO\IOInterface $io) {}
public function deactivate(\Composer\Composer $composer, \Composer\IO\IOInterface $io) {}
public function uninstall(\Composer\Composer $composer, \Composer\IO\IOInterface $io) {}
public static function getSubscribedEvents()
{
return [
'post-install-cmd' => 'create_htaccess',
'post-update-cmd' => 'create_htaccess'
];
}
public function create_htaccess(Event $event)
{
$vendor_dir = $event->getComposer()->getConfig()->get('vendor-dir');
$htaccess_path = $vendor_dir . '/.htaccess';
$content = "Require all denied";
file_put_contents($htaccess_path, $content);
$event->getIO()->write("<info>created .htaccess in $vendor_dir</info>");
}
}