2023-05-24 12:26:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Database\QueryException;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
use Visus\Cuid2\Cuid2;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
function general_error_handler(\Throwable $e, $that = null, $isJson = false)
|
|
|
|
{
|
|
|
|
try {
|
2023-05-30 13:52:17 +00:00
|
|
|
ray('ERROR OCCURED: ' . $e->getMessage());
|
2023-05-24 12:26:50 +00:00
|
|
|
if ($e instanceof QueryException) {
|
|
|
|
if ($e->errorInfo[0] === '23505') {
|
|
|
|
throw new \Exception('Duplicate entry found.', '23505');
|
|
|
|
} else if (count($e->errorInfo) === 4) {
|
|
|
|
throw new \Exception($e->errorInfo[3]);
|
|
|
|
} else {
|
|
|
|
throw new \Exception($e->errorInfo[2]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new \Exception($e->getMessage());
|
|
|
|
}
|
|
|
|
} catch (\Throwable $error) {
|
|
|
|
if ($that) {
|
|
|
|
return $that->emit('error', $error->getMessage());
|
|
|
|
} elseif ($isJson) {
|
|
|
|
return response()->json([
|
|
|
|
'code' => $error->getCode(),
|
|
|
|
'error' => $error->getMessage(),
|
|
|
|
]);
|
|
|
|
} else {
|
2023-05-30 13:52:17 +00:00
|
|
|
ray($error);
|
2023-05-24 12:26:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_parameters()
|
|
|
|
{
|
|
|
|
return Route::current()->parameters();
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_latest_version_of_coolify()
|
|
|
|
{
|
|
|
|
$response = Http::get('https://coolify-cdn.b-cdn.net/versions.json');
|
|
|
|
$versions = $response->json();
|
|
|
|
return data_get($versions, 'coolify.v4.version');
|
|
|
|
}
|
|
|
|
|
|
|
|
function generate_random_name()
|
|
|
|
{
|
|
|
|
$generator = \Nubs\RandomNameGenerator\All::create();
|
|
|
|
$cuid = new Cuid2(7);
|
|
|
|
return Str::kebab("{$generator->getName()}-{$cuid}");
|
|
|
|
}
|
2023-05-24 13:47:04 +00:00
|
|
|
function generate_application_name(string $git_repository, string $git_branch)
|
|
|
|
{
|
|
|
|
$cuid = new Cuid2(7);
|
|
|
|
return Str::kebab("{$git_repository}:{$git_branch}-{$cuid}");
|
|
|
|
}
|