|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace OPGG\LaravelEssentialsEntry\Console\Commands; |
| 4 | + |
| 5 | +use Illuminate\Console\Command; |
| 6 | +use Illuminate\Support\Facades\File; |
| 7 | +use Illuminate\Support\Facades\Config; |
| 8 | + |
| 9 | +class CleanLanguageFilesCommand extends Command |
| 10 | +{ |
| 11 | + /** |
| 12 | + * 명령어 시그니처 |
| 13 | + * |
| 14 | + * @var string |
| 15 | + */ |
| 16 | + protected $signature = 'lang:clean'; |
| 17 | + |
| 18 | + /** |
| 19 | + * 명령어 설명 |
| 20 | + * |
| 21 | + * @var string |
| 22 | + */ |
| 23 | + protected $description = '기본 언어를 제외한 모든 언어 파일 삭제'; |
| 24 | + |
| 25 | + /** |
| 26 | + * 명령어 실행 |
| 27 | + * |
| 28 | + * @return int |
| 29 | + */ |
| 30 | + public function handle() |
| 31 | + { |
| 32 | + // 기본 언어 가져오기 |
| 33 | + $defaultLang = Config::get('essentials-entry.language.default'); |
| 34 | + |
| 35 | + // 환경 변수에서 직접 가져오는 경우 처리 |
| 36 | + if (empty($defaultLang)) { |
| 37 | + $defaultLang = env('APP_LOCALE', 'en'); |
| 38 | + } |
| 39 | + |
| 40 | + $this->info("기본 언어: {$defaultLang}"); |
| 41 | + |
| 42 | + // 언어 디렉토리 경로 |
| 43 | + $langPath = base_path('lang'); |
| 44 | + |
| 45 | + // 언어 디렉토리가 없으면 생성 |
| 46 | + if (!File::exists($langPath)) { |
| 47 | + $this->warn("언어 디렉토리({$langPath})가 존재하지 않습니다."); |
| 48 | + return 0; |
| 49 | + } |
| 50 | + |
| 51 | + // 모든 언어 디렉토리 가져오기 |
| 52 | + $langDirs = File::directories($langPath); |
| 53 | + |
| 54 | + if (empty($langDirs)) { |
| 55 | + $this->info("언어 디렉토리가 비어있습니다."); |
| 56 | + return 0; |
| 57 | + } |
| 58 | + |
| 59 | + $deletedFiles = 0; |
| 60 | + |
| 61 | + foreach ($langDirs as $langDir) { |
| 62 | + $langCode = basename($langDir); |
| 63 | + |
| 64 | + // 기본 언어인 경우 건너뛰기 |
| 65 | + if ($langCode === $defaultLang) { |
| 66 | + $this->info("기본 언어({$langCode}) 디렉토리 유지"); |
| 67 | + continue; |
| 68 | + } |
| 69 | + |
| 70 | + // 해당 언어 디렉토리의 모든 PHP 파일 가져오기 |
| 71 | + $langFiles = File::glob("{$langDir}/*.php"); |
| 72 | + |
| 73 | + if (empty($langFiles)) { |
| 74 | + $this->info("{$langCode} 디렉토리에 PHP 파일이 없음"); |
| 75 | + continue; |
| 76 | + } |
| 77 | + |
| 78 | + // 해당 언어의 PHP 파일 삭제 |
| 79 | + foreach ($langFiles as $file) { |
| 80 | + File::delete($file); |
| 81 | + $deletedFiles++; |
| 82 | + $this->line("삭제됨: {$file}"); |
| 83 | + } |
| 84 | + |
| 85 | + $this->info("{$langCode} 디렉토리의 모든 PHP 파일 삭제 완료"); |
| 86 | + } |
| 87 | + |
| 88 | + $this->info("총 {$deletedFiles}개 파일 삭제 완료"); |
| 89 | + |
| 90 | + return 0; |
| 91 | + } |
| 92 | +} |
0 commit comments