Zend Acl 的首选实现方法是什么
在 Zend Framework 1.X 中,以下哪种方法更好,为什么?
方法1:
创建一个扩展 Zend_Acl 的(子)类并用于管理所有 Acl。它将允许我们使用 $this 对象来使用所有 Zend_Acl 特性/函数。
方法2:
创建一个自定义类,其中包含 Zend_Acl 对象并对该对象执行操作。在这里,我们可以创建包装函数,并可以控制对 Zend_Acl 基本函数的访问,并且仅使用少数功能。
单例模式也可用于这两种方法,以确保在整个站点中使用相同的 Zend_Acl。
我将寻找一种稍后可以轻松移植到 ZF-2.0 的方法。如果有任何其他方法,请提及,我将相应地更新帖子。
更新: 除了单例之外,还有其他方法可以在整个站点中维护单个 Zend_Acl 对象吗?您如何看待使用带有 Approach-1 的单例以及使用自定义方法,这将为我们提供 Zend_Acl 的所有预定义方法以及自定义包装器。
In Zend Framework 1.X which of the following approaches is better and why?
Approach-1:
Create a (sub)Class extending Zend_Acl and use is to manage all the Acl. It will allow us to use all the Zend_Acl features/function using $this object.
Approach-2:
Create a Custom Class which holds Zend_Acl object and perform actions on the object. Here we can create wrapper functions and can control the access to Zend_Acl's base functions and use only a handful features.
Singleton pattern can be used for both approaches as well to make sure that throughout the site, same Zend_Acl is used.
I will looking for an approach which I can later port to ZF-2.0 easily. If there is any-other approach, please mention it and I will update the post accordingly.
Update: Are there any approaches other thn singleton to maintain single Zend_Acl object throughout the site? And what do you think about using a singleton with approach-1 and use custom methods as well, which will give us all the predefined methods of Zend_Acl along with our custom wrappers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此评论强烈支持方法 2,因为您的包装器充当 ACL 实现的适配器,并且您的应用程序仅与您的适配器交互,而不是直接与
Zend_Acl
交互。因此,您稍后可以将特定实现(即Zend_Acl
的组成)更改为另一个实现,无论是Zend\Acl
还是 Symfony 2 组件或者您自己编写的东西。This remark strongly favors approach 2, since your wrapper acts as an adapter to the ACL implementation, and your application interacts only with your adapter, not
Zend_Acl
directly. Thus you can later change the specific implementation (i.e. composition ofZend_Acl
) to another one, be itZend\Acl
or a Symfony 2 component or something you write yourself..在我的项目中,我使用模型来管理整个 ACL 系统(添加资源、添加角色等)。显然这个类扩展了 Zend_Acl。此外,我使用一个插件,该插件使用 preDispatch 方法来检查是否允许发出请求的用户访问请求的 url。
In my projects, I use a Model to manage the whole ACL system (add resources, add roles and so on). Obviously this class extends Zend_Acl. Moreover I use a plugin, that use a preDispatch method, to check if the user who made the request is allowed to access the requested url or not.