mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 08:12:17 +01:00
Migrate permission away from Jetstream; Moved update user to REST API
This commit is contained in:
45
app/Support/Base64File.php
Normal file
45
app/Support/Base64File.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Symfony\Component\Mime\MimeTypes;
|
||||
|
||||
class Base64File
|
||||
{
|
||||
/**
|
||||
* @return array{data: string, mime_type: string}|null
|
||||
*/
|
||||
public static function decode(string $value): ?array
|
||||
{
|
||||
if (str_contains($value, ',')) {
|
||||
[, $value] = explode(',', $value, 2);
|
||||
}
|
||||
|
||||
$value = preg_replace('/\s+/', '', $value);
|
||||
if ($value === null || $value === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$decoded = base64_decode($value, true);
|
||||
if ($decoded === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$mimeType = (new \finfo(FILEINFO_MIME_TYPE))->buffer($decoded);
|
||||
if ($mimeType === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'data' => $decoded,
|
||||
'mime_type' => $mimeType,
|
||||
];
|
||||
}
|
||||
|
||||
public static function extension(string $mimeType): ?string
|
||||
{
|
||||
return MimeTypes::getDefault()->getExtensions($mimeType)[0] ?? null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user