Пример #1
0
 private function compareMeta(Version $version1, Version $version2)
 {
     $v1IsPreRelease = $version1->isPreRelease();
     $v2IsPreRelease = $version2->isPreRelease();
     if ($v1IsPreRelease xor $v2IsPreRelease) {
         return !$v1IsPreRelease ? 1 : -1;
         // pre-release version has lower precedence than a normal version
     }
     $result = $version1->getPreRelease()->compareTo($version2->getPreRelease());
     if ($result > 0) {
         return 1;
     }
     if ($result < 0) {
         return -1;
     }
     return 0;
 }
Пример #2
0
 /**
  * @param array $versions
  */
 public function __construct(array $versions)
 {
     foreach ($versions as $version) {
         if (is_string($version)) {
             $version = Version::fromString($version);
         } elseif (!$version instanceof Version) {
             throw new InvalidArgumentException(sprintf('Item in the versions array should be either string or Version instance, %s given', gettype($version)));
         }
         $this->versions[] = $version;
     }
 }
Пример #3
0
 /**
  * @param string $constraintStringUnit
  * @return Constraint
  */
 protected function buildConstraintFromStringUnit($constraintStringUnit)
 {
     list($operator, $operandString) = array_values($this->parseConstraintStringUnit($constraintStringUnit));
     if (empty($operandString)) {
         $this->error();
     }
     try {
         return Constraint::fromProperties($operator ?: Constraint::OPERATOR_EQ, Version::fromString($operandString));
     } catch (Exception $ex) {
         $this->error();
     }
 }
Пример #4
0
 /**
  * Determines if the update prompt should show.
  *
  * @param View $view
  */
 public function compose(View $view)
 {
     $latest_tag = $this->release->latest();
     $current = Version::parse(APP_VERSION);
     $latest = Version::parse(APP_VERSION);
     if ($latest_tag) {
         $latest = Version::parse($latest_tag);
     }
     $is_outdated = $latest->compare($current) === 1;
     $view->with('is_outdated', $is_outdated);
     $view->with('current_version', $current);
     $view->with('latest_version', $latest);
 }
 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException When the target directory does not exist or symlink cannot be used
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $targetArg = rtrim($input->getArgument('target'), '/');
     if (!is_dir($targetArg)) {
         throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
     }
     $wantedVersion = $input->getOption('zeroclipboard-version');
     try {
         $versionConstraint = Constraint::parse($wantedVersion);
     } catch (UnexpectedValueException $e) {
         $output->writeln('<error>Error:</error> <info>' . $wantedVersion . '</info> is not a valid version constraint.');
         return;
     }
     $minimalConstraint = new SimpleConstraint(new Operator('>='), Version::parse($this->minimalSupportedVersion));
     if (!$minimalConstraint->matches($versionConstraint)) {
         $output->writeln('<error>Error:</error> <info>' . $wantedVersion . '</info> is not supported. Minimal version is: ' . $this->minimalSupportedVersion);
         return;
     }
     $curl = new Curl();
     $curl->get('https://api.github.com' . '/repos/zeroclipboard/zeroclipboard/tags?per_page=100');
     $versionToInstall = null;
     $versionToInstallObj = new Version(1, 0, 6);
     foreach (json_decode($curl->response) as $release) {
         try {
             $tag = Version::parse($release->name);
             if ($tag->getStability()->isStable()) {
                 $constraint = new SimpleConstraint(new Operator('='), $tag);
                 if ($constraint->isSubsetOf($versionConstraint)) {
                     if ($tag->compare($versionToInstallObj) > 0) {
                         $versionToInstall = $release->name;
                         $versionToInstallObj = $tag;
                     }
                 } else {
                 }
             }
         } catch (\Exception $e) {
         }
     }
     if (!$versionToInstall) {
         $output->writeln('<error>Error:</error> <info>' . $wantedVersion . '</info> is greator than the last release. ');
         return;
     }
     /** @var Filesystem $filesystem */
     $filesystem = $this->getContainer()->get('filesystem');
     // Create the bundles directory otherwise symlink will fail.
     $bundlesDir = $targetArg . '/bundles/';
     $filesystem->mkdir($bundlesDir, 0777);
     $output->writeln('Installing ZeroClipboard assets.');
     $targetDir = $bundlesDir . 'zeroclipboard-assets';
     $namespaceParts = explode('\\', __NAMESPACE__);
     array_pop($namespaceParts);
     $output->writeln(sprintf('Installing assets for <comment>%s</comment> into <comment>%s</comment>', implode('\\', $namespaceParts), $targetDir));
     $filesystem->remove($targetDir);
     $filesystem->mkdir($targetDir, 0777);
     $filesystem->mkdir($targetDir . '/tmp');
     $zip = file_get_contents('https://github.com/zeroclipboard/zeroclipboard/archive/' . $versionToInstall . '.zip');
     file_put_contents($targetDir . '/tmp/zeroclipboard.zip', $zip);
     $zip = new \ZipArchive();
     if ($zip->open($targetDir . '/tmp/zeroclipboard.zip') === TRUE) {
         $zip->extractTo($targetDir . '/tmp');
         $zip->close();
         if (file_exists($targetDir . '/tmp/zeroclipboard-' . $versionToInstall . '/dist')) {
             $filesystem->mirror($targetDir . '/tmp/zeroclipboard-' . $versionToInstall . '/dist', $targetDir);
         } else {
             $versionToInstall = $versionToInstallObj->getMajor() . '.' . $versionToInstallObj->getMinor() . '.' . $versionToInstallObj->getRevision();
             if (file_exists($targetDir . '/tmp/zeroclipboard-' . $versionToInstall . '/dist')) {
                 $filesystem->mirror($targetDir . '/tmp/zeroclipboard-' . $versionToInstall . '/dist', $targetDir);
             } else {
                 foreach (array('ZeroClipboard.js', 'ZeroClipboard.min.js', 'ZeroClipboard.min.map', 'ZeroClipboard.Core.js', 'ZeroClipboard.Core.min.js', 'ZeroClipboard.Core.min.map', 'ZeroClipboard.swf') as $file) {
                     if (file_exists($targetDir . '/tmp/zeroclipboard-' . $versionToInstall . '/' . $file)) {
                         $filesystem->copy($targetDir . '/tmp/zeroclipboard-' . $versionToInstall . '/' . $file, $targetDir . '/' . $file);
                     }
                 }
             }
         }
         $filesystem->remove($targetDir . '/tmp');
     } else {
         throw new FileException('File Error');
     }
 }
Пример #6
0
 /**
  * {@inheritDoc}
  */
 public function assert(Version $version)
 {
     switch ($this->operator) {
         case self::OPERATOR_EQ:
             return $version->isEqualTo($this->operand);
         case self::OPERATOR_NEQ:
             return !$version->isEqualTo($this->operand);
         case self::OPERATOR_GT:
             return $version->isGreaterThan($this->operand);
         case self::OPERATOR_GTE:
             return $version->isGreaterOrEqualTo($this->operand);
         case self::OPERATOR_LT:
             return $version->isLessThan($this->operand);
         case self::OPERATOR_LTE:
             return $version->isLessOrEqualTo($this->operand);
     }
 }