/** * Download a package file. * * @param string $path * @param string $url * @param string $shasum */ public function downloadFile($path, $url, $shasum = '') { $file = $path . '/' . uniqid(); try { $data = $this->client->get($url)->getBody(); if ($shasum && sha1($data) !== $shasum) { throw new ChecksumVerificationException("The file checksum verification failed"); } if (!$this->files->makeDir($path) || !$this->files->putContents($file, $data)) { throw new NotWritableException("The path is not writable ({$path})"); } if (Zip::extract($file, $path) !== true) { throw new ArchiveExtractionException("The file extraction failed"); } $this->files->delete($file); } catch (\Exception $e) { $this->files->delete($path); if ($e instanceof TransferException) { if ($e instanceof BadResponseException) { throw new UnauthorizedDownloadException("Unauthorized download ({$url})"); } throw new DownloadErrorException("The file download failed ({$url})"); } throw $e; } }
/** * {@inheritdoc} */ public function uninstall(PackageInterface $package) { if (!$this->repository->hasPackage($package)) { throw new LogicException('Package is not installed: ' . $package); } $this->filesystem->delete($this->repository->getInstallPath($package)); $this->repository->removePackage($package); }