Parse semantic version strings into major.minor.patch pieces.

@param string $version
@param string $prefix
@return array
774975
protected function parseVersion($version, $prefix)
    {
        $response = [];

        if (preg_match('%(?<major>\d+)((\.(?<minor>\d+)((\.(?<patch>\d+))|$))|$)%', $version, $match)) {
            $pieces = [];

            foreach ($match as $key => $value) {
                if ($key === 'major' || $key === 'minor' || $key === 'patch') {
                    $pieces[] = $response[$prefix . 'Version' . ucfirst($key)] = (int) $value;
                }
            }

            if ( ! empty($pieces)) {
                $response[$prefix . 'Version'] = implode('.', $pieces);
            }
        }

        return $response;
    }
1236495
public function resolve(string $namespace, string $version, string $name): string
    {
        $class = str_replace('.', '\\', $name);

        if (! array_key_exists($version, $this->supportedVersions)) {
            $version = $this->defaultVersion;
        }

        return sprintf('%s\%s\%s\%s', $namespace, $this->supportedVersions[$version], $class);
    }
1259804
public function parseVersions($versions)
    {
        $retValue = array();
        if (is_string($versions)) {
            $retValue[] = array($versions, '>=');
        } elseif (is_array($versions)) {
            foreach ($versions as $version) {
                if (is_string($version)) {
                    $retValue[] = array($version, '>=');
                } elseif (is_array($version)) {
                    $retValue[] = array($version[0], $version[1]);
                } else {
                    throw new \InvalidArgumentException('Invalid version. Needs to be a string or an array.');
                }
            }
        } else {
            throw new \InvalidArgumentException('Invalid version. Needs to be a string or an array.');
        }

        return $retValue;
    }
1019741
def tokenize_version(version_string: str) -> Tuple[int, int, int]:
    
    before_dash = version_string.split('-')[0]
    major, minor, patch = before_dash.split('.')[:3]  # take only the first 3 in case there's an extension like -dev.0
    return int(major), int(minor), int(patch)
359995
private function getVersionNumbers(array $versions): array
    {
        $versionNumbers = array_column($versions, 'versionNo');

        return array_combine($versionNumbers, array_fill_keys($versionNumbers, false));
    }
426896
private function handleVersions($versions)
    {
        foreach ($versions as $version => $info) {
            $announcement = $this->handleAnnouncement($version, $info);
            $date = $this->handleDate($info);

            $sources = [];

            foreach ($info['source'] as $source) {
                if (!isset($source['filename'])) {
                    continue;
                }

                foreach (['md5', 'sha256'] as $index) {
                    if (!isset($source[$index])) {
                        $source[$index] = null;
                    }
                }

                if (isset($source['date'])) {
                    unset($source['date']);
                }

                $sources[preg_replace('~.*\.~', '', $source['filename'])] = $source;
            }

            $versions[$version] = [
                'version' => $version,
                'aliases' => [],
                'announcement' => $announcement,
                'date' => date('Y-m-d', strtotime($date)),
                'source' => $sources,
                'museum' => isset($info['museum']) ? (boolean)$info['museum'] : false,
                'xdebug' => $this->getXdebugInfo($version),
                'gpg' => $this->getGpgInfo($version),
            ];
        }

        return $versions;
    }
1105073
public static function getSymfonyVersion($version)
    {
        return implode('.', \array_slice(array_map(static function ($val) {
            return (int) $val;
        }, explode('.', $version)), 0, 3));
    }
738282
public static function toVersion($version)
    {
        $components = self::toComponents($version);

        return new Version(
            $components['major'],
            $components['minor'],
            $components['patch'],
            $components['pre'],
            $components['build']
        );
    }
53195
private function getVersion($oldVersion)
    {
        preg_match('#^(?<PREFIX>v)?(?<MAJOR>\d+)?(?:\.(?<MINOR>\d+))?(?:\.(?<BUGFIX>\d+))?#', $oldVersion, $version);

        // Setting values if not captured
        $version['PREFIX'] = $version['PREFIX'] ?? '';
        $version[self::RELEASETYPE_MAJOR] = $version[self::RELEASETYPE_MAJOR] ?? '0';
        $version[self::RELEASETYPE_MINOR] = $version[self::RELEASETYPE_MINOR] ?? '0';
        $version[self::RELEASETYPE_BUGFIX] = $version[self::RELEASETYPE_BUGFIX] ?? '0';

        // Resetting Minor and/or Bugfix number according to release type
        switch ($this->releasetype) {
            case self::RELEASETYPE_MAJOR:
                $version[self::RELEASETYPE_MINOR] = '0';
            // no break
            case self::RELEASETYPE_MINOR:
                $version[self::RELEASETYPE_BUGFIX] = '0';
                break;
        }

        $version[$this->releasetype]++;

        return sprintf(
            '%s%u.%u.%u',
            $version['PREFIX'],
            $version[self::RELEASETYPE_MAJOR],
            $version[self::RELEASETYPE_MINOR],
            $version[self::RELEASETYPE_BUGFIX]
        );
    }
412352
protected function filterProtocolVersion($version)
    {
        if (!is_string($version) || !in_array($version, $this->protocols)) {
            throw new \InvalidArgumentException('The specified protocol is invalid.');
        }

        return $version;
    }
426932
public function getVersionParts(string $version) : array
    {
        $dots = explode('.', $version, 2);

        $majorVer = $dots[0];
        $minorVer = (isset($dots[1]) ? $dots[1] : '0');

        return [$majorVer, $minorVer];
    }
14394
protected static function splitUrlVersion($version)
    {
        $pos = strpos($version, '#');

        // number version or empty version
        if (false !== $pos) {
            $url = substr($version, 0, $pos);
            $version = substr($version, $pos);
        } else {
            $url = $version;
            $version = '#';
        }

        return array($url, $version);
    }
901150
def version_variants(version):
    """"""

    result = [version]

    # Add trailing ".0" as needed to ensure that we have at least
    # major.minor.patch
    parts = version.split(".")
    while len(parts) < 3:
        parts.append("0")
        result.append(".".join(parts))

    return result
834729
public static function toString(Version $version)
    {
        return sprintf(
            '%d.%d.%d%s%s',
            $version->getMajor(),
            $version->getMinor(),
            $version->getPatch(),
            $version->getPreRelease()
                ? '-' . join('.', $version->getPreRelease())
                : '',
            $version->getBuild()
                ? '+' . join('.', $version->getBuild())
                : ''
        );
    }
422570
public function asVersion($version) {
        $result = array();

        foreach (get_object_vars($this) as $property => $value) {
            //
            // skip properties that start with an underscore to allow
            // storing information that isn't included in statement
            // structure etc. (see Attachment.content for example)
            //
            if (strpos($property, '_') === 0) {
                continue;
            }

            if ($value instanceof VersionableInterface) {
                $value = $value->asVersion($version);
            }
            elseif (is_array($value) && !empty($value)) {
                $tmp_value = array();
                foreach ($value as $element) {
                    if ($element instanceof VersionableInterface) {
                        array_push($tmp_value, $element->asVersion($version));
                    }
                    else {
                        array_push($tmp_value, $element);
                    }
                }
                $value = $tmp_value;
            }

            if (isset($value) && (!is_array($value) || !empty($value))) {
                $result[$property] = $value;
            }
        }

        if (method_exists($this, '_asVersion')) {
            $this->_asVersion($result, $version);
        }

        return $result;
    }
632818
public function setVersion($version)
    {
        // Set version
        $this->version = $version;

        // Split version into major, minor and patch
        $version = explode('.', $version);
        if (count($version) == 1) {
            array_push($version, 0, 0);
        }

        // Set major, minor and patch version
        $this->majorVersion = (int) isset($version[0]) ? $version[0] : 0;
        $this->minorVersion = (int) isset($version[1]) ? $version[1] : 0;
        $this->patchVersion = (int) isset($version[2]) ? $version[2] : 0;

        return $this;
    }
856398
public function find_by_prefix($prefix) {
        $return = [];
        foreach ($this->find_all() as $key) {
            if (strpos($key, $prefix) === 0) {
                $return[] = $key;
            }
        }
        return $return;
    }