Zend_Acl:使用数据库进行持久化,序列化 acl 对象还是使用特殊模式更好?
我需要实现 Zend_Acl 组件。我在文档中读到 Zend_Acl 对象可以使用 PHP 的序列化函数进行序列化。我的应用程序将有很多角色、规则和资源。我需要创建一个后端来配置所有这些东西。
我的问题是:在这种情况下,序列化 ACL 对象更好,还是创建一个架构来将角色、规则和资源保存在三个不同的表中更好?我的猜测是第一个选项,因为 Zend_Acl 组件已经具有添加/删除规则的方法,它自己处理每种类型对象的继承,并且可以查询 ACL。但我想听听以前遇到过这种情况的人的意见,这样我就不会在没有询问的情况下做出重大错误:)
谢谢!
I need to implement the Zend_Acl component. I read in the docs that the Zend_Acl object can be serialized with the serialized function of PHP. My application will have lots of roles, rules and resources. And I need to create a backend to configure all this stuff.
My question is: In this case, is it better to serialize the ACL object, or it's better to create a schema to persist roles, rules and resources in three different tables? My guess is the first option, because the Zend_Acl component already has methods to add / remove rules, it handles itself the inheritance of each type of object and it has the possibility to query the ACL. But I would like to hear opinions from people who faced this situation before so I don't make a big mistake deciding without asking :)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无论它有多大或多复杂,您都需要首先创建模式,然后通过扩展类来实现
Zend_Acl
,重写allow()
和deny()< /code> 方法并将权限架构的 CRUD 放入其中,然后分别将调用传递给
parent::allow()
和parent::deny()
。构建 ACL 需要一些时间,但您可以使用
Zend_Cache
对其进行缓存。使用这种方法,您的 ACL 将与您的架构保持同步。You need to create the schema first no matter how big or complicated it gets, then implement
Zend_Acl
by extending the class, overrideallow()
anddeny()
methods and put your CRUD for the permission schema in them, and then pass the call toparent::allow()
andparent::deny()
, respectively.Building the ACL will take time, but you can cache it using
Zend_Cache
. Using this approach, your ACL will remain in sync with your schema.我认为这主要是哪个选项更适合您的需求的问题。
我认为主要考虑因素如下:
对于大型 ACL,拥有特定架构是更好的选择。这将使您能够轻松构建仅包含适用于您当前使用情况的特定规则的 ACL。这样您就可以限制 ACL 的大小,并获得更好的性能。
如果 ACL 较小,序列化通常会工作得很好。
如果您需要对 ACL 进行更复杂的更改,您可能还需要考虑为其使用特定架构。这样您将可以更轻松地查询所有规则并显示它们以供用户编辑。
(关于尺寸/性能部分:您可能只需分析并查看是否存在性能问题即可确定最佳选择)
I think this is mainly a question of which option is more suited to what you need.
The main considerations I think are as follows:
In the case of a large ACL, having a specific schema is a better option. This will allow you to easily construct the ACL of only the specific rules which apply to your current usage. This way you can limit the size of the ACL, and get better performance.
If have a small ACL, serialization will usually work quite well.
If you need to do more complicated changes to the ACL, you might also want to consider using a specific schema for it. This way you will have an easier time querying all the rules, and displaying them for the user to edit.
(Regarding the size / performance parts: You probably can just profile and see if you have performance issues to determine the best choice)