Browscap\Data\PropertyHolder::getPropertyType PHP Method

getPropertyType() public method

Get the type of a property
public getPropertyType ( string $propertyName ) : string
$propertyName string
return string
    public function getPropertyType($propertyName)
    {
        $stringProperties = ['Comment' => 1, 'Browser' => 1, 'Browser_Maker' => 1, 'Browser_Modus' => 1, 'Platform' => 1, 'Platform_Name' => 1, 'Platform_Description' => 1, 'Device_Name' => 1, 'Platform_Maker' => 1, 'Device_Code_Name' => 1, 'Device_Maker' => 1, 'Device_Brand_Name' => 1, 'RenderingEngine_Name' => 1, 'RenderingEngine_Description' => 1, 'RenderingEngine_Maker' => 1, 'Parent' => 1, 'PropertyName' => 1];
        if (isset($stringProperties[$propertyName])) {
            return self::TYPE_STRING;
        }
        $arrayProperties = ['Browser_Type' => 1, 'Device_Type' => 1, 'Device_Pointing_Method' => 1, 'Browser_Bits' => 1, 'Platform_Bits' => 1];
        if (isset($arrayProperties[$propertyName])) {
            return self::TYPE_IN_ARRAY;
        }
        $genericProperties = ['Platform_Version' => 1, 'RenderingEngine_Version' => 1];
        if (isset($genericProperties[$propertyName])) {
            return self::TYPE_GENERIC;
        }
        $numericProperties = ['Version' => 1, 'CssVersion' => 1, 'AolVersion' => 1, 'MajorVer' => 1, 'MinorVer' => 1];
        if (isset($numericProperties[$propertyName])) {
            return self::TYPE_NUMBER;
        }
        $booleanProperties = ['Alpha' => 1, 'Beta' => 1, 'Win16' => 1, 'Win32' => 1, 'Win64' => 1, 'Frames' => 1, 'IFrames' => 1, 'Tables' => 1, 'Cookies' => 1, 'BackgroundSounds' => 1, 'JavaScript' => 1, 'VBScript' => 1, 'JavaApplets' => 1, 'ActiveXControls' => 1, 'isMobileDevice' => 1, 'isTablet' => 1, 'isSyndicationReader' => 1, 'Crawler' => 1, 'MasterParent' => 1, 'LiteMode' => 1, 'isFake' => 1, 'isAnonymized' => 1, 'isModified' => 1];
        if (isset($booleanProperties[$propertyName])) {
            return self::TYPE_BOOLEAN;
        }
        throw new \InvalidArgumentException("Property {$propertyName} did not have a defined property type");
    }

Usage Example

Esempio n. 1
0
 /**
  * formats the name of a property
  *
  * @param string $value
  * @param string $property
  *
  * @return string
  */
 public function formatPropertyValue($value, $property)
 {
     $propertyHolder = new PropertyHolder();
     switch ($propertyHolder->getPropertyType($property)) {
         case PropertyHolder::TYPE_STRING:
             $valueOutput = json_encode(trim($value));
             break;
         case PropertyHolder::TYPE_BOOLEAN:
             if (true === $value || $value === 'true') {
                 $valueOutput = 'true';
             } elseif (false === $value || $value === 'false') {
                 $valueOutput = 'false';
             } else {
                 $valueOutput = '""';
             }
             break;
         case PropertyHolder::TYPE_IN_ARRAY:
             try {
                 $valueOutput = json_encode($propertyHolder->checkValueInArray($property, $value));
             } catch (\InvalidArgumentException $ex) {
                 $valueOutput = '""';
             }
             break;
         default:
             $valueOutput = json_encode($value);
             break;
     }
     if ('unknown' === $valueOutput || '"unknown"' === $valueOutput) {
         $valueOutput = '""';
     }
     return $valueOutput;
 }
All Usage Examples Of Browscap\Data\PropertyHolder::getPropertyType