Exemple #1
0
 /**
  * Matches actual version with preset version.
  *
  * @param string $actual
  * @param array $preset
  *
  * @return bool
  */
 private function matchVersion($actual, array $preset)
 {
     if (!$actual || !array_key_exists('version', $preset)) {
         return false;
     }
     return Semver::satisfies($actual, $preset['version']);
 }
Exemple #2
0
 /**
  * Return all versions that satisfy given constraints.
  *
  * @param array $versions
  * @param string $constraints
  *
  * @return array
  */
 public static function satisfiedBy(array $versions, $constraints)
 {
     $versions = array_filter($versions, function ($version) use($constraints) {
         return Semver::satisfies($version, $constraints);
     });
     return array_values($versions);
 }
Exemple #3
0
 private function matchAllVersionsViaSemver($composerVersion)
 {
     $matches = [];
     foreach ($this->tagsReleasesBranches as $ref) {
         $matching = $this->semver->satisfies($ref, $composerVersion);
         if ($matching) {
             $matches[] = $ref;
             break;
         }
     }
     return !empty($matches) ? $matches : false;
 }
Exemple #4
0
 public function testCheckRequire()
 {
     $rootJson = $this->getJsonFromFile($this->rootComposerJson);
     $rootRequires = array_merge($rootJson['require'], $rootJson['require-dev'], $rootJson['replace']);
     foreach (array_merge($this->jsonFiles) as $jsonFile) {
         $subJson = $this->getJsonFromFile($jsonFile);
         if (isset($subJson['require'])) {
             foreach ($subJson['require'] as $subRequireName => $subRequireVersion) {
                 static::assertArrayHasKey($subRequireName, $rootRequires);
                 // root require contains all of sub require package
                 if ($rootRequires[$subRequireName] === 'self.version') {
                     static::assertTrue(Semver::satisfies(Application::VERSION, $subRequireVersion));
                     // self.version version check
                 } else {
                     static::assertEquals($rootRequires[$subRequireName], $subRequireVersion);
                 }
             }
         }
     }
 }
Exemple #5
0
/**
 * Compare two version strings to get the named semantic version.
 *
 * @access public
 *
 * @param string $new_version
 * @param string $original_version
 * @return string $name 'major', 'minor', 'patch'
 */
function get_named_sem_ver($new_version, $original_version)
{
    if (!Comparator::greaterThan($new_version, $original_version)) {
        return '';
    }
    $parts = explode('-', $original_version);
    list($major, $minor, $patch) = explode('.', $parts[0]);
    if (Semver::satisfies($new_version, "{$major}.{$minor}.x")) {
        return 'patch';
    } else {
        if (Semver::satisfies($new_version, "{$major}.x.x")) {
            return 'minor';
        } else {
            return 'major';
        }
    }
}
 /**
  * @return array
  */
 public static function getCoverageFileProvider()
 {
     $version = 'CodeCoverage >4.0';
     $filenames = array('coverage-tests/runner_test.cov', 'coverage-tests/result_printer_test.cov');
     $coverageClass = 'SebastianBergmann\\CodeCoverage\\CodeCoverage';
     if (class_exists('PHP_CodeCoverage')) {
         $version = 'Legacy CodeCoverage';
         $filenames = array('coverage-tests/runner_test.cov4', 'coverage-tests/result_printer_test.cov4');
         $coverageClass = 'PHP_CodeCoverage';
         if (Semver::satisfies(static::getPhpUnitVersion(), '3.7.*')) {
             $version = 'PHPUnit 3.7';
             $filenames = array('coverage-tests/runner_test.cov3', 'coverage-tests/result_printer_test.cov3');
         }
     }
     return array($version => array('filenames' => $filenames, 'expected coverage class' => $coverageClass));
 }
Exemple #7
0
 public function processNotifications($notifications)
 {
     // Sort by date
     usort($notifications, function ($a, $b) {
         return strcmp($a->date, $b->date);
     });
     $notifications = array_reverse($notifications);
     // Make adminNicetimeFilter available
     require_once __DIR__ . '/../twig/AdminTwigExtension.php';
     $adminTwigExtension = new AdminTwigExtension();
     $filename = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT, true, true);
     $read_notifications = CompiledYamlFile::instance($filename)->content();
     $notifications_processed = [];
     foreach ($notifications as $key => $notification) {
         $is_valid = true;
         if (in_array($notification->id, $read_notifications)) {
             $notification->read = true;
         }
         if ($is_valid && isset($notification->permissions) && !$this->authorize($notification->permissions)) {
             $is_valid = false;
         }
         if ($is_valid && isset($notification->dependencies)) {
             foreach ($notification->dependencies as $dependency => $constraints) {
                 if ($dependency == 'grav') {
                     if (!Semver::satisfies(GRAV_VERSION, $constraints)) {
                         $is_valid = false;
                     }
                 } else {
                     $packages = array_merge($this->plugins()->toArray(), $this->themes()->toArray());
                     if (!isset($packages[$dependency])) {
                         $is_valid = false;
                     } else {
                         $version = $packages[$dependency]['version'];
                         if (!Semver::satisfies($version, $constraints)) {
                             $is_valid = false;
                         }
                     }
                 }
                 if (!$is_valid) {
                     break;
                 }
             }
         }
         if ($is_valid) {
             $notifications_processed[] = $notification;
         }
     }
     // Process notifications
     $notifications_processed = array_map(function ($notification) use($adminTwigExtension) {
         $notification->date = $adminTwigExtension->adminNicetimeFilter($notification->date);
         return $notification;
     }, $notifications_processed);
     return $notifications_processed;
 }
Exemple #8
0
 protected function getVersionStyle(PackageInterface $latestPackage, PackageInterface $package)
 {
     if ($latestPackage->getFullPrettyVersion() === $package->getFullPrettyVersion()) {
         // print green as it's up to date
         return 'info';
     }
     $constraint = $package->getVersion();
     if (0 !== strpos($constraint, 'dev-')) {
         $constraint = '^' . $constraint;
     }
     if ($latestPackage->getVersion() && Semver::satisfies($latestPackage->getVersion(), $constraint)) {
         // print red as it needs an immediate semver-compliant upgrade
         return 'highlight';
     }
     // print yellow as it needs an upgrade but has potential BC breaks so is not urgent
     return 'comment';
 }
Exemple #9
0
/**
 * Compare two version strings to get the named semantic version.
 *
 * @access public
 *
 * @param string $new_version
 * @param string $original_version
 * @return string $name 'major', 'minor', 'patch'
 */
function get_named_sem_ver($new_version, $original_version)
{
    if (!Comparator::greaterThan($new_version, $original_version)) {
        return '';
    }
    $parts = explode('-', $original_version);
    $bits = explode('.', $parts[0]);
    $major = $bits[0];
    if (isset($bits[1])) {
        $minor = $bits[1];
    }
    if (isset($bits[2])) {
        $patch = $bits[2];
    }
    if (!is_null($minor) && Semver::satisfies($new_version, "{$major}.{$minor}.x")) {
        return 'patch';
    } else {
        if (Semver::satisfies($new_version, "{$major}.x.x")) {
            return 'minor';
        } else {
            return 'major';
        }
    }
}
Exemple #10
0
 /**
  * Check if the extension is valid for loading, i.e has a class and is withing version constraints.
  *
  * @param Composer    $composer
  * @param string|null $class
  * @param string|null $constraint
  *
  * @return bool
  */
 private static function parseValid(Composer $composer, $class, $constraint)
 {
     if ($constraint === null) {
         return false;
     }
     $provides = $composer->getPackage()->getProvides();
     $boltVersion = isset($provides['bolt/bolt']) ? $provides['bolt/bolt'] : new Link('__root__', 'bolt/bolt', new Constraint('=', '0.0.0'));
     return $class && Semver::satisfies($boltVersion->getPrettyConstraint(), $constraint);
 }
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once __DIR__ . '/vendor/autoload.php';
use Composer\Semver\Semver;
// Available versions in the order we want to check.
$available_versions = [getenv('PHP70_VERSION'), getenv('PHP56_VERSION')];
if (count($argv) < 2) {
    die("Usage:\n" . $argv[0] . " filename\n");
}
$composer = json_decode(file_get_contents($argv[1]), true);
$php_version = '';
if (is_array($composer) && array_key_exists('require', $composer) && array_key_exists('php', $composer['require'])) {
    $constraints = $composer['require']['php'];
    foreach ($available_versions as $version) {
        if (Semver::satisfies($version, $constraints)) {
            // The first match wins, picking the highest version possible.
            $php_version = substr($version, 0, strrpos($version, '.'));
            break;
        }
    }
}
echo $php_version;
 /**
  * @return array
  */
 public static function getReporterProvider()
 {
     $version = 'CodeCoverage >4.0';
     $filenames = array('coverage-tests/runner_test.cov', 'coverage-tests/result_printer_test.cov');
     $reporterClass = 'ParaTest\\Coverage\\CoverageReporter';
     if (class_exists('\\PHP_CodeCoverage')) {
         $version = 'Legacy CodeCoverage';
         $filenames = array('coverage-tests/runner_test.cov4', 'coverage-tests/result_printer_test.cov4');
         $reporterClass = 'ParaTest\\Coverage\\CoverageReporterLegacy';
         if (Semver::satisfies(static::getPhpUnitVersion(), '3.7.*')) {
             $version = 'PHPUnit 3.7';
             $filenames = array('coverage-tests/runner_test.cov3', 'coverage-tests/result_printer_test.cov3');
         }
     }
     return array($version => array('filenames' => $filenames, 'expected reporter class' => $reporterClass));
 }