Files
unified-restaurant-original/backend/app/Services/UuidService.php
2021-06-16 03:40:12 -04:00

20 lines
473 B
PHP

<?php
namespace App\Services;
use Illuminate\Support\ServiceProvider;
use App\Exceptions\InvalidUuidException;
class UuidService extends ServiceProvider {
public function isValid(string $uuid) {
$regex = '/^[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}$/i';
return preg_match($regex, $uuid) === 1;
}
public function validOrFail(string $uuid) {
if(!$this->isValid($uuid)) {
throw new InvalidUuidException($uuid);
}
}
}