可重用邮件客户端库的代码组织和设计
我现在很少有项目使用 PHP IMAP 扩展中的 imap_*
函数集。
任务是从邮件主机获取邮件并进行一些处理,并根据结果将它们存储在数据库中或回复邮件(即无效的任务请求格式)
使用imap_*
功能非常低-级别的任务,有很多重复的代码,所以我认为我应该实现一些统一的库来覆盖 imap 函数,并让我可以处理高级的、定义良好的类/接口/对象工厂等。
问题是我应该如何组织此任务的类/代码?我知道设计糟糕的库比没有库更糟糕:)
[编辑]
我最初的想法是创建 Transport
类来包装连接、隐藏邮箱私有属性内的句柄(imap_open
的结果),以及通过 __call
魔法使用 imap_*
函数。 第二个类是 AccessManager
,它将使用 Transport
类并负责邮件获取逻辑,也许还有第三个 Message
对象工厂?或者 Message
类应该有一些 ::createFromSomething()
静态初始值设定项?
I have now few projects that make use of imap_*
set of functions from PHP IMAP extension.
The task is to fetch mails from mailhost do some processing and based on results, store them in DB or reply to mail (in ie. invalid task request format)
Working with the imap_*
functions is a very low-level task, with a lot of repetitive code, so I get to the point that I should implement some unified lib that will cover the imap functions and let me work on a high-level, well defined classes / interfaces / object factories etc.
Question is how I should organize classes/code for this task? I know that badly designed library is worst than no library at all :)
[EDIT]
My initial idea was to create the Transport
class that will wrap the connection, hide the mailbox handle (result of imap_open
) inside the private property, and use of imap_*
functions via __call
magic.
Secod class would be the AccessManager
that will use Transport
class and take care of mail fetch logic, and mayby also third Message
object factory? Or Message
class should have some ::createFromSomething()
static initializer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将创建以下类:
I would create the following classes: