This commit is contained in:
58
api/app/Utils/DataUtil.php
Normal file
58
api/app/Utils/DataUtil.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user