src/POData/UriProcessor/RequestDescription.php
/**
     * Validates the given version in string format and returns the version as instance of Version
     * 
     * @param string $versionHeader The DataServiceVersion or MaxDataServiceVersion header value
     * @param string $headerName    The name of the header
     * 
     * @return Version
     * 
     * @throws ODataException If the version is malformed or not supported
     */
Validates the given version in string format and returns the version as instance of Version

@param string $versionHeader The DataServiceVersion or MaxDataServiceVersion header value
@param string $headerName    The name of the header

@return Version

@throws ODataException If the version is malformed or not supported
Validates the given version in string format and returns the version as instance of Version @param string $versionHeader The DataServiceVersion or MaxDataServiceVersion header value @param string $headerName The name of the header @return Version @throws ODataException If the version is malformed or not supported
private static function parseVersionHeader($versionHeader, $headerName)
    {
        $libName = null;
        $versionHeader = trim($versionHeader);
        $libNameIndex = strpos($versionHeader, ';');
        if ($libNameIndex !== false) {
            $libName = substr($versionHeader, $libNameIndex);
        } else {
            $libNameIndex = strlen($versionHeader);
        }
        $dotIndex = -1;
        for ($i = 0; $i < $libNameIndex; $i++) {
            if ($versionHeader[$i] == '.') {
	            if ($dotIndex != -1) {
					throw ODataException::createBadRequestError(
                        Messages::requestDescriptionInvalidVersionHeader(
                            $versionHeader,
                            $headerName
                        )
                    );
                }
                $dotIndex = $i;
            } else if ($versionHeader[$i] < '0' || $versionHeader[$i] > '9') {
				throw ODataException::createBadRequestError(
                    Messages::requestDescriptionInvalidVersionHeader(
                        $versionHeader,
                        $headerName
                    )
                );
            }
        }
	    $major = intval(substr($versionHeader, 0, $dotIndex));
	    $minor = 0;
        if ($dotIndex != -1) {
            if ($dotIndex == 0) {
				throw ODataException::createBadRequestError(
                    Messages::requestDescriptionInvalidVersionHeader(
                        $versionHeader,
                        $headerName
                    )
                );
            }
            $minor = intval(substr($versionHeader, $dotIndex + 1, $libNameIndex));
        }
        $version = new Version($major, $minor);
        return $version;
    }
private static function parseVersionHeader ( $ versionHeader , $ headerName ) { $ libName = null ; $ versionHeader = trim ( $ versionHeader ) ; $ libNameIndex = strpos ( $ versionHeader , ';' ) ; if ( $ libNameIndex !== false ) { $ libName = substr ( $ versionHeader , $ libNameIndex ) ; } else { $ libNameIndex = strlen ( $ versionHeader ) ; } $ dotIndex = - 1 ; for ( $ i = 0 ; $ i < $ libNameIndex ; $ i ++ ) { if ( $ versionHeader [ $ i ] == '.' ) { if ( $ dotIndex != - 1 ) { throw ODataException :: createBadRequestError ( Messages :: requestDescriptionInvalidVersionHeader ( $ versionHeader , $ headerName ) ) ; } $ dotIndex = $ i ; } else if ( $ versionHeader [ $ i ] < '0' || $ versionHeader [ $ i ] > '9' ) { throw ODataException :: createBadRequestError ( Messages :: requestDescriptionInvalidVersionHeader ( $ versionHeader , $ headerName ) ) ; } } $ major = intval ( substr ( $ versionHeader , 0 , $ dotIndex ) ) ; $ minor = 0 ; if ( $ dotIndex != - 1 ) { if ( $ dotIndex == 0 ) { throw ODataException :: createBadRequestError ( Messages :: requestDescriptionInvalidVersionHeader ( $ versionHeader , $ headerName ) ) ; } $ minor = intval ( substr ( $ versionHeader , $ dotIndex + 1 , $ libNameIndex ) ) ; } $ version = new Version ( $ major , $ minor ) ; return $ version ; }
Validates the given version in string format and returns the version as instance of Version
Validates the given version in string format and returns the version as instance of Version
//Throw an exception if we find more than 1 dot //Apparently the . is optional //If it starts with a ., throw an exception //TODO: move this somewhere... /*
        $isSupportedVersion = false;
        foreach (self::getKnownDataServiceVersions() as $version1) {
            if ($version->compare($version1) == 0) {
                $isSupportedVersion = true;
                break;
            }
        }

        if (!$isSupportedVersion) {
            $availableVersions = null;
            foreach (self::getKnownDataServiceVersions() as $version1) {
                $availableVersions .= $version1->toString() . ', ';
            }

            $availableVersions = rtrim($availableVersions, ', ');
            throw ODataException::createBadRequestError(
                Messages::requestDescriptionUnSupportedVersion(
                    $headerName,
                    $versionHeader,
	                $availableVersions
                )
            );
        }
	    */