Closed gt816 closed 2 years ago
vendor\overtrue\laravel-lang\src\Commands\Publish.php下的handle方法 删除或注释掉文件数组添加.json文件的相关代码 ` /**
@return mixed */ public function handle() { $locale = \strreplace('-', '', $this->argument('locales')); $force = $this->option('force') ? 'f' : 'n';
$sourcePath = base_path('vendor/laravel-lang/lang/locales'); $sourceJsonPath = base_path('vendor/laravel-lang/lang/locales'); $targetPath = base_path('resources/lang/'); if (!is_dir($targetPath) && !mkdir($targetPath)) { return $this->error('The lang path "resources/lang/" does not exist or not writable.'); } $files = []; $published = []; $copyEnFiles = false; $inLumen = $this->laravel instanceof \Laravel\Lumen\Application; if ('all' == $locale) { $files = [ \addslashes($sourcePath) . '/*', \addslashes($sourceJsonPath) . '/*/*.json', ]; $message = 'all'; $copyEnFiles = true; } else { foreach (explode(',', $locale) as $filename) { if ('en' === $locale) { $copyEnFiles = true; continue; } $trimFilename = trim($filename); $file = $sourcePath . '/' . $trimFilename; if (!file_exists($file)) { $this->error("'$filename' not found."); continue; } $published[] = $filename; $files[] = escapeshellarg($file); /*$jsonFile = $sourceJsonPath . "/{$trimFilename}/{$trimFilename}" . '.json'; if (!file_exists($jsonFile)) { $this->error("'$filename' not found."); continue; } $files[] = escapeshellarg($jsonFile);*/ } if (empty($files)) { return; } $message = json_encode($published); } if ($inLumen && $copyEnFiles) { $files[] = escapeshellarg(base_path('vendor/laravel/lumen-framework/resources/lang/en')); } array_map(function ($file) use ($targetPath) { $file = str_replace("\\", "/", $file); $targetPath = str_replace("\\", "/", $targetPath); $result = $this->cp($file, $targetPath); $this->info("copy {$file} to $targetPath result: " . json_encode($result)); }, $files); /*$files = implode(' ', $files); $targetPath = escapeshellarg($targetPath); $command = "cp -r{$force} {$files} {$targetPath}"; $process = \method_exists(Process::class, 'fromShellCommandline') ? Process::fromShellCommandline($command) : new Process($command); $process->run(function ($type, $buffer) { if (Process::ERR === $type) { return $this->error(trim($buffer)); } }); $type = ('f' == $force) ? 'overwrite' : 'no overwrite'; $this->info("published languages <comment>({$type})</comment>: {$message}.");*/
}
/* $param 来源文件夹或者文件$src $param 目的地 $des 返回值,true或者false / function cp($src, $des) { // 删除路径左右两侧的双引号 $src = rtrim(ltrim($src, "\""), "\""); // 清除文件状态缓存 clearstatcache($src); //假如是文件并且目的地不存在则创建目的地,并把文件放在目的地之下 if (is_file($src)) { var_dump($des . '/' . dirname($src)); //目的地不存在则创建目的地 if (!file_exists($des) && !is_dir($des)) { mkdir($des, 0777, true); } copy($src, $des . '/' . basename($src)); //假如是目录 } else if (is_dir($src)) { //目的地不存在则创建目的地 if (!file_exists($des) && !is_dir($des)) { mkdir($des, 0777, true); } //遍历目录下面的文件 foreach (glob($src . '/') as $f) { //假如目录下面的文件是目录则对它进行递归复制 if (is_dir($f)) { $this->cp($f, $des . '/' . basename($f)); } else { $baseDir = $des . '/' . basename($src); if (!file_exists($baseDir) && !is_dir($baseDir)) { mkdir($baseDir, 0777, true); } $to = $baseDir . '/' . basename($f); if (!file_exists($to)) { fopen($to, "w+"); } //文件则复制到目的地 copy($f, $to); } } } else { return false; } return true; }`
vendor\overtrue\laravel-lang\src\Commands\Publish.php下的handle方法 删除或注释掉文件数组添加.json文件的相关代码 ` /**
@return mixed */ public function handle() { $locale = \strreplace('-', '', $this->argument('locales')); $force = $this->option('force') ? 'f' : 'n';
}
/* $param 来源文件夹或者文件$src $param 目的地 $des 返回值,true或者false / function cp($src, $des) { // 删除路径左右两侧的双引号 $src = rtrim(ltrim($src, "\""), "\""); // 清除文件状态缓存 clearstatcache($src); //假如是文件并且目的地不存在则创建目的地,并把文件放在目的地之下 if (is_file($src)) { var_dump($des . '/' . dirname($src)); //目的地不存在则创建目的地 if (!file_exists($des) && !is_dir($des)) { mkdir($des, 0777, true); } copy($src, $des . '/' . basename($src)); //假如是目录 } else if (is_dir($src)) { //目的地不存在则创建目的地 if (!file_exists($des) && !is_dir($des)) { mkdir($des, 0777, true); } //遍历目录下面的文件 foreach (glob($src . '/') as $f) { //假如目录下面的文件是目录则对它进行递归复制 if (is_dir($f)) { $this->cp($f, $des . '/' . basename($f)); } else { $baseDir = $des . '/' . basename($src); if (!file_exists($baseDir) && !is_dir($baseDir)) { mkdir($baseDir, 0777, true); } $to = $baseDir . '/' . basename($f); if (!file_exists($to)) { fopen($to, "w+"); } //文件则复制到目的地 copy($f, $to); } } } else { return false; } return true; }`