JBZoo\Utils\Env::convert PHP Method

convert() public static method

Converts the type of values like "true", "false", "null" or "123".
public static convert ( string $value, integer $options = self::VAR_STRING ) : mixed
$value string
$options integer
return mixed
    public static function convert($value, $options = self::VAR_STRING)
    {
        $options = (int) $options;
        if ($options & self::VAR_STRING && !empty($value)) {
            return trim(Filter::stripQuotes($value));
        }
        if ($options & self::VAR_FLOAT) {
            return Filter::float($value, 12);
        }
        if ($options & self::VAR_INT) {
            return Filter::int($value);
        }
        if ($options & self::VAR_BOOL || $options & self::VAR_NULL) {
            if (null === $value || 'null' === strtolower(trim($value))) {
                return null;
            }
            return Filter::bool($value);
        }
        return (string) $value;
    }

Usage Example

Beispiel #1
0
 /**
  * @dataProvider dataProvider
  * @param mixed $value
  * @param int   $options
  * @param mixed $expected
  */
 public function testConvertOptions($value, $options, $expected)
 {
     isSame($expected, Env::convert($value, $options));
 }