YUCLing
a4b3a57e1d
chore: ui improvements fix: login modal fail to show if not logged in fix: cannot set null for nullable fields
40 lines
No EOL
1.2 KiB
PHP
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;
|
|
}
|
|
} |