App\Libraries\Str::isBoolean PHP Метод

isBoolean() публичный статический Метод

Evaluate the input string and returns true if it can be converted to a boolean.
public static isBoolean ( $str ) : boolean
$str
Результат boolean
    public static function isBoolean($str)
    {
        if (is_string($str)) {
            switch (strtolower($str)) {
                case '1':
                case 'true':
                case 'on':
                case 'yes':
                case 'y':
                    return true;
                case '0':
                case 'false':
                case 'off':
                case 'no':
                case 'n':
                    return true;
            }
        } else {
            return false;
        }
    }

Usage Example

 /**
  * Evaluate the input variable and if the string can be converted to either
  * a boolean, float or integer converts it and return that value.
  * Otherwise simply return the inout variable unchanged.
  *
  * @param $value
  * @return bool|float|int|misc
  */
 public static function correctType($value)
 {
     try {
         if (Str::isBoolean($value)) {
             $value = Str::toBoolean($value);
         } elseif (is_float($value)) {
             $value = floatval($value);
         } elseif (is_int($value)) {
             $value = intval($value);
         }
     } catch (Exception $ex) {
     }
     return $value;
 }