Example #1
0
 /**
  * Gets all tags that exist in the repository
  *
  * @return Version[] Array where the keys are the version tags, and the values are Version object instances
  */
 public function getTags()
 {
     // Return cached values
     if ($this->tags) {
         return $this->tags;
     }
     // Get tag strings
     $repo = $this->getRepository();
     $result = $repo->run('tag');
     $tags = preg_split('~\\R~u', $result);
     $tags = array_filter($tags);
     // Objectify tags
     $this->tags = [];
     foreach ($tags as $tag) {
         // Skip invalid tags
         if (Version::parse($tag)) {
             $version = new Version($tag);
             $this->tags[$version->getValue()] = $version;
         }
     }
     return $this->tags;
 }
Example #2
0
 /**
  * ComposerConstraint constructor.
  * @param string $constraint
  * @param Version $parentVersion
  * @param string $name Name of dependency
  */
 public function __construct($constraint, $parentVersion = null, $name = null)
 {
     $this->setValue($constraint);
     if ($constraint === 'self.version') {
         if (!$parentVersion instanceof Version) {
             throw new InvalidArgumentException("{$name} dependency self.version given with missing parent version");
         }
         $this->isSelfVersion = true;
         $this->minVersion = $parentVersion;
         $this->maxVersion = $parentVersion;
         return;
     }
     // Check if matches explicit version (4.0.0, no semver flags)
     if (Version::parse($constraint)) {
         $this->minVersion = new Version($constraint);
         $this->maxVersion = new Version($constraint);
         return;
     }
     // Parse type
     $parsed = static::parse($constraint);
     if (!$parsed) {
         throw new InvalidArgumentException("Composer constraint {$constraint} for {$name} is not semver-compatible. " . "E.g. ^4.0, self.version, or a fixed version");
     }
     // From version ignores modifier, includes alpha1 tag. :)
     if (empty($parsed['stability'])) {
         $fromStability = '';
     } else {
         $fromStabilityVersion = isset($parsed['stabilityVersion']) ? $parsed['stabilityVersion'] : '';
         $fromStability = '-' . $parsed['stability'] . $fromStabilityVersion;
     }
     $from = sprintf("%d.%d.%d%s", $parsed['major'], isset($parsed['minor']) ? $parsed['minor'] : '0', isset($parsed['patch']) ? $parsed['patch'] : '0', $fromStability);
     // Semver to
     if ($parsed['type'] === '^') {
         $to = $parsed['major'] . '.99999.99999';
     } elseif (isset($parsed['patch']) && strlen($parsed['patch'])) {
         // ~x.y.z
         $to = $parsed['major'] . '.' . $parsed['minor'] . '.99999';
     } elseif (isset($parsed['minor']) && strlen($parsed['minor'])) {
         // ~x.y
         $to = $parsed['major'] . '.99999.99999';
     } else {
         // ~y
         $to = '99999.99999.99999';
     }
     $this->minVersion = new Version($from);
     $this->maxVersion = new Version($to);
 }
Example #3
0
 /**
  * Update the version of a selected library
  *
  * @param OutputInterface $output
  * @param InputInterface $input
  * @param LibraryRelease $selectedVersion
  */
 protected function reviewLibraryVersion(OutputInterface $output, InputInterface $input, LibraryRelease $selectedVersion)
 {
     $question = new Question("Please enter a new version to release for <info>" . $selectedVersion->getLibrary()->getName() . "</info>: ", $selectedVersion->getVersion());
     $newVersionName = $this->getQuestionHelper()->ask($input, $output, $question);
     // If version is valid, update and return
     if (Version::parse($newVersionName)) {
         // Warn if upgrade-only and selected version isn't an existing tag
         if ($selectedVersion->getLibrary()->isUpgradeOnly()) {
             $tags = $selectedVersion->getLibrary()->getTags();
             if (!array_key_exists($newVersionName, $tags)) {
                 $this->log($output, "This library is marked as upgrade-only; {$newVersionName} is not an existing tag", 'error');
                 $this->reviewLibraryVersion($output, $input, $selectedVersion);
                 return;
             }
         }
         // Update release version
         $newVersion = new Version($newVersionName);
         $this->modifyLibraryReleaseVersion($selectedVersion, $newVersion);
         // Save modified plan to cache immediately
         $this->getProject()->saveCachedPlan($this->getReleasePlan());
         return;
     }
     // If error, repeat
     $this->log($output, "Invalid version {$newVersionName}; Please enter a tag in w.x.y(-[rc|alpha|beta][z]) format", "error");
     $this->reviewLibraryVersion($output, $input, $selectedVersion);
 }