Upgrade to 3.1.4

This commit is contained in:
Bastian Allgeier
2019-05-21 12:16:05 +02:00
parent 066913cb6e
commit 9e18cf635d
42 changed files with 215 additions and 109 deletions

View File

@@ -870,6 +870,36 @@ class Str
}, $string);
}
/**
* Convert the string to the given type
*
* @param string $string
* @param mixed $type
* @return mixed
*/
public static function toType($string = null, $type)
{
if (is_string($type) === false) {
$type = gettype($type);
}
switch ($type) {
case 'array':
return (array)$string;
case 'bool':
case 'boolean':
return filter_var($string, FILTER_VALIDATE_BOOLEAN);
case 'double':
case 'float':
return floatval($string);
case 'int':
case 'integer':
return intval($string);
}
return (string)$string;
}
/**
* Safe trim alternative
*