Zend_Acl:使用数据库进行持久化,序列化 acl 对象还是使用特殊模式更好?

发布于 2024-10-09 14:57:37 字数 290 浏览 5 评论 0原文

我需要实现 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 技术交流群。

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

发布评论

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

评论(2

提笔落墨 2024-10-16 14:57:37

无论它有多大或多复杂,您都需要首先创建模式,然后通过扩展类来实现 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, override allow() and deny() methods and put your CRUD for the permission schema in them, and then pass the call to parent::allow() and parent::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.

爱的那么颓废 2024-10-16 14:57:37

我认为这主要是哪个选项更适合您的需求的问题。

我认为主要考虑因素如下:

  • ACL 大小:非常大的 ACL 序列化/反序列化可能不会很快,而且一般情况下工作速度可能会较慢。
  • ACL 修改:您是否需要能够对 ACL 执行更复杂的修改,而不仅仅是添加和删除规则?

对于大型 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:

  • ACL size: A very large ACL may not be very fast to serialize/unserialize, and it may work slower in general.
  • ACL modification: Do you need to be able to perform more complicated modifications to the ACL than just maybe adding and removing rules

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)

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