40 lines
1.2 KiB
PHP
40 lines
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;
|
||
|
}
|
||
|
}
|