Method to validate protocol version format.

Only allow 1.0, 1.1 and 2.

@param   string $version Version string to validate.

@return  boolean  Valid or not.
773964
public static function isValidProtocolVersion($version)
    {
        if (!is_string($version) || empty($version)) {
            return false;
        }

        return (bool) preg_match('#^(1\.[01]|2)$#', $version);
    }
1102762
public function setVersion($version)
    {

        if (!is_null($version) && (!preg_match("/^(([0-9]|[1-9][0-9]*)\\.([0-9]|[1-9][0-9]*)\\.([0-9]|[1-9][0-9]*)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?)?$/", $version))) {
            throw new \InvalidArgumentException("invalid value for $version when calling Stack., must conform to the pattern /^(([0-9]|[1-9][0-9]*)\\.([0-9]|[1-9][0-9]*)\\.([0-9]|[1-9][0-9]*)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?)?$/.");
        }

        $this->container['version'] = $version;

        return $this;
    }
203608
public function setVersion($version)
    {
        Assert::string($version, 'The module file version must be a string. Got: %s');
        Assert::regex($version, '~^\d\.\d$~', 'The module file version must have the format "<digit>.<digit>". Got: %s</digit>');

        $this->version = $version;
    }
1176472
public static function setSpecVersion($version)
  {
    if (!in_array($version, array('1.1', '1.2'))) {
      throw new InvalidArgumentException(sprintf('Version %s of the YAML specifications is not supported', $version));
    }

    self::$spec = $version;
  }
814130
public function setProtocolVersion($version)
	{
		if (!array_key_exists($version, self::$protocolVersionMap)) {
			throw new InvalidArgumentException(sprintf('The HTTP protkoll version %s is unknown', $version));			
		}

		$this->protocolVersion = $version;

		return $this;
	}
574618
public function useVersion(string $version)
    {
        if (! \array_key_exists($version, $this->supportedVersions)) {
            throw new InvalidArgumentException("API version [{$version}] is not supported.");
        }

        $this->defaultVersion = $version;

        return $this;
    }
1031298
public function setProtocolVersion($version)
    {
        if (!preg_match('/^\d(\.\d+)+$/', $version))
        {
            throw new InvalidArgumentException('Invalid protocol version: ' . $version);
        }
        $this->protocolVersion = $version;
        return $this;
    }
479
public function savePreviousVersion($version)
    {
        if (!is_numeric($version)) {
            return;
        }

        try {
            $this->setVersionNumber($version);
            $this->owner->write();
        } catch (Exception $e) {
            throw new ValidationException(new ValidationResult(
                false,
                "Could not replace file #{$this->owner->ID} with version #$version."
            ));
        }
    }
366227
protected function _getVersionType($version)
    {
        if (strtolower($version) == 'latest') {
            return 'latest';
        }

        $parts = explode('.', $version);
        $count = count($parts);
        if (1 == $count) {
            return 'major';
        }
        if (2 == $count) {
            return 'minor';
        }
        if (3 < $count) {
            throw new Zend_Loader_Exception('Invalid version string provided');
        }
        return 'specific';
    }
874241
protected function getUntilRegExp($version)
    {
        $version = str_pad($version, 3, '.0');

        return sprintf(
            '(?:[0-%d]\.[0-%d])|(?:[0-%d]\.\d)',
            $version[0],
            $version[2],
            0 > $version[0] - 1 ? 0 : $version[0] - 1
        );
    }
341543
public function selectVersion($version)
	{
		if ( ! in_array($version, $this->versions))
		{
			// not a value version
			return false;
		}

		$this->version = $version;

		return $this;
	}
737048
private function validateProtocol($version)
    {
        $valid = [
            '1.0' => true,
            '1.1' => true,
            '2.0' => true,
        ];

        if (!isset($valid[$version])) {
            throw new InvalidArgumentException('Invalid HTTP version. Must be one of: 1.0, 1.1, 2.0');
        }
    }
821412
public function containsVersionOfFile($file, $version)
    {
        $f = $this->findVersionOfFile($file, $version);
        return  $f != null;
    }
849190
public function setVersion(string $version)
    {
        if (Validation::isValidVersionRegex($version)) {
            $this->version = $version;
        } else {
            throw new CustomException('Malformed version');
        }
    }
260532
public static function validateVersion($requiredVersion, $composerVersion)
    {
        if (false === strpos($composerVersion, '@') && !version_compare($composerVersion, $requiredVersion, '>=')) {
            $msg = 'Foxy requires the Composer\'s minimum version "%s", current version is "%s"';

            throw new RuntimeException(sprintf($msg, $requiredVersion, $composerVersion));
        }
    }
255345
public function setVersion(string $version): bool
    {
        $supportedVersions = $this->getSupportedVersions();

        if (in_array($version, $supportedVersions, true)) {
            $this->_version = $version;

            return true;
        } else {
            throw new NotSupportedException("Version `$version` is not supported in " . __CLASS__ . "! Supported versions: " . implode(' - ', $supportedVersions));
        }
    }
1278369
public static function isValid ($version)
    {
        if (self::isDev($version)) {
            return true;
        } else {
            return (boolean) preg_match('/' . self::$validPattern . '/i', $version);
        }
    }