Garden\Schema::validateBoolean PHP Method

validateBoolean() protected method

Validate a boolean value.
protected validateBoolean ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
return boolean Returns true if {@link $value} is valid or false otherwise.
    protected function validateBoolean(&$value, array $field, Validation $validation)
    {
        if (is_bool($value)) {
            $validType = true;
        } else {
            $bools = ['0' => false, 'false' => false, 'no' => false, 'off' => false, '1' => true, 'true' => true, 'yes' => true, 'on' => true];
            if ((is_string($value) || is_numeric($value)) && isset($bools[$value])) {
                $value = $bools[$value];
                $validType = true;
            } else {
                $validType = false;
            }
        }
        return $validType;
    }