Browscap\Data\PropertyHolder::checkValueInArray PHP Method

checkValueInArray() public method

public checkValueInArray ( string $property, string $value ) : string
$property string
$value string
return string
    public function checkValueInArray($property, $value)
    {
        switch ($property) {
            case 'Browser_Type':
                $allowedValues = ['Useragent Anonymizer', 'Browser', 'Offline Browser', 'Multimedia Player', 'Library', 'Feed Reader', 'Email Client', 'Bot/Crawler', 'Application', 'Tool', 'unknown'];
                break;
            case 'Device_Type':
                $allowedValues = ['Console', 'TV Device', 'Tablet', 'Mobile Phone', 'Mobile Device', 'Desktop', 'Ebook Reader', 'Car Entertainment System', 'Digital Camera', 'unknown'];
                break;
            case 'Device_Pointing_Method':
                // This property is taken from http://www.scientiamobile.com/wurflCapability
                $allowedValues = ['joystick', 'stylus', 'touchscreen', 'clickwheel', 'trackpad', 'trackball', 'mouse', 'unknown'];
                break;
            case 'Browser_Bits':
            case 'Platform_Bits':
                $allowedValues = ['0', '8', '16', '32', '64'];
                break;
            default:
                throw new \InvalidArgumentException('Property "' . $property . '" is not defined to be validated');
        }
        if (in_array($value, $allowedValues)) {
            return $value;
        }
        throw new \InvalidArgumentException('invalid value given for Property "' . $property . '": given value "' . (string) $value . '", allowed: ' . json_encode($allowedValues));
    }

Usage Example

Example #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::checkValueInArray