php - How to get package name in script? -


i'm doing short post package install/update script copy files vendor directory public one.

following example of composer site when execute error:

fatal error: call 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 please advise?

following further testing have identified issue, due 2 different interfaces having same/a similar method different signatures. thusly have ended 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().


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -