Automattic\WooCommerce\Vendor\Detection

MobileDetect::version()publicWC 1.0

Check the version of the given property in the User-Agent. Will return a float number. (e.g. 2_0 will return 2.0, 4.3.1 will return 4.31)

Method of the class: MobileDetect{}

No Hooks.

Return

String|float|false. The version of the property we are trying to extract.

Usage

$MobileDetect = new MobileDetect();
$MobileDetect->version( $propertyName, $type );
$propertyName(string) (required)
The name of the property. See self::getProperties() array keys for all possible properties.
$type(string)
Either self::VERSION_TYPE_STRING to get a string value or self::VERSION_TYPE_FLOAT indicating a float value. This parameter is optional and defaults to self::VERSION_TYPE_STRING. Passing an invalid parameter will default to the type as well.
Default: self::VERSION_TYPE_STRING

MobileDetect::version() code WC 9.3.3

public function version(string $propertyName, string $type = self::VERSION_TYPE_STRING)
{
    if (empty($propertyName)) {
        return false;
    }

    if (!\is_string($this->userAgent)) {
        return false;
    }

    // set the $type to the default if we don't recognize the type
    if ($type !== self::VERSION_TYPE_STRING && $type !== self::VERSION_TYPE_FLOAT) {
        $type = self::VERSION_TYPE_STRING;
    }

    $properties = self::getProperties();

    // Check if the property exists in the properties array.
    if (true === isset($properties[$propertyName])) {
        // Prepare the pattern to be matched.
        // Make sure we always deal with an array (string is converted).
        $properties[$propertyName] = (array) $properties[$propertyName];

        foreach ($properties[$propertyName] as $propertyMatchString) {
            $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString);

            // Identify and extract the version.
            preg_match(sprintf('#%s#is', $propertyPattern), $this->userAgent, $match);

            if (false === empty($match[1])) {
                return ($type == self::VERSION_TYPE_FLOAT ? $this->prepareVersionNo($match[1]) : $match[1]);
            }
        }
    }

    return false;
}