Horde_ActiveSync_Device::getMajorVersion PHP Method

getMajorVersion() public method

Return the major version number of the OS (or client app) as reported by the client.
public getMajorVersion ( ) : integer
return integer The version number.
    public function getMajorVersion()
    {
        switch (Horde_String::lower($this->clientType)) {
            case self::TYPE_BLACKBERRY:
                if (preg_match('/(.+)\\/(.+)/', $this->userAgent, $matches)) {
                    return $matches[2];
                }
                break;
            case self::TYPE_IPOD:
            case self::TYPE_IPAD:
            case self::TYPE_IPHONE:
                if (empty($this->_iOSVersion)) {
                    $this->_getIosVersion();
                }
                if (preg_match('/(\\d+)\\.(\\d+)/', $this->_iOSVersion, $matches)) {
                    return $matches[1];
                }
                break;
            case self::TYPE_ANDROID:
            case self::TYPE_NINE:
                // Most newer Android clients send self::OS, so check that first
                if (!empty($this->properties[self::OS]) && preg_match('/(\\d+)\\.(\\d+)/', $this->properties[self::OS], $matches)) {
                    return $matches[1];
                }
                // Some newer devices send userAgent like Android/4.3.3-EAS-1.3
                if (preg_match('/Android\\/(\\d+)\\.(\\d+)/', $this->userAgent, $matches)) {
                    return $matches[1];
                }
                // Older Android/0.3 type userAgent strings.
                if (preg_match('/(.+)\\/(\\d+)\\.(\\d+)/', $this->userAgent, $matches)) {
                    return $matches[2];
                }
                break;
            case self::TYPE_TOUCHDOWN:
                if (preg_match('/(.+)\\/(\\d+)\\.(\\d+)/', $this->userAgent, $matches)) {
                    return $matches[2];
                }
                break;
        }
        return 0;
    }

Usage Example

Exemplo n.º 1
0
 public function testDeviceGetMajorVersion()
 {
     $state = $this->getMockSkipConstructor('Horde_ActiveSync_State_Base');
     $fixture = array('deviceType' => 'iPod', 'userAgent' => 'Apple-iPod5C1/1102.55400001', 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 7.0.4'));
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $this->assertEquals(7, $device->getMajorVersion());
     $this->assertEquals(Horde_ActiveSync_Device::TYPE_IPOD, strtolower($device->deviceType));
     $this->assertEquals(Horde_ActiveSync_Device::MULTIPLEX_NOTES, $device->multiplex);
     $fixture = array('deviceType' => 'iPhone', 'userAgent' => 'iOS/6.1.3 (10B329)');
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $this->assertEquals(6, $device->getMajorVersion());
     $this->assertEquals(Horde_ActiveSync_Device::TYPE_IPHONE, strtolower($device->deviceType));
     $this->assertEquals(Horde_ActiveSync_Device::MULTIPLEX_NOTES, $device->multiplex);
     $fixture = array('userAgent' => 'Android/0.3', 'deviceType' => 'Android');
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $this->assertEquals(0, $device->getMajorVersion());
     $this->assertEquals(Horde_ActiveSync_Device::TYPE_ANDROID, strtolower($device->deviceType));
     $this->assertEquals(Horde_ActiveSync_Device::TYPE_ANDROID, strtolower($device->clientType));
     $this->assertEquals(Horde_ActiveSync_Device::MULTIPLEX_CONTACTS | Horde_ActiveSync_Device::MULTIPLEX_CALENDAR | Horde_ActiveSync_Device::MULTIPLEX_NOTES | Horde_ActiveSync_Device::MULTIPLEX_TASKS, $device->multiplex);
     $fixture = array('userAgent' => 'TouchDown(MSRPC)/7.1.0005', 'deviceType' => 'Android');
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $this->assertEquals(7, $device->getMajorVersion());
     $this->assertEquals(Horde_ActiveSync_Device::TYPE_ANDROID, strtolower($device->deviceType));
     $this->assertEquals(Horde_ActiveSync_Device::TYPE_TOUCHDOWN, strtolower($device->clientType));
     $this->assertEquals(0, $device->multiplex);
     $fixture = array('userAgent' => 'MOTOROLA-Droid(4D6F7869SAM)/2.1707', 'deviceType' => 'Android');
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $this->assertEquals(0, $device->getMajorVersion());
     $this->assertEquals(Horde_ActiveSync_Device::TYPE_ANDROID, strtolower($device->deviceType));
     $this->assertEquals(Horde_ActiveSync_Device::TYPE_UNKNOWN, strtolower($device->clientType));
     $this->assertEquals(0, $device->multiplex);
     // Devices like this (from a Note 3) we simply can't sniff multiplex for since there
     // is no version string. Stuff like this would go in the hook.
     $fixture = array('deviceType' => 'SAMSUNGSMN900V', 'userAgent' => 'SAMSUNG-SM-N900V/101.403', 'properties' => array(Horde_ActiveSync_Device::OS => 'Android'));
     $device = new Horde_ActiveSync_Device($state, $fixture);
     $this->assertEquals(0, $device->getMajorVersion());
     $this->assertEquals('samsungsmn900v', strtolower($device->deviceType));
     $this->assertEquals(Horde_ActiveSync_Device::TYPE_UNKNOWN, strtolower($device->clientType));
     $this->assertEquals(0, $device->multiplex);
 }
All Usage Examples Of Horde_ActiveSync_Device::getMajorVersion