Example #1
0
 /**
  * @param string $constraint See {@link https://getcomposer.org/doc/articles/versions.md}
  * @param bool   $transform  if true, will transform the simple constraint (v1, 1.2, ...) in a constraint with an interval (^v1, ^1.2, ...)
  *
  * @return array ordered from the last release to the first
  */
 public function match($constraint, $transform = true)
 {
     if ($transform && preg_match('/^v?[0-9]+(\\.[0-9]+)*$/', $constraint)) {
         $constraint = '^' . $constraint;
     }
     return Semver::satisfiedBy($this->versions, $constraint);
 }
Example #2
0
 /** @inheritdoc */
 public function satisfiedBy($packageName, $versionContraint)
 {
     $versions = Semver::satisfiedBy($packageName, $versionContraint);
     // Unlike composer, we allow dependant packages to define stability
     // flags. Why? Because we can have multiple versions of the same
     // package. So if foo requires bar@dev & baz requires bar@beta this is
     // totally fine.
     if (preg_match("/dev/i", $versionContraint)) {
         return $versions;
     }
     if (preg_match("/alpha/i", $versionContraint)) {
         return $this->filterDev($versions);
     }
     if (preg_match("/beta/i", $versionContraint)) {
         return $this->filterAlpha($versions);
     }
     if (preg_match("/rc/i", $versionContraint)) {
         return $this->filterBeta($versions);
     }
     // If the version contraint does not define a stability
     // then we defer to our "root" minimum-stability setting.
     switch ($this->minimumStability) {
         case 'dev':
             return $versions;
         case 'alpha':
             return $this->filterDev($versions);
         case 'beta':
             return $this->filterAlpha($versions);
         case 'rc':
             return $this->filterBeta($versions);
         default:
             return $this->filterRc($versions);
     }
 }
Example #3
0
 /**
  * Resolves a Wordpress Version Contraint.
  *
  * This is a private helper method. It takes a semantic version contraint,
  * parsable by [Composer's Semver](https://github.com/composer/semver) and
  * resolves an actual wordpress version number.
  *
  * We use this page: http://wordpress.org/download/release-archive/
  * As an offical list of released versions.
  *
  * @param  string $versionContraint A semantic version contraint.
  * @return string 					A semantic version number.
  */
 private function wpResolveVersionNo($versionContraint)
 {
     // Remove a v at the start if it exists
     $versionContraint = str_replace('v', '', $versionContraint);
     // If the constraint it a single wildcard, lets just
     // return the latest stable release of wordpress.
     if ($versionContraint == '*') {
         $json = (new Http())->request('GET', self::$WP_VERSION_URL)->getBody();
         return json_decode($json, true)['offers'][0]['version'];
     }
     // Download the releases from the wordpress site.
     $html = (new Http())->request('GET', self::$WP_RELEASES_URL)->getBody();
     // Extract a list of download links, these contain the versions.
     preg_match_all("#><a href='https://wordpress\\.org/wordpress-[^>]+#", $html, $matches);
     // Filter the links to obtain a list of just versions
     $versions = Linq::from($matches[0])->select(function ($v) {
         return s::create($v);
     })->where(function ($v) {
         return $v->endsWith(".zip'");
     })->where(function ($v) {
         return !$v->contains('IIS');
     })->where(function ($v) {
         return !$v->contains('mu');
     })->select(function ($v) {
         return $v->between('wordpress-', '.zip');
     })->where(function ($v) {
         if ($v->contains('-')) {
             return preg_match("#.*-(dev|beta|alpha|rc).*#i", $v) === 1;
         }
         return true;
     })->toArray();
     // Let semver take over and work it's magic
     return (string) Semver::satisfiedBy($versions, $versionContraint)[0];
 }