Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Version.php

class Version

Same name in this branch
  1. 11.1.x vendor/phpunit/php-code-coverage/src/Version.php \SebastianBergmann\CodeCoverage\Version
  2. 11.1.x vendor/phpunit/phpunit/src/Runner/Version.php \PHPUnit\Runner\Version
  3. 11.1.x vendor/phar-io/version/src/Version.php \PharIo\Version\Version
  4. 11.1.x vendor/composer/composer/src/Composer/Platform/Version.php \Composer\Platform\Version
  5. 11.1.x vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Version.php \phpDocumentor\Reflection\DocBlock\Tags\Version

Hierarchy

  • class \SebastianBergmann\Version

Expanded class hierarchy of Version

3 files declare their use of Version
ExcludeList.php in vendor/phpunit/phpunit/src/Util/ExcludeList.php
Version.php in vendor/phpunit/php-code-coverage/src/Version.php
Version.php in vendor/phpunit/phpunit/src/Runner/Version.php
173 string references to 'Version'
announcements_feed.info.yml in core/modules/announcements_feed/announcements_feed.info.yml
core/modules/announcements_feed/announcements_feed.info.yml
announcements_feed.libraries.yml in core/modules/announcements_feed/announcements_feed.libraries.yml
core/modules/announcements_feed/announcements_feed.libraries.yml
ArchiveCommand::execute in vendor/composer/composer/src/Composer/Command/ArchiveCommand.php
Executes the current command.
AutoAddedKeysSniff::process in vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php
Processes this test, when one of its tokens is encountered.
automated_cron.info.yml in core/modules/automated_cron/automated_cron.info.yml
core/modules/automated_cron/automated_cron.info.yml

... See full list

File

vendor/sebastian/version/src/Version.php, line 23

Namespace

SebastianBergmann
View source
final class Version {
    private readonly string $version;
    public function __construct(string $release, string $path) {
        $this->version = $this->generate($release, $path);
    }
    public function asString() : string {
        return $this->version;
    }
    private function generate(string $release, string $path) : string {
        if (substr_count($release, '.') + 1 === 3) {
            $version = $release;
        }
        else {
            $version = $release . '-dev';
        }
        $git = $this->getGitInformation($path);
        if (!$git) {
            return $version;
        }
        if (substr_count($release, '.') + 1 === 3) {
            return $git;
        }
        $git = explode('-', $git);
        return $release . '-' . end($git);
    }
    private function getGitInformation(string $path) : bool|string {
        if (!is_dir($path . DIRECTORY_SEPARATOR . '.git')) {
            return false;
        }
        $process = proc_open('git describe --tags', [
            1 => [
                'pipe',
                'w',
            ],
            2 => [
                'pipe',
                'w',
            ],
        ], $pipes, $path);
        if (!is_resource($process)) {
            return false;
        }
        $result = trim(stream_get_contents($pipes[1]));
        fclose($pipes[1]);
        fclose($pipes[2]);
        $returnCode = proc_close($process);
        if ($returnCode !== 0) {
            return false;
        }
        return $result;
    }

}

Members

Title Sort descending Modifiers Object type Summary
Version::$version private property
Version::asString public function
Version::generate private function
Version::getGitInformation private function
Version::__construct public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal