Skip to content

Commit 735323b

Browse files
committed
优化对 Phar 的支持 top-think#3049
1 parent 2df402d commit 735323b

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

src/think/App.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class App extends Container
173173
*/
174174
public function __construct(string $rootPath = '')
175175
{
176-
$this->thinkPath = realpath(dirname(__DIR__)) . DIRECTORY_SEPARATOR;
176+
$this->thinkPath = dirname(__DIR__) . DIRECTORY_SEPARATOR;
177177
$this->rootPath = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $this->getDefaultRootPath();
178178
$this->appPath = $this->rootPath . 'app' . DIRECTORY_SEPARATOR;
179179
$this->runtimePath = $this->rootPath . 'runtime' . DIRECTORY_SEPARATOR;
@@ -538,14 +538,12 @@ protected function load(): void
538538

539539
$configPath = $this->getConfigPath();
540540

541-
$files = [];
542-
543541
if (is_dir($configPath)) {
544-
$files = glob($configPath . '*' . $this->configExt);
545-
}
542+
foreach (scandir($configPath) as $name) {
543+
if (!str_ends_with($name, $this->configExt) || !is_file($configPath . $name)) continue;
546544

547-
foreach ($files as $file) {
548-
$this->config->load($file, pathinfo($file, PATHINFO_FILENAME));
545+
$this->config->load($configPath . $name, pathinfo($name, PATHINFO_FILENAME));
546+
}
549547
}
550548

551549
if (is_file($appPath . 'event.php')) {

src/think/Http.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,10 @@ protected function loadRoutes(): void
229229
$routePath = $this->getRoutePath();
230230

231231
if (is_dir($routePath)) {
232-
$files = glob($routePath . '*.php');
233-
foreach ($files as $file) {
234-
include $file;
232+
foreach (scandir($routePath) as $name) {
233+
if (!str_ends_with($name, '.php') || !is_file($routePath . $name)) continue;
234+
235+
include $routePath . $name;
235236
}
236237
}
237238

src/think/Lang.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,22 @@ public function switchLangSet(string $langset)
137137
]);
138138

139139
// 加载系统语言包
140-
$files = glob($this->app->getAppPath() . 'lang' . DIRECTORY_SEPARATOR . $langset . '.*');
141-
$this->load($files);
140+
$appLangDir = $this->app->getAppPath() . 'lang' . DIRECTORY_SEPARATOR;
141+
if (is_dir($appLangDir)) {
142+
$files = [];
143+
144+
foreach (scandir($appLangDir) as $name) {
145+
$path = $appLangDir . $name;
146+
147+
if (!str_starts_with($name, $langset) || !is_file($path) || !in_array(pathinfo($name, PATHINFO_EXTENSION), ['php', 'yaml', 'json'])) {
148+
continue;
149+
}
150+
151+
$files[] = $path;
152+
}
153+
154+
$this->load($files);
155+
}
142156

143157
// 加载扩展(自定义)语言包
144158
$list = $this->app->config->get('lang.extend_list', []);

src/think/log/driver/File.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@ protected function getMasterLogFile(): string
135135
{
136136

137137
if ($this->config['max_files']) {
138-
$files = glob($this->config['path'] . '*.log');
138+
$files = [];
139+
foreach (scandir($this->config['path']) as $name) {
140+
if (!str_ends_with($name, '.log') || !is_file($this->config['path'] . $name)) continue;
141+
142+
$files[] = $this->config['path'] . $name;
143+
}
139144

140145
try {
141146
if (count($files) > $this->config['max_files']) {

0 commit comments

Comments
 (0)