Преглед изворни кода

#8809: expand context for post file download event

Lucas D Hedding пре 5 година
родитељ
комит
3e2163de5c

+ 1 - 1
src/Composer/Downloader/FileDownloader.php

@@ -159,7 +159,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
                 }
 
                 if ($eventDispatcher) {
-                    $postFileDownloadEvent = new PostFileDownloadEvent(PluginEvents::POST_FILE_DOWNLOAD, $fileName, $checksum, $url['processed']);
+                    $postFileDownloadEvent = new PostFileDownloadEvent(PluginEvents::POST_FILE_DOWNLOAD, $fileName, $checksum, $url['processed'], $package);
                     $eventDispatcher->dispatch($postFileDownloadEvent->getName(), $postFileDownloadEvent);
                 }
 

+ 19 - 2
src/Composer/Plugin/PostFileDownloadEvent.php

@@ -13,7 +13,7 @@
 namespace Composer\Plugin;
 
 use Composer\EventDispatcher\Event;
-use Composer\Util\RemoteFilesystem;
+use Composer\Package\PackageInterface;
 
 /**
  * The post file download event.
@@ -38,6 +38,11 @@ class PostFileDownloadEvent extends Event
      */
     private $url;
 
+    /**
+     * @var \Composer\Package\PackageInterface
+     */
+    private $package;
+
     /**
      * Constructor.
      *
@@ -45,13 +50,15 @@ class PostFileDownloadEvent extends Event
      * @param string           $fileName     The file name
      * @param string|null      $checksum     The checksum
      * @param string           $url          The processed url
+     * @param PackageInterface $package      The package.
      */
-    public function __construct($name, $fileName, $checksum, $url)
+    public function __construct($name, $fileName, $checksum, $url, PackageInterface $package)
     {
         parent::__construct($name);
         $this->fileName = $fileName;
         $this->checksum = $checksum;
         $this->url = $url;
+        $this->package = $package;
     }
 
     /**
@@ -82,4 +89,14 @@ class PostFileDownloadEvent extends Event
         return $this->url;
     }
 
+    /**
+     * Get the package.
+     *
+     * @return \Composer\Package\PackageInterface
+     *   The package.
+     */
+    public function getPackage() {
+        return $this->package;
+    }
+
 }