addOption('file','f', InputArgument::OPTIONAL, '只是针对那个文件'); } /** * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output): int { $file = $input->getOption('file'); $file = base_path()."/app/api/controller/ServerController.php"; $dir = new \RecursiveDirectoryIterator(base_path().'/app'); $iterator = new \RecursiveIteratorIterator($dir); $phpFiles = new \RegexIterator($iterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH); $fnlist = []; $result = [ 'common.php'=>"" ]; foreach ($phpFiles as $_file) { $_file = $_file[0]; $fnlist[] = $_file; $key = 'common.php'; if(false !==strpos($_file, base_path().'/app/api/controller')){ $key = 'api/'.pathinfo($_file,PATHINFO_BASENAME); } if(false !==strpos($_file, base_path().'/app/controller')){ $key = pathinfo($_file,PATHINFO_BASENAME); } $key = strtolower(str_replace('Controller','',$key)); //cp($key); $res = $this->parseOneFile($_file); $result[$key]=$res; } //$res = $this->parseOneFile($file); //cp($result); $this->write2file($result); return 0; } function write2file($data=[]){ $langs = ['zh-Hans','en']; foreach($data as $fn=>$arr){ foreach($langs as $lang){ $lang_path = base_path('/resource/translations/'.$lang.'/'); $_common_arr = require($lang_path.'common.php'); $_arr = []; if(file_exists($lang_path.$fn)){ $_arr = require($lang_path.$fn); } foreach($arr as $ov){ if(!isset($_common_arr[$ov]) && !isset($_arr[$ov])){ $_arr[$ov]=$ov; } if(isset($_common_arr[$ov]) && isset($_arr[$ov])){ unset($_arr[$ov]); } } file_put_contents($lang_path.$fn,'