src/Version/Macos.php
/**
     * returns the version of the operating system/platform
     *
     * @throws UnexpectedValueException
     */
returns the version of the operating system/platform
@throws UnexpectedValueException
returns the version of the operating system / platform @throws UnexpectedValueException
public function detectVersion(string $useragent): VersionInterface
    {
        $doMatch = preg_match('/\((?:build )?(?P<build>\d+[A-Z]\d+(?:[a-z])?)\)/i', $useragent, $matches);
        if ($doMatch) {
            try {
                $buildVersion = $this->macosBuild->getVersion($matches['build']);
            } catch (BuildException | NotFoundException $e) {
                $buildVersion = false;
            }
            if (false !== $buildVersion) {
                try {
                    return $this->versionFactory->set($buildVersion);
                } catch (NotNumericException $e) {
                    $this->logger->info($e);
                    return new NullVersion();
                }
            }
        }
        $doMatch = preg_match('/coremedia v\d+\.\d+\.\d+\.(?P<build>\d+[A-Z]\d+(?:[a-z])?)/i', $useragent, $matches);
        if ($doMatch) {
            try {
                $buildVersion = $this->macosBuild->getVersion($matches['build']);
            } catch (BuildException | NotFoundException $e) {
                $buildVersion = false;
            }
            if (false !== $buildVersion) {
                try {
                    return $this->versionFactory->set($buildVersion);
                } catch (NotNumericException $e) {
                    $this->logger->info($e);
                    return new NullVersion();
                }
            }
        }
        if (false !== mb_stripos($useragent, 'darwin')) {
            foreach (self::DARWIN_MAP as $rule => $version) {
                if (!preg_match($rule, $useragent)) {
                    continue;
                }
                try {
                    return $this->versionFactory->set($version);
                } catch (NotNumericException $e) {
                    $this->logger->info($e);
                    return new NullVersion();
                }
            }
        }
        $searches = ['Mac OS X Version', 'Mac OS X v', 'Mac OS X', 'OS X', 'os=mac '];
        try {
            $detectedVersion = $this->versionFactory->detectVersion(str_replace(',', '.', $useragent), $searches);
        } catch (NotNumericException $e) {
            $this->logger->info($e);
            return new NullVersion();
        }
        if (null !== $detectedVersion->getVersion(VersionInterface::IGNORE_MINOR) && preg_match('/(?P<major>\d{2})(?P<minor>\d{2})(?P<micro>\d)/', $detectedVersion->getVersion(VersionInterface::IGNORE_MINOR), $versions)) {
            try {
                return $this->versionFactory->set($versions['major'] . '.' . $versions['minor'] . '.' . $versions['micro']);
            } catch (NotNumericException $e) {
                $this->logger->info($e);
                return new NullVersion();
            }
        }
        if (null !== $detectedVersion->getVersion(VersionInterface::IGNORE_MINOR) && preg_match('/(?P<major>\d{2})(?P<minor>\d)(?P<micro>\d)?/', $detectedVersion->getVersion(VersionInterface::IGNORE_MINOR), $versions)) {
            $version = $versions['major'] . '.' . $versions['minor'];
            if (array_key_exists('micro', $versions)) {
                $version .= '.' . $versions['micro'];
            }
            try {
                return $this->versionFactory->set($version);
            } catch (NotNumericException $e) {
                $this->logger->info($e);
                return new NullVersion();
            }
        }
        return $detectedVersion;
    }
public function detectVersion ( string $ useragent ) : VersionInterface { $ doMatch = preg_match ( '/\((?:build )?(?P<build>\d+[A-Z]\d+(?:[a-z])?)\)/i' , $ useragent , $ matches ) ; if ( $ doMatch ) { try { $ buildVersion = $ this -> macosBuild -> getVersion ( $ matches [ 'build' ] ) ; } catch ( BuildException | NotFoundException $ e ) { $ buildVersion = false ; } if ( false !== $ buildVersion ) { try { return $ this -> versionFactory -> set ( $ buildVersion ) ; } catch ( NotNumericException $ e ) { $ this -> logger -> info ( $ e ) ; return new NullVersion ( ) ; } } } $ doMatch = preg_match ( '/coremedia v\d+\.\d+\.\d+\.(?P<build>\d+[A-Z]\d+(?:[a-z])?)/i' , $ useragent , $ matches ) ; if ( $ doMatch ) { try { $ buildVersion = $ this -> macosBuild -> getVersion ( $ matches [ 'build' ] ) ; } catch ( BuildException | NotFoundException $ e ) { $ buildVersion = false ; } if ( false !== $ buildVersion ) { try { return $ this -> versionFactory -> set ( $ buildVersion ) ; } catch ( NotNumericException $ e ) { $ this -> logger -> info ( $ e ) ; return new NullVersion ( ) ; } } } if ( false !== mb_stripos ( $ useragent , 'darwin' ) ) { foreach ( self :: DARWIN_MAP as $ rule => $ version ) { if ( ! preg_match ( $ rule , $ useragent ) ) { continue ; } try { return $ this -> versionFactory -> set ( $ version ) ; } catch ( NotNumericException $ e ) { $ this -> logger -> info ( $ e ) ; return new NullVersion ( ) ; } } } $ searches = [ 'Mac OS X Version' , 'Mac OS X v' , 'Mac OS X' , 'OS X' , 'os=mac ' ] ; try { $ detectedVersion = $ this -> versionFactory -> detectVersion ( str_replace ( ',' , '.' , $ useragent ) , $ searches ) ; } catch ( NotNumericException $ e ) { $ this -> logger -> info ( $ e ) ; return new NullVersion ( ) ; } if ( null !== $ detectedVersion -> getVersion ( VersionInterface :: IGNORE_MINOR ) && preg_match ( '/(?P<major>\d{2})(?P<minor>\d{2})(?P<micro>\d)/' , $ detectedVersion -> getVersion ( VersionInterface :: IGNORE_MINOR ) , $ versions ) ) { try { return $ this -> versionFactory -> set ( $ versions [ 'major' ] . '.' . $ versions [ 'minor' ] . '.' . $ versions [ 'micro' ] ) ; } catch ( NotNumericException $ e ) { $ this -> logger -> info ( $ e ) ; return new NullVersion ( ) ; } } if ( null !== $ detectedVersion -> getVersion ( VersionInterface :: IGNORE_MINOR ) && preg_match ( '/(?P<major>\d{2})(?P<minor>\d)(?P<micro>\d)?/' , $ detectedVersion -> getVersion ( VersionInterface :: IGNORE_MINOR ) , $ versions ) ) { $ version = $ versions [ 'major' ] . '.' . $ versions [ 'minor' ] ; if ( array_key_exists ( 'micro' , $ versions ) ) { $ version .= '.' . $ versions [ 'micro' ] ; } try { return $ this -> versionFactory -> set ( $ version ) ; } catch ( NotNumericException $ e ) { $ this -> logger -> info ( $ e ) ; return new NullVersion ( ) ; } } return $ detectedVersion ; }
returns the version of the operating system/platform
 @throws UnexpectedValueException
returns the version of the operating system / platform @throws UnexpectedValueException