Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phar 模式不支持 glob 遍历目录。 #127

Open
zoujingli opened this issue Aug 30, 2024 · 3 comments
Open

Phar 模式不支持 glob 遍历目录。 #127

zoujingli opened this issue Aug 30, 2024 · 3 comments
Labels
bug Something isn't working stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed

Comments

@zoujingli
Copy link

$modules = glob(self::getAppPath() . '*');

可以尝试使用 DirectoryIterator 实现。

 $modules = [];
foreach (new \DirectoryIterator(self::getAppPath()) as $directory) {
    if ($directory->isDot()) {
        continue;
    }
    if ($directory->isDir()) {
        $modules[] = $directory->getPathname();
    }
}
@dosubot dosubot bot added the bug Something isn't working label Aug 30, 2024
@zds-s
Copy link
Member

zds-s commented Aug 30, 2024

2.0 新版已经不扫描了吧,如果要还扫描。就自己继承一下这个类。然后去 setting 里面改成你的类名

@zoujingli
Copy link
Author

zoujingli commented Aug 31, 2024

目前 MineAdmin 打包为 Phar,再打包为二进制包运行,只需要修改这两处代码。

  1. 关于 Ip2region 的路径计算,不使用 realpath 即可。
  2. Mine 类检测模块时使用了 glob 扫描目录,这里需要改为 DirectoryIterator 方式即可。

另外,我对 HttpCoreMiddleware 进行了部分修改,可以支持将编译好的前端代码打包到 Phar 包里面,即可实现一个二进制文件+.env 配置文件即可运行整个项目。对外看来就是一个完整的应用文件,不能直接看不出是 PHP 写的。

对于 HttpCoreMiddleware 的修改主要是因为没有抛出 NotFount 异常,在这里直接 JSON 返回了。

如果有需要,我可以提交 PR。

目前还有一个问题,就是 MineAdmin 打包 Phar 有点慢(应该说是 Hyperf 打包慢),后续有空还可以继续优化。

Copy link

dosubot bot commented Nov 30, 2024

Hi, @zoujingli. I'm Dosu, and I'm helping the components team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • The issue involves Phar mode not supporting directory traversal using glob.
  • You suggested using DirectoryIterator as an alternative.
  • @zds-s mentioned the new version does not scan and suggested class inheritance for scanning.
  • You provided code modification details and offered to submit a PR.
  • A performance issue with Phar packaging was noted, possibly related to Hyperf.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the components repository by commenting here.
  • If there is no further activity, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed
Projects
None yet
Development

No branches or pull requests

2 participants