代码点火器可扩展系统?
我正在为 Code Igniter 编写一个身份验证库(用于练习,因此请不要建议使用 Tank Auth 或 DX Auth)。
该库具有基本的登录功能,还具有 Facebook 和 Twitter 登录功能。
然而,Facebook 和 Twitter 登录代码被硬编码到库中。这意味着,如果我决定添加 Google Logins 等,我必须修改库的核心。我不喜欢这个。
我想知道如何使库可扩展,以便 Facebook 和 Twitter 登录成为可以添加的“模块”。
这样,有人也可以编写一个用于 Google 登录的模块,而无需修改系统的核心。
如何在代码点火器中创建可扩展库?
I am writing a authentication Library for Code Igniter (for practice, so please do not suggest e.g. Tank Auth or DX Auth).
The library has basic login functionality, it also has the ability for Facebook and Twitter Logins.
However the Facebook and Twitter login code is hard coded into the Library. Which means that if I decide to add in e.g. Google Logins I have to modify the core of the Library. I don't like this.
I am wondering what ways I could make the library extensible so that Facebook and Twitter logins are "Modules" that can be added.
In this way someone could write a module for Google logins as well and the core of the system would not have to be modified.
How can I make extensible libraries in code igniter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这听起来像是 codeigniter 中的驱动程序非常适合此任务。查看文档:http://codeigniter.com/user_guide/general/creating_drivers.html< /a>
This sounds like drivers in codeigniter is the right fit for this task. Take a look at the documentation : http://codeigniter.com/user_guide/general/creating_drivers.html
基本上你需要抽象类(查看http://nl2.php。 net/manual/en/language.oop5.abstract.php)
在这种特殊情况下,您可以编写如下内容;
- - 编辑
您可能对 kohana 如何处理此类扩展感兴趣,例如。 auth 模块有多个驱动程序。查看http://kohanaframework.org/3.2/guide/api/Auth,您可以从中学到很多东西!
Basically you'll need abstract classes (checkout http://nl2.php.net/manual/en/language.oop5.abstract.php)
In this particular case you would write something like this;
--- edit
you might be interested in how kohana handles this type of extension, eg. the auth module has several drivers. Checkout http://kohanaframework.org/3.2/guide/api/Auth, you can learn a lot from this!