private function getMediaWikiVersionConstraint()
 {
     $mvVersion = $this->versionFetcher->fetchVersion();
     $mvVersion = $this->versionNormalizer->normalizeSuffix($mvVersion);
     $version = new Constraint('==', $this->versionNormalizer->normalizeLevelCount($mvVersion));
     $version->setPrettyString($mvVersion);
     return $version;
 }
Esempio n. 2
0
 public function versionCompare(PackageInterface $a, PackageInterface $b, $operator)
 {
     if ($this->preferStable && ($stabA = $a->getStability()) !== ($stabB = $b->getStability())) {
         return BasePackage::$stabilities[$stabA] < BasePackage::$stabilities[$stabB];
     }
     $constraint = new Constraint($operator, $b->getVersion());
     $version = new Constraint('==', $a->getVersion());
     return $constraint->matchSpecific($version, true);
 }
 /**
  * Compares two versions and returns 0 if $a == $b, -1 if $a < $b and +1 if $b > $a.
  *
  * @param AddonVersion
  * @param AddonVersion
  * @return int
  */
 public function compare(AddonVersion $a, AddonVersion $b)
 {
     $parser = $this->getParser();
     $a = $parser->normalize($a->version);
     $b = $parser->normalize($b->version);
     $constraint = new Constraint('==', $a);
     if ($constraint->versionCompare($a, $b, '==')) {
         return 0;
     } elseif ($constraint->versionCompare($a, $b, '<')) {
         return -1;
     } else {
         return 1;
     }
 }
Esempio n. 4
0
 /**
  * @param  RootPackageInterface $rootPackage
  * @param  PlatformRepository   $platformRepo
  * @return Request
  */
 private function createRequest(RootPackageInterface $rootPackage, PlatformRepository $platformRepo)
 {
     $request = new Request();
     $constraint = new Constraint('=', $rootPackage->getVersion());
     $constraint->setPrettyString($rootPackage->getPrettyVersion());
     $request->install($rootPackage->getName(), $constraint);
     $fixedPackages = $platformRepo->getPackages();
     if ($this->additionalInstalledRepository) {
         $additionalFixedPackages = $this->additionalInstalledRepository->getPackages();
         $fixedPackages = array_merge($fixedPackages, $additionalFixedPackages);
     }
     // fix the version of all platform packages + additionally installed packages
     // to prevent the solver trying to remove or update those
     $provided = $rootPackage->getProvides();
     foreach ($fixedPackages as $package) {
         $constraint = new Constraint('=', $package->getVersion());
         $constraint->setPrettyString($package->getPrettyVersion());
         // skip platform packages that are provided by the root package
         if ($package->getRepository() !== $platformRepo || !isset($provided[$package->getName()]) || !$provided[$package->getName()]->getConstraint()->matches($constraint)) {
             $request->fix($package->getName(), $constraint);
         }
     }
     return $request;
 }
Esempio n. 5
0
 public function load(array $config, $class = 'Composer\\Package\\CompletePackage')
 {
     $this->errors = array();
     $this->warnings = array();
     $this->config = $config;
     if ($this->strictName) {
         $this->validateRegex('name', '[A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9][A-Za-z0-9_.-]*', true);
     } else {
         $this->validateString('name', true);
     }
     if (!empty($this->config['version'])) {
         try {
             $this->versionParser->normalize($this->config['version']);
         } catch (\Exception $e) {
             $this->errors[] = 'version : invalid value (' . $this->config['version'] . '): ' . $e->getMessage();
             unset($this->config['version']);
         }
     }
     $this->validateRegex('type', '[A-Za-z0-9-]+');
     $this->validateString('target-dir');
     $this->validateArray('extra');
     $this->validateFlatArray('bin');
     $this->validateArray('scripts');
     // TODO validate event names & listener syntax
     $this->validateString('description');
     $this->validateUrl('homepage');
     $this->validateFlatArray('keywords', '[\\p{N}\\p{L} ._-]+');
     if (isset($this->config['license'])) {
         if (is_string($this->config['license'])) {
             $this->validateRegex('license', '[A-Za-z0-9+. ()-]+');
         } else {
             $this->validateFlatArray('license', '[A-Za-z0-9+. ()-]+');
         }
     }
     $this->validateString('time');
     if (!empty($this->config['time'])) {
         try {
             $date = new \DateTime($this->config['time'], new \DateTimeZone('UTC'));
         } catch (\Exception $e) {
             $this->errors[] = 'time : invalid value (' . $this->config['time'] . '): ' . $e->getMessage();
             unset($this->config['time']);
         }
     }
     if ($this->validateArray('authors') && !empty($this->config['authors'])) {
         foreach ($this->config['authors'] as $key => $author) {
             if (!is_array($author)) {
                 $this->errors[] = 'authors.' . $key . ' : should be an array, ' . gettype($author) . ' given';
                 unset($this->config['authors'][$key]);
                 continue;
             }
             foreach (array('homepage', 'email', 'name', 'role') as $authorData) {
                 if (isset($author[$authorData]) && !is_string($author[$authorData])) {
                     $this->errors[] = 'authors.' . $key . '.' . $authorData . ' : invalid value, must be a string';
                     unset($this->config['authors'][$key][$authorData]);
                 }
             }
             if (isset($author['homepage']) && !$this->filterUrl($author['homepage'])) {
                 $this->warnings[] = 'authors.' . $key . '.homepage : invalid value (' . $author['homepage'] . '), must be an http/https URL';
                 unset($this->config['authors'][$key]['homepage']);
             }
             if (isset($author['email']) && !filter_var($author['email'], FILTER_VALIDATE_EMAIL)) {
                 $this->warnings[] = 'authors.' . $key . '.email : invalid value (' . $author['email'] . '), must be a valid email address';
                 unset($this->config['authors'][$key]['email']);
             }
             if (empty($this->config['authors'][$key])) {
                 unset($this->config['authors'][$key]);
             }
         }
         if (empty($this->config['authors'])) {
             unset($this->config['authors']);
         }
     }
     if ($this->validateArray('support') && !empty($this->config['support'])) {
         foreach (array('issues', 'forum', 'wiki', 'source', 'email', 'irc', 'docs', 'rss') as $key) {
             if (isset($this->config['support'][$key]) && !is_string($this->config['support'][$key])) {
                 $this->errors[] = 'support.' . $key . ' : invalid value, must be a string';
                 unset($this->config['support'][$key]);
             }
         }
         if (isset($this->config['support']['email']) && !filter_var($this->config['support']['email'], FILTER_VALIDATE_EMAIL)) {
             $this->warnings[] = 'support.email : invalid value (' . $this->config['support']['email'] . '), must be a valid email address';
             unset($this->config['support']['email']);
         }
         if (isset($this->config['support']['irc']) && !$this->filterUrl($this->config['support']['irc'], array('irc'))) {
             $this->warnings[] = 'support.irc : invalid value (' . $this->config['support']['irc'] . '), must be a irc://<server>/<channel> URL';
             unset($this->config['support']['irc']);
         }
         foreach (array('issues', 'forum', 'wiki', 'source', 'docs') as $key) {
             if (isset($this->config['support'][$key]) && !$this->filterUrl($this->config['support'][$key])) {
                 $this->warnings[] = 'support.' . $key . ' : invalid value (' . $this->config['support'][$key] . '), must be an http/https URL';
                 unset($this->config['support'][$key]);
             }
         }
         if (empty($this->config['support'])) {
             unset($this->config['support']);
         }
     }
     $unboundConstraint = new Constraint('=', $this->versionParser->normalize('dev-master'));
     $stableConstraint = new Constraint('=', '1.0.0');
     foreach (array_keys(BasePackage::$supportedLinkTypes) as $linkType) {
         if ($this->validateArray($linkType) && isset($this->config[$linkType])) {
             foreach ($this->config[$linkType] as $package => $constraint) {
                 if (!preg_match('{^[A-Za-z0-9_./-]+$}', $package)) {
                     $this->warnings[] = $linkType . '.' . $package . ' : invalid key, package names must be strings containing only [A-Za-z0-9_./-]';
                 }
                 if (!is_string($constraint)) {
                     $this->errors[] = $linkType . '.' . $package . ' : invalid value, must be a string containing a version constraint';
                     unset($this->config[$linkType][$package]);
                 } elseif ('self.version' !== $constraint) {
                     try {
                         $linkConstraint = $this->versionParser->parseConstraints($constraint);
                     } catch (\Exception $e) {
                         $this->errors[] = $linkType . '.' . $package . ' : invalid version constraint (' . $e->getMessage() . ')';
                         unset($this->config[$linkType][$package]);
                         continue;
                     }
                     // check requires for unbound constraints on non-platform packages
                     if ($this->flags & self::CHECK_UNBOUND_CONSTRAINTS && 'require' === $linkType && $linkConstraint->matches($unboundConstraint) && !preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $package)) {
                         $this->warnings[] = $linkType . '.' . $package . ' : unbound version constraints (' . $constraint . ') should be avoided';
                     } elseif ($this->flags & self::CHECK_STRICT_CONSTRAINTS && 'require' === $linkType && substr($linkConstraint, 0, 1) === '=' && $stableConstraint->versionCompare($stableConstraint, $linkConstraint, '<=')) {
                         $this->warnings[] = $linkType . '.' . $package . ' : exact version constraints (' . $constraint . ') should be avoided if the package follows semantic versioning';
                     }
                 }
             }
         }
     }
     if ($this->validateArray('suggest') && !empty($this->config['suggest'])) {
         foreach ($this->config['suggest'] as $package => $description) {
             if (!is_string($description)) {
                 $this->errors[] = 'suggest.' . $package . ' : invalid value, must be a string describing why the package is suggested';
                 unset($this->config['suggest'][$package]);
             }
         }
     }
     if ($this->validateString('minimum-stability') && !empty($this->config['minimum-stability'])) {
         if (!isset(BasePackage::$stabilities[$this->config['minimum-stability']])) {
             $this->errors[] = 'minimum-stability : invalid value (' . $this->config['minimum-stability'] . '), must be one of ' . implode(', ', array_keys(BasePackage::$stabilities));
             unset($this->config['minimum-stability']);
         }
     }
     if ($this->validateArray('autoload') && !empty($this->config['autoload'])) {
         $types = array('psr-0', 'psr-4', 'classmap', 'files', 'exclude-from-classmap');
         foreach ($this->config['autoload'] as $type => $typeConfig) {
             if (!in_array($type, $types)) {
                 $this->errors[] = 'autoload : invalid value (' . $type . '), must be one of ' . implode(', ', $types);
                 unset($this->config['autoload'][$type]);
             }
             if ($type === 'psr-4') {
                 foreach ($typeConfig as $namespace => $dirs) {
                     if ($namespace !== '' && '\\' !== substr($namespace, -1)) {
                         $this->errors[] = 'autoload.psr-4 : invalid value (' . $namespace . '), namespaces must end with a namespace separator, should be ' . $namespace . '\\\\';
                     }
                 }
             }
         }
     }
     if (!empty($this->config['autoload']['psr-4']) && !empty($this->config['target-dir'])) {
         $this->errors[] = 'target-dir : this can not be used together with the autoload.psr-4 setting, remove target-dir to upgrade to psr-4';
         // Unset the psr-4 setting, since unsetting target-dir might
         // interfere with other settings.
         unset($this->config['autoload']['psr-4']);
     }
     // TODO validate dist
     // TODO validate source
     // TODO validate repositories
     // TODO validate package repositories' packages using this recursively
     $this->validateFlatArray('include-path');
     $this->validateArray('transport-options');
     // branch alias validation
     if (isset($this->config['extra']['branch-alias'])) {
         if (!is_array($this->config['extra']['branch-alias'])) {
             $this->errors[] = 'extra.branch-alias : must be an array of versions => aliases';
         } else {
             foreach ($this->config['extra']['branch-alias'] as $sourceBranch => $targetBranch) {
                 // ensure it is an alias to a -dev package
                 if ('-dev' !== substr($targetBranch, -4)) {
                     $this->warnings[] = 'extra.branch-alias.' . $sourceBranch . ' : the target branch (' . $targetBranch . ') must end in -dev';
                     unset($this->config['extra']['branch-alias'][$sourceBranch]);
                     continue;
                 }
                 // normalize without -dev and ensure it's a numeric branch that is parseable
                 $validatedTargetBranch = $this->versionParser->normalizeBranch(substr($targetBranch, 0, -4));
                 if ('-dev' !== substr($validatedTargetBranch, -4)) {
                     $this->warnings[] = 'extra.branch-alias.' . $sourceBranch . ' : the target branch (' . $targetBranch . ') must be a parseable number like 2.0-dev';
                     unset($this->config['extra']['branch-alias'][$sourceBranch]);
                     continue;
                 }
                 // If using numeric aliases ensure the alias is a valid subversion
                 if (($sourcePrefix = $this->versionParser->parseNumericAliasPrefix($sourceBranch)) && ($targetPrefix = $this->versionParser->parseNumericAliasPrefix($targetBranch)) && stripos($targetPrefix, $sourcePrefix) !== 0) {
                     $this->warnings[] = 'extra.branch-alias.' . $sourceBranch . ' : the target branch (' . $targetBranch . ') is not a valid numeric alias for this version';
                     unset($this->config['extra']['branch-alias'][$sourceBranch]);
                 }
             }
         }
     }
     if ($this->errors) {
         throw new InvalidPackageException($this->errors, $this->warnings, $config);
     }
     $package = $this->loader->load($this->config, $class);
     $this->config = null;
     return $package;
 }
Esempio n. 6
0
 /**
  * @return bool
  */
 public function isLatest()
 {
     $constraint = new Constraint('==', $this->latestPackage->getVersion());
     return $constraint->matches($this->getCurrentVersion());
 }
Esempio n. 7
0
 protected function getVersionConstraint($operator, $version)
 {
     $constraint = new Constraint($operator, self::getVersionParser()->normalize($version));
     $constraint->setPrettyString($operator . ' ' . $version);
     return $constraint;
 }
Esempio n. 8
0
 private function createConstraint($operator, $version)
 {
     $constraint = new Constraint($operator, $version);
     $constraint->setPrettyString($operator . ' ' . $version);
     return $constraint;
 }
 public function resolveFeatureBranch(Event $event)
 {
     if (empty($this->featureBranchRepositories)) {
         $this->io->write('No feature branches configured, continuing!');
         return;
     }
     $package = $this->composer->getPackage();
     if ($package->isDev()) {
         $featureBranchConstraint = new Constraint('=', $this->versionParser->normalize($package->getVersion()));
         $featureBranchConstraint->setPrettyString($package->getVersion());
         $requires = $package->getRequires();
         $this->io->write(sprintf("<info>Checking for feature branch '%s'</info>", $featureBranchConstraint->getPrettyString()));
         foreach ($requires as $key => $require) {
             if ($this->hasFeatureBranch($require, $featureBranchConstraint)) {
                 $requires[$key] = new Link($require->getSource(), $require->getTarget(), $featureBranchConstraint, 'requires', $featureBranchConstraint->getPrettyString());
             } else {
                 $fallbackBranch = $this->getFallbackBranch($require);
                 if ($fallbackBranch !== false) {
                     $fallbackConstraint = new Constraint('=', $this->versionParser->normalize($fallbackBranch));
                     $fallbackConstraint->setPrettyString($fallbackBranch);
                     $requires[$key] = new Link($require->getSource(), $require->getTarget(), $fallbackConstraint, 'requires', $fallbackConstraint->getPrettyString());
                 }
             }
             $this->io->write('');
         }
         $package->setRequires($requires);
     }
 }
Esempio n. 10
0
 /**
  * Evaluates the expression: $version1 $operator $version2.
  *
  * @param string $version1
  * @param string $operator
  * @param string $version2
  *
  * @return bool
  */
 public static function compare($version1, $operator, $version2)
 {
     $constraint = new Constraint($operator, $version2);
     return $constraint->matches(new Constraint('==', $version1));
 }