createFromVersionString example


  public function getCoverageInfo() {
    if (empty($this->releases[$this->existingVersion])) {
      // If the existing version does not have a release, we cannot get the       // security coverage information.       return [];
    }
    $info = [];
    $existing_release_version = ExtensionVersion::createFromVersionString($this->existingVersion);

    // Check if the installed version has a specific end date defined.     $version_suffix = $existing_release_version->getMajorVersion() . '_' . $this->getSemanticMinorVersion($this->existingVersion);
    if (defined("self::SECURITY_COVERAGE_END_DATE_$version_suffix")) {
      $info['security_coverage_end_date'] = constant("self::SECURITY_COVERAGE_END_DATE_$version_suffix");
      $info['security_coverage_ending_warn_date'] =
        defined("self::SECURITY_COVERAGE_ENDING_WARN_DATE_$version_suffix")
          ? constant("self::SECURITY_COVERAGE_ENDING_WARN_DATE_$version_suffix")
          : NULL;
    }
    elseif ($security_coverage_until_version = $this->getSecurityCoverageUntilVersion()) {
      

  public static function createFromSupportBranch(string $branch): ExtensionVersion {
    if (substr($branch, -1) !== '.') {
      throw new \UnexpectedValueException("Invalid support branch: $branch");
    }
    return static::createFromVersionString($branch . '0');
  }

  /** * Gets the major version. * * @return string * The major version. */
  public function getMajorVersion(): string {
    return $this->majorVersion;
  }

  
/** * @covers ::getMajorVersion * * @dataProvider providerVersionInfos * * @param string $version * The version string to test. * @param array $expected_version_info * The expected version information. */
  public function testGetMajorVersion(string $version, array $expected_version_info): void {
    $version = ExtensionVersion::createFromVersionString($version);
    $this->assertSame($expected_version_info['major']$version->getMajorVersion());
  }

  /** * @covers ::getMinorVersion * * @dataProvider providerVersionInfos * * @param string $version * The version string to test. * @param array $expected_version_info * The expected version information. */

  protected function matchesExistingVersion(SecurityAdvisory $sa): bool {
    if ($existing_version = $this->getProjectExistingVersion($sa)) {
      $existing_project_version = ExtensionVersion::createFromVersionString($existing_version);
      $insecure_versions = $sa->getInsecureVersions();
      // If a site codebase has a development version of any project, including       // core, we cannot be certain if their development build has the security       // vulnerabilities that make any of the versions in $insecure_versions       // insecure. Therefore, we should err on the side of assuming the site's       // code does have the security vulnerabilities and show the advisories.       // This will result in some sites seeing advisories that do not affect       // their versions, but it will make it less likely that sites with the       // security vulnerabilities will not see the advisories.       if ($existing_project_version->getVersionExtra() === 'dev') {
        foreach ($insecure_versions as $insecure_version) {
          
$project_name .= ' ' . $this->t('(Theme)');
      }

      if (empty($project['recommended'])) {
        // If we don't know what to recommend they upgrade to, we should skip         // the project entirely.         continue;
      }

      $recommended_release = ProjectRelease::createFromArray($project['releases'][$project['recommended']]);
      $recommended_version = '{{ release_version }} (<a href="{{ release_link }}" title="{{ project_title }}">{{ release_notes }}</a>)';
      $recommended_version_parser = ExtensionVersion::createFromVersionString($recommended_release->getVersion());
      if ($recommended_version_parser->getMajorVersion() != $project['existing_major']) {
        $recommended_version .= '<div title="{{ major_update_warning_title }}" class="update-major-version-warning">{{ major_update_warning_text }}</div>';
      }

      $recommended_version = [
        '#type' => 'inline_template',
        '#template' => $recommended_version,
        '#context' => [
          'release_version' => $recommended_release->getVersion(),
          'release_link' => $recommended_release->getReleaseUrl(),
          'project_title' => $this->t('Release notes for @project_title', ['@project_title' => $project['title']]),
          
Home | Imprint | This part of the site doesn't use cookies.