<?php
// 로딩 전체에서 자동 로딩: app/Config/Autoload.php
// public $helpers = ['util'];
// BaseController에서:
// helper('util');

use App\Traits\UtilTrait;

if (!function_exists('alertTrait')) {
    function alertTrait(string $msg, $url = null): string
    {
        static $util = null;

        if ($util === null) {
            $util = new class {
                use UtilTrait;
            };
        }

        return $util->alertTrait($msg, $url);
    }
}

if (!function_exists('dev_exception')) {
    function dev_exception(string $message): RuntimeException
    {
        if (ENVIRONMENT === 'development') {
            $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
            $caller = $trace[1] ?? null;

            if ($caller) {
                $message = sprintf(
                    '%s->%s에서 오류발생: %s',
                    $caller['class'] ?? '',
                    $caller['function'] ?? '',
                    $message
                );
            }
        }

        return new RuntimeException($message);
    }
}

