59 lines
1.3 KiB
PHP
59 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Utils;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
class DataUtil
|
|
{
|
|
public static function isStringBoolean($string)
|
|
{
|
|
return !is_null($string) && !is_null(filter_var($string, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
|
|
}
|
|
|
|
public static function isStringTrue($string)
|
|
{
|
|
return !is_null($string) && filter_var($string, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === true;
|
|
}
|
|
|
|
public static function isStringFalse($string)
|
|
{
|
|
return !is_null($string) && filter_var($string, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === false;
|
|
}
|
|
|
|
public static function getBooleanValueFromStringBoolean($string)
|
|
{
|
|
return filter_var($string, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
|
}
|
|
|
|
public static function hasData(?array $data)
|
|
{
|
|
if (is_null($data)) {
|
|
|
|
return false;
|
|
}
|
|
|
|
foreach ($data as $item) {
|
|
|
|
if (isset($item)) {
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static function getSimOuNao(?bool $isTrue, bool $uppercase = false)
|
|
{
|
|
$response = $isTrue ? 'Sim' : 'Não';
|
|
|
|
if ($uppercase) {
|
|
|
|
$response = Str::upper($response);
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
}
|