| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- namespace App\Module\Dev\Services;
- use App\Module\Dev\Enums\DEV_LOG_TYPE;
- use App\Module\Dev\Logics\DevLogic;
- use App\Module\Dev\Models\DevConfig;
- use Illuminate\Support\Facades\Cache;
- /**
- * 开发工具服务类
- *
- * 提供开发工具相关的服务方法,供其他模块调用
- */
- class DevService
- {
- /**
- * 获取开发工具列表
- *
- * @param array $params 查询参数
- * @return \Illuminate\Pagination\LengthAwarePaginator
- */
- public static function getDevTools(array $params = [])
- {
- return DevLogic::getDevTools($params);
- }
- /**
- * 获取开发工具详情
- *
- * @param int $id 开发工具ID
- * @return Dev|null
- */
- public static function getDevToolDetail(int $id): ?Dev
- {
- return Dev::find($id);
- }
- /**
- * 创建开发工具
- *
- * @param array $data 开发工具数据
- * @return Dev
- */
- public static function createDevTool(array $data): Dev
- {
- return DevLogic::createDevTool($data);
- }
- /**
- * 更新开发工具
- *
- * @param int $id 开发工具ID
- * @param array $data 开发工具数据
- * @return bool
- */
- public static function updateDevTool(int $id, array $data): bool
- {
- return DevLogic::updateDevTool($id, $data);
- }
- /**
- * 删除开发工具
- *
- * @param int $id 开发工具ID
- * @return bool
- */
- public static function deleteDevTool(int $id): bool
- {
- return DevLogic::deleteDevTool($id);
- }
- /**
- * 记录开发日志
- *
- * @param string $type 日志类型
- * @param string $content 日志内容
- * @param array $extraData 额外数据
- * @return DevLog
- */
- public static function log(string $type, string $content, array $extraData = []): DevLog
- {
- return DevLogic::log($type, $content, $extraData);
- }
- /**
- * 记录信息日志
- *
- * @param string $content 日志内容
- * @param array $extraData 额外数据
- * @return DevLog
- */
- public static function logInfo(string $content, array $extraData = []): DevLog
- {
- return self::log(DEV_LOG_TYPE::INFO->value, $content, $extraData);
- }
- /**
- * 记录警告日志
- *
- * @param string $content 日志内容
- * @param array $extraData 额外数据
- * @return DevLog
- */
- public static function logWarning(string $content, array $extraData = []): DevLog
- {
- return self::log(DEV_LOG_TYPE::WARNING->value, $content, $extraData);
- }
- /**
- * 记录错误日志
- *
- * @param string $content 日志内容
- * @param array $extraData 额外数据
- * @return DevLog
- */
- public static function logError(string $content, array $extraData = []): DevLog
- {
- return self::log(DEV_LOG_TYPE::ERROR->value, $content, $extraData);
- }
- /**
- * 记录调试日志
- *
- * @param string $content 日志内容
- * @param array $extraData 额外数据
- * @return DevLog
- */
- public static function logDebug(string $content, array $extraData = []): DevLog
- {
- return self::log(DEV_LOG_TYPE::DEBUG->value, $content, $extraData);
- }
- /**
- * 获取开发配置
- *
- * @param string $key 配置键
- * @param mixed $default 默认值
- * @return mixed
- */
- public static function getConfig(string $key, $default = null)
- {
- $cacheKey = 'dev_config_' . $key;
- return Cache::remember($cacheKey, 3600, function () use ($key, $default) {
- $config = DevConfig::where('key', $key)->first();
- return $config ? $config->value : $default;
- });
- }
- /**
- * 设置开发配置
- *
- * @param string $key 配置键
- * @param mixed $value 配置值
- * @param string $description 描述
- * @return DevConfig
- */
- public static function setConfig(string $key, $value, string $description = ''): DevConfig
- {
- $config = DevConfig::updateOrCreate(
- ['key' => $key],
- [
- 'value' => $value,
- 'description' => $description,
- 'status' => 1,
- ]
- );
- // 清除缓存
- Cache::forget('dev_config_' . $key);
- return $config;
- }
- /**
- * 获取所有开发配置
- *
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public static function getAllConfigs()
- {
- return DevConfig::all();
- }
- /**
- * 获取系统信息
- *
- * @return array
- */
- public static function getSystemInfo(): array
- {
- return [
- 'php_version' => PHP_VERSION,
- 'laravel_version' => app()->version(),
- 'server_software' => $_SERVER['SERVER_SOFTWARE'] ?? 'Unknown',
- 'server_os' => PHP_OS,
- 'database_connection' => config('database.default'),
- 'cache_driver' => config('cache.default'),
- 'session_driver' => config('session.driver'),
- 'queue_connection' => config('queue.default'),
- 'timezone' => config('app.timezone'),
- 'locale' => config('app.locale'),
- 'env' => config('app.env'),
- 'debug' => config('app.debug'),
- 'url' => config('app.url'),
- 'memory_limit' => ini_get('memory_limit'),
- 'max_execution_time' => ini_get('max_execution_time'),
- 'upload_max_filesize' => ini_get('upload_max_filesize'),
- 'post_max_size' => ini_get('post_max_size'),
- ];
- }
- }
|