是否可以创建一个自安装的 PHP 框架?

发布于 2024-11-05 03:29:50 字数 562 浏览 0 评论 0原文

好吧,这可能看起来是一个坏主意,或者是一个显而易见的主意。但让我们想象一下像 PHPBB 这样的 CMS。让我们想象一下您会建造一个。我只创建 1 个名为 PHPBB.install.php 的文件,并运行它,它将创建 PHP 所需的所有文件夹和文件。我的意思是,用户只需运行一次,应用程序的每个文件和文件夹都是通过 PHP 文件创建的。

为什么要这样做?

主要是因为它更干净,并且您非常确定它会按照您的意愿创建所有内容(显然首先会检查有关服务器的所有内容)。另外,将所有文件备份在一个文件中,您可以通过删除所有内容并重新安装并再次运行 PHPBB.install.php 来轻松恢复它。像这样备份文件还可以防止错误:如何?当文件发生错误时,该文件将恢复原样并自动重新运行。

它太重了!

安装只会发生一次,并且您可以确保用户不会忘记正确放置文件。预防错误是值得的,而且它也只会发生一次。

现在的问题是:

  1. 这种技术存在吗?如果是这样,它的名字是什么?

  2. 你为什么要阻止它?

Ok this might seems a bad idea or an obvious one. But let's imagine a CMS like PHPBB. And let's imagine you'd build one. I'd create just 1 file called PHPBB.install.php and running it it will create all folders and files needed with PHP. I mean, the user run it just once and every file and folder of the app is created via the PHP file.

Why to do this?

Well mostly because it's cleaner and you are pretty much sure it creates everything as you wish (obliviously checking everything about the server first). Also, having all the files backed-up inside a file you would be able to restore it very easily by deleting everything and reinstalling it running again PHPBB.install.php. Backing-up files like this will allow you to also prevent errors: How? When an error occurred in a file, this file is restored as it was and automatically re-run.

It would be too heavy!

The installation would happen only once and you'd be sure the user will not forget to place the files correctly. The error-preventing will worth the cause and it would also happen only once.

Now the questions:

  1. Does this technique exists? If so, What's its name?

  2. Why would you discourage it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑梦风尘 2024-11-12 03:29:51
  1. 正如其他人所说,安装程序。

  2. 它要求 Web 服务器具有写入文件系统的权限,并最终拥有 Web 服务器运行的用户所拥有的文件。即使能够更改文件系统权限,这通常也是一个比提取存档并让初始设置验证权限更长的过程。

  1. As others have said, an installer.

  2. It requires the web server to have permission to write to the filesystem, and ends up having the files owned by the user the web server runs as. Even when one has the ability to change filesystem permissions, it's usually a longer process than just extracting an archive and having the initial setup verify permissions.

刘备忘录 2024-11-12 03:29:51

这种技术存在吗?如果是的话,它的名字是什么?

我建议阅读 __halt_compiler() 。它允许您将 PHP 代码与未解析的非 PHP 数据混合,因此您可以在单个 PHP 文件中拥有 PHP 代码(“安装程序”)和二进制数据(例如,所有文件的压缩内容)。

Does this technique exists? If so, What's its name?

I'd advise to read about __halt_compiler(). It allows you to mix PHP code with non-php data which is not parsed, so you may have PHP code ("installer") and binary data (e.g., compressed contents of all the files) in single PHP file.

随波逐流 2024-11-12 03:29:51

1 - 是的,PHPBB 中有一个安装文件。您可以通过在线向导来定义您的设置,然后它会自动安装。

http://www.phpbb.com/support/documents.php?mode=install&version=3&sid=908f5766fc04868ccb985c1b1e6dee4b#quickinstall

2 - 阻止它的唯一原因是您希望用户准确了解系统的工作原理。自动安装意味着用户无需了解其全部细节 - 当然,许多人认为这是一件好事。

1 - Yes, there is a single install file in PHPBB. You run through an online wizard defining your settings and then it installs automatically.

http://www.phpbb.com/support/documents.php?mode=install&version=3&sid=908f5766fc04868ccb985c1b1e6dee4b#quickinstall

2 - The only reason to discourage it would be if you want the user to understand exactly how the system works. Automatically installing it means the user has no need to understand the nitty gritty of it all - of course, many see this as a good thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文