I'm doing a short post package install/update script to copy some files from the vendor
directory into my public
one.
Following the example of the composer
site however when I execute it I get an error:
Fatal error: Call to undefined method Composer\DependencyResolver\Operation\UpdateOperation::getPackage() in S:\Projects\composer-scripts\FileCopy.php on line 17
The code is:
namespace composer-scipts;
use Composer\Script\Event;
class FileCopy
{
public static function postPackageInstall( Event $event )
{
$packageName = $event->getOperation()->getPackage()->getName();
echo "$packageName\n";
}
public static function postPackageUpdate( Event $event )
{
$packageName = $event->getOperation()->getPackage()->getName();
echo "$packageName\n";
}
}
Can anyone please advise?
Following further testing I have identified the issue, which is essentially due to two different interfaces having the same/a similar method but with different signatures. Thusly I have ended up with:
public static function postPackageInstall( Event $event )
{
$packageName = $event->getOperation()->getPackage()->getName();
if( $packageName == 'twbs/bootstrap' )
{
self::copyFiles();
}
}
public static function postPackageUpdate( Event $event )
{
$packageName = $event->getOperation()->getInitialPackage()->getName();
if( $packageName == 'twbs/bootstrap' )
{
self::copyFiles();
}
}
So, postPackageInstall uses getPackage()
where-as postPackageUpdate uses getInitialPackage()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With