*/ function appLocales(): array { return config()->array('app.locales'); } /** * Get module */ function module(string $moduleName): ModuleContract { $moduleClass = 'App\\Modules\\'.$moduleName.'\\'.$moduleName.'Module'; if (class_exists($moduleClass)) { /** @var ModuleContract $module */ $module = new $moduleClass; return $module; } return emptyModule(); } /** * Empty module */ function emptyModule(): ModuleContract { return new EmptyModule; } /** * Modules directory path */ function modules_path(string $path = ''): string { return app_path('Modules/'.$path); } /** * Modules * * @return Collection */ function modules(bool $withDisabled = false): Collection { if (temp_cache()->has('modules')) { /** @var Collection $modules */ $modules = temp_cache('modules'); return $modules; } /** @var array */ $modulesDir = File::directories(modules_path()); $modules = collect(); foreach ($modulesDir as $modulePath) { $moduleName = Str::afterLast($modulePath, '/'); $module = new BaseModule( path: $modulePath, name: $moduleName, enabled: module($moduleName)->isEnabled() ); // Include all if ($withDisabled) { $modules->push($module); continue; } if ($module->enabled) { $modules->push($module); } } temp_cache()->put('modules', $modules); return $modules; } /** * Temprory cache for single request * * @return ($key is '' ? CacheRepository : mixed) */ function temp_cache(string $key = ''): mixed { $tempCache = cache()->driver('array'); return ($key === '') ? $tempCache : $tempCache->get($key); } /** * Log */ function logDB(): void { if (! app()->isLocal()) { return; } DB::listen(function ($query) { Log::info($query->sql, $query->bindings, $query->time); }); } /** * Get latest number */ function getLatestNumber(string $tableName = 'incoming_letters', string $column = 'number'): int { /** @var null|object{max_number: string} $data */ $data = DB::table($tableName)->select(DB::raw("MAX(CAST(REGEXP_REPLACE({$column}, '[^0-9]', '') AS UNSIGNED)) AS max_number"))->first(); return $data ? intval($data->max_number) : 0; } /** * Written format of money in turkmen */ function moneyFormatInTurkmenLetter(string $money): string { return TurkmenNumberFormatter::format(floatval($money)); }