How to get package name in script?

composer-php, php

Solution

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()`.

Problem

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?

Original source