Пример #1
0
 public function download(PackageInterface $package, $targetDir, $preferSource = null)
 {
     $preferSource = null !== $preferSource ? $preferSource : $this->preferSource;
     $sourceType = $package->getSourceType();
     $distType = $package->getDistType();
     if ((!$package->isDev() || $this->preferDist || !$sourceType) && !($preferSource && $sourceType) && $distType) {
         $package->setInstallationSource('dist');
     } elseif ($sourceType) {
         $package->setInstallationSource('source');
     } else {
         throw new \InvalidArgumentException('Package ' . $package . ' must have a source or dist specified');
     }
     $this->filesystem->ensureDirectoryExists($targetDir);
     $downloader = $this->getDownloaderForInstalledPackage($package);
     $downloader->download($package, $targetDir);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function setInstallationSource($type)
 {
     $this->package->setInstallationSource($type);
 }
 /**
  * @param PackageInterface $package
  */
 public function setPackageInstallationSource(PackageInterface $package)
 {
     if (null == $package->getInstallationSource()) {
         $package->setInstallationSource($this->getPackageInstallationSource($package));
     }
 }
Пример #4
0
 public function setInstallationSource($type)
 {
     $this->aliasOf->setInstallationSource($type);
 }
Пример #5
0
 /**
  * Downloads package into target dir.
  *
  * @param PackageInterface $package      package instance
  * @param string           $targetDir    target dir
  * @param bool             $preferSource prefer installation from source
  *
  * @throws \InvalidArgumentException if package have no urls to download from
  * @throws \RuntimeException
  */
 public function download(PackageInterface $package, $targetDir, $preferSource = null)
 {
     $preferSource = null !== $preferSource ? $preferSource : $this->preferSource;
     $sourceType = $package->getSourceType();
     $distType = $package->getDistType();
     $sources = array();
     if ($sourceType) {
         $sources[] = 'source';
     }
     if ($distType) {
         $sources[] = 'dist';
     }
     if (empty($sources)) {
         throw new \InvalidArgumentException('Package ' . $package . ' must have a source or dist specified');
     }
     if ((!$package->isDev() || $this->preferDist) && !$preferSource) {
         $sources = array_reverse($sources);
     }
     $this->filesystem->ensureDirectoryExists($targetDir);
     foreach ($sources as $i => $source) {
         if (isset($e)) {
             $this->io->writeError('    <warning>Now trying to download from ' . $source . '</warning>');
         }
         $package->setInstallationSource($source);
         try {
             $downloader = $this->getDownloaderForInstalledPackage($package);
             if ($downloader) {
                 $downloader->download($package, $targetDir);
             }
             break;
         } catch (\RuntimeException $e) {
             if ($i === count($sources) - 1) {
                 throw $e;
             }
             $this->io->writeError('    <warning>Failed to download ' . $package->getPrettyName() . ' from ' . $source . ': ' . $e->getMessage() . '</warning>');
         }
     }
 }
Пример #6
0
 /**
  * Updates package from initial to target version.
  *
  * @param   PackageInterface    $initial    initial package version
  * @param   PackageInterface    $target     target package version
  * @param   string              $targetDir  target dir
  *
  * @throws  InvalidArgumentException        if initial package is not installed
  */
 public function update(PackageInterface $initial, PackageInterface $target, $targetDir)
 {
     $downloader = $this->getDownloaderForInstalledPackage($initial);
     $installationSource = $initial->getInstallationSource();
     if ('dist' === $installationSource) {
         $initialType = $initial->getDistType();
         $targetType = $target->getDistType();
     } else {
         $initialType = $initial->getSourceType();
         $targetType = $target->getSourceType();
     }
     if ($initialType === $targetType) {
         $target->setInstallationSource($installationSource);
         $downloader->update($initial, $target, $targetDir);
     } else {
         $downloader->remove($initial, $targetDir);
         $this->download($target, $targetDir, 'source' === $installationSource);
     }
 }