如何在 Zend Framework 中合并少量 ACL?

发布于 2024-10-07 16:00:53 字数 1071 浏览 1 评论 0原文

我有几个 Zend_Acl 对象实例,例如这个(每个模块一个):

class My_Acl_Module1 extends My_Base_Acl
{
    public function __construct()
    {
        parent::__construct();
        $this->addResource('News_Model_Entry');
        $this->deny('guest', 'News_Model_Entry', 'index', new News_Model_Acl_Assert_CategoryPrivate());
    }       
}

class My_Base_Acl extends Zend_Acl 
{
    public function __construct()
    {
              $this->addRole('guest');
    }
}

How to merge them into one ACL object to use in navigation container?

编辑

更多信息:

  • 我不使用控制器资源,而是使用基于模型的资源(模型、表单实现 Zend_Acl_Resource_Interface)。它们都有方法 isAllowed()
  • 我使用模块化目录和可重用模块(单独的模型、配置、路由等)
  • 我的应用程序知道所有已安装的模块、控制器、操作(结构已解析,而不是实际的)时间)

所以我正在寻找遵循此方案的方法,并分离每个模块的 ACL。我不想使用应用程序资源,因为它是一种浪费 - acl 并不总是需要的。

我有一个操作助手,仅在真正需要时才实例化模块特定的 ACL。但有时我也希望全局应用程序 ACL 可用(例如,当我想将其传递给导航视图助手或控制器插件时)。

我的模块 ACL 类只有一个方法:init()
我看到的肮脏的解决方案是解析源类并将文件合并到新类的一种方法中。

有什么建议吗?

I have few instances of Zend_Acl objects, like this one (one for each module):

class My_Acl_Module1 extends My_Base_Acl
{
    public function __construct()
    {
        parent::__construct();
        $this->addResource('News_Model_Entry');
        $this->deny('guest', 'News_Model_Entry', 'index', new News_Model_Acl_Assert_CategoryPrivate());
    }       
}

class My_Base_Acl extends Zend_Acl 
{
    public function __construct()
    {
              $this->addRole('guest');
    }
}

How to merge them into one ACL object to use in navigation container?

Edit

Some more info:

  • I don't use controller resources in favor of model based resources (models, forms implement Zend_Acl_Resource_Interface). All of them have method isAllowed()
  • I use modular directory and reusable modules (separate models, configs, routes etc.)
  • My application knows all installed modules, controllers, action (structure already parsed, not in real time)

So I'm looking the way to follow this scheme, and separate the ACL for each module. I don't want to use application resource, because it is a waste - acl is not needed always.

I have an action helper which instantiates module specific ACL only when it is really needed. But sometimes I'd like to have global application ACL available too (eg. when I'd like to pass it to the navigation view helper or controller plugin).

My module ACL classes have all just one method: init().
Dirty solution I see, is to parse the source classes and merge the files into one method for new class.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

ˇ宁静的妩媚 2024-10-14 16:00:53

我认为如果应用程序不对其自身有更多的了解,这几乎是不可能的。不久前我也遇到了类似的问题,但没有找到令人满意的解决方案。合并时,您将丢失一些稍后在导航中需要的信息(模块)。

我在那里的第一个解决方案是迭代每个模块中的所有 acl 文件并创建一个自定义 ACL 合并函数来合并它们。这实际上确实有效,但我不喜欢对整个应用程序进行文件扫描的想法(即使结果已缓存)。

我的最后一个方法是向我的应用程序添加更多数据:对于每个可链接操作,我定义了相应的 acl 文件。这并不像听起来那么繁重。主要是因为我的控制器/模型几乎完全匹配。所以我有一个模型“新闻”和一个控制器“新闻”,它处理对其的访问并将模型的每个操作映射到前端。所以我只需要指定 acl/控制器关系。 (我在每个导航容器中使用自定义元素来保存它)。

I think this is almost impossible without the application knowing a bit more about itself. I had a similiar problem a while ago too and didn't find any satisfying solution. When merging you'll loose some information (the module) which you need later on in your navigation.

The first solution I had back there, was to iterate over all acl-files in each module and create a custom ACL-merge function to merge them all. This actually did work but I didn't like the idea of a file-scan over my complete application (even if the results were cached).

My last approach was to add more data to my application: For every linkable action I defined the corresponding acl-file. This wasn't as much work as it may sound. Mainly because my controllers/models do match almost exactly. So I have a model 'News' and a controller 'News' which handles the access to it and maps every action of the model to the frontend. So I only had to specify the acl/controller relations. (I used a custom element in each navigation container to save this).

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