BrowscapPHP\Data\PropertyFormatter::formatPropertyValue PHP Method

formatPropertyValue() public method

formats the name of a property
public formatPropertyValue ( string $value, string $property ) : string
$value string
$property string
return string
    public function formatPropertyValue($value, $property)
    {
        $valueOutput = $value;
        switch ($this->propertyHolder->getPropertyType($property)) {
            case PropertyHolder::TYPE_BOOLEAN:
                if (true === $value || $value === 'true' || $value === '1') {
                    $valueOutput = true;
                } elseif (false === $value || $value === 'false' || $value === '') {
                    $valueOutput = false;
                } else {
                    $valueOutput = '';
                }
                break;
            case PropertyHolder::TYPE_IN_ARRAY:
                try {
                    $valueOutput = $this->propertyHolder->checkValueInArray($property, $value);
                } catch (\InvalidArgumentException $ex) {
                    $valueOutput = '';
                }
                break;
            default:
                // nothing t do here
                break;
        }
        return $valueOutput;
    }

Usage Example

Example #1
0
 /**
  * Gets the relevant part (array of settings) of the ini file for a given pattern.
  *
  * @param  string $pattern
  * @return array
  */
 private function getIniPart($pattern)
 {
     $pattern = strtolower($pattern);
     $patternhash = Pattern::getHashForParts($pattern);
     $subkey = SubKey::getIniPartCacheSubKey($patternhash);
     if (!$this->cache->hasItem('browscap.iniparts.' . $subkey, true)) {
         $this->logger->debug('cache key "browscap.iniparts.' . $subkey . '" not found');
         return [];
     }
     $success = null;
     $file = $this->cache->getItem('browscap.iniparts.' . $subkey, true, $success);
     if (!$success) {
         $this->logger->debug('cache key "browscap.iniparts.' . $subkey . '" not found');
         return [];
     }
     if (!is_array($file) || !count($file)) {
         $this->logger->debug('cache key "browscap.iniparts.' . $subkey . '" was empty');
         return [];
     }
     $propertyFormatter = new PropertyFormatter(new PropertyHolder());
     $return = [];
     foreach ($file as $buffer) {
         list($tmpBuffer, $patterns) = explode("\t", $buffer, 2);
         if ($tmpBuffer === $patternhash) {
             $return = json_decode($patterns, true);
             foreach (array_keys($return) as $property) {
                 $return[$property] = $propertyFormatter->formatPropertyValue($return[$property], $property);
             }
             break;
         }
     }
     return $return;
 }
All Usage Examples Of BrowscapPHP\Data\PropertyFormatter::formatPropertyValue