Skip to content

Commit 9965a6b

Browse files
committed
prePackageUninstall method
1 parent e7687c8 commit 9965a6b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/Illuminate/Foundation/ComposerScripts.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Foundation;
44

5+
use Composer\Installer\PackageEvent;
56
use Composer\Script\Event;
67

78
class ComposerScripts
@@ -45,6 +46,40 @@ public static function postAutoloadDump(Event $event)
4546
static::clearCompiled();
4647
}
4748

49+
/**
50+
* Handle the pre-package-uninstall Composer event.
51+
*
52+
* @param \Composer\Installer\PackageEvent $event
53+
* @return void
54+
*/
55+
public static function prePackageUninstall(PackageEvent $event)
56+
{
57+
$bootstrapFile = $event->getComposer()->getConfig()->get('base-dir');
58+
59+
$bootstrapFile = dirname($vendorDir = $event->getComposer()->getConfig()->get('vendor-dir')).'/bootstrap/app.php';
60+
61+
if (! file_exists($bootstrapFile)) {
62+
return;
63+
}
64+
65+
require_once $vendorDir.'/autoload.php';
66+
67+
define('LARAVEL_START', microtime(true));
68+
69+
/** @var Application $app */
70+
$app = require_once $bootstrapFile;
71+
72+
/** @var \Composer\DependencyResolver\Operation\UninstallOperation $uninstallOperation */
73+
$uninstallOperation = $event->getOperation()->getPackage();
74+
$packageName = $uninstallOperation->getName();
75+
$isDev = $uninstallOperation->isDev();
76+
77+
$app['events']->dispatch('composer_package:uninstall:'.$packageName, [
78+
'package' => $packageName,
79+
'isDev' => $isDev,
80+
]);
81+
}
82+
4883
/**
4984
* Clear the cached Laravel bootstrapping files.
5085
*

0 commit comments

Comments
 (0)