1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-10-28 04:42:29 +01:00
Pterodactyl-Panel/app/Services/Components/UuidService.php

64 lines
1.6 KiB
PHP
Raw Normal View History

<?php
2016-01-20 01:10:39 +01:00
/**
2016-01-20 22:05:16 +01:00
* Pterodactyl - Panel
2017-01-24 23:57:08 +01:00
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
2016-01-20 01:10:39 +01:00
*
2017-09-26 04:43:01 +02:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
2016-01-20 01:10:39 +01:00
*/
2016-12-07 23:46:38 +01:00
namespace Pterodactyl\Services\Components;
use DB;
use Uuid;
class UuidService
{
/**
* Generate a unique UUID validating against specified table and column.
2016-12-07 23:46:38 +01:00
* Defaults to `users.uuid`.
*
2017-08-22 05:10:48 +02:00
* @param string $table
* @param string $field
* @param int $type
* @return string
* @deprecated
*/
public function generate($table = 'users', $field = 'uuid', $type = 4)
{
$return = false;
do {
$uuid = Uuid::generate($type);
2016-12-07 23:46:38 +01:00
if (! DB::table($table)->where($field, $uuid)->exists()) {
$return = $uuid;
}
2016-12-07 23:46:38 +01:00
} while (! $return);
return (string) $return;
}
/**
* Generates a ShortUUID code which is 8 characters long and is used for identifying servers in the system.
*
2017-08-22 05:10:48 +02:00
* @param string $table
* @param string $field
* @param null|string $attachedUuid
* @return string
* @deprecated
*/
public function generateShort($table = 'servers', $field = 'uuidShort', $attachedUuid = null)
{
$return = false;
do {
$short = (is_null($attachedUuid)) ? substr(Uuid::generate(4), 0, 8) : substr($attachedUuid, 0, 8);
$attachedUuid = null;
2016-12-07 23:46:38 +01:00
if (! DB::table($table)->where($field, $short)->exists()) {
$return = $short;
}
2016-12-07 23:46:38 +01:00
} while (! $return);
return (string) $return;
}
}