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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -