Created
November 26, 2015 11:06
-
-
Save derhasi/8afdd0ba314fa6953716 to your computer and use it in GitHub Desktop.
PoC for script update event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"prefer-stable": true, | |
"autoload": { | |
"psr-4": { | |
"DrupalComposer\\DrupalProject\\": "." | |
} | |
}, | |
"scripts": { | |
"post-package-install": [ | |
"DrupalComposer\\DrupalProject\\Scripts::hook" | |
], | |
"post-package-update": [ | |
"DrupalComposer\\DrupalProject\\Scripts::hook" | |
] | |
}, | |
"require": { | |
"monolog/monolog": "1.17.0", | |
"composer/composer": "dev-master" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace DrupalComposer\DrupalProject; | |
use Composer\DependencyResolver\Operation\InstallOperation; | |
use Composer\DependencyResolver\Operation\UninstallOperation; | |
use Composer\DependencyResolver\Operation\UpdateOperation; | |
use Composer\Package\PackageInterface; | |
class Scripts { | |
public static function hook(\Composer\Installer\PackageEvent $event){ | |
$operation = $event->getOperation(); | |
if ($operation instanceof InstallOperation) { | |
$package = $operation->getPackage(); | |
} | |
elseif ($operation instanceof UpdateOperation) { | |
$package = $operation->getTargetPackage(); | |
} | |
elseif ($operation instanceof UninstallOperation) { | |
$package = $operation->getPackage(); | |
} | |
if ($package && $package instanceof PackageInterface) { | |
/** @var \Composer\Installer\InstallationManager $installationManager */ | |
$installationManager = $event->getComposer()->getInstallationManager(); | |
$path = $installationManager->getInstallPath($package); | |
$event->getIO()->write(sprintf('Event called: %s, Package: %s (%s), Path: %s', | |
$event->getName(), | |
$package->getName(), | |
$package->getVersion(), | |
$path | |
), TRUE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment