forum-oauth-center/src/Utils.php
YUCLing a4b3a57e1d
add: serverside record models
chore: ui improvements
fix: login modal fail to show if not logged in
fix: cannot set null for nullable fields
2024-04-05 12:42:19 +08:00

40 lines
No EOL
1.2 KiB
PHP

<?php
namespace RhodesIsland\OAuthCenter;
use Illuminate\Support\Arr;
class Utils {
public const CLIENT_ATTRIBUTES = [
"client_id",
"client_secret",
"redirect_uri",
"client_name"
];
public const CLIENT_NULLABLE_ATTRIBUTES = [
"grant_types",
"scope",
"client_icon",
"client_desc",
"client_home"
];
public static function nullIfEmpty(string $value): string | null {
return $value == "" ? null : $value;
}
public static function processAttributes(array $attributes, array $requiredAttributes, array $nullableAttributes): array {
$result = [];
collect($requiredAttributes)->each(function (string $attribute) use (&$result, $attributes) {
if (($val = Arr::get($attributes, $attribute)) !== null) {
$result[$attribute] = $val;
}
});
collect($nullableAttributes)->each(function (string $attribute) use (&$result, $attributes) {
if (($val = Arr::get($attributes, $attribute)) !== null) {
$result[$attribute] = Utils::nullIfEmpty($val);
}
});
return $result;
}
}