. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Elements; use Fisharebest\Webtrees\Tree; use Ramsey\Uuid\Exception\RandomSourceException; use Ramsey\Uuid\Uuid; use function dechex; use function hexdec; use function strtolower; use function strtoupper; use function strtr; use function substr; /** * UID fields */ class Uid extends AbstractElement { protected const MAXIMUM_LENGTH = 36; /** * Create a default value for this element. * * @param Tree $tree * * @return string */ public function default(Tree $tree): string { try { if ($tree->getPreference('GENERATE_UIDS') === '1') { return strtolower(Uuid::uuid4()->toString()); } } catch (RandomSourceException $ex) { } return ''; } }