doutangu4671 2011-03-08 18:53
浏览 34
已采纳

Magento控制器应该被宣布为FINAL吗?

In true Magento confusion there are two sets of controller classes; Those in the Controller directory and those in the controllers directory. The former have names like Mage_Adminhtml_Controller_Action and the latter are Mage_Adminhtml_IndexController. The latter are normally descendants of the former.

Because the latter don't cleanly map their names to their location in PEAR naming convention they don't get autoloaded by the normal autoloader, you cannot include them from your scripts since you cannot be certain which code pool they are in and it potentially breaks the compilation feature.

I feel because it's so hard to extend them they should be officially final and be done with it. Will this break anything I'm not thinking of? Is it bad practice somehow? Can anyone suggest better terms for describing the extendible classes and damn-hard-to-extend classes?

  • 写回答

2条回答 默认 最新

  • dongposhi8677 2011-03-08 20:28
    关注

    That would be awful.

    If you went back in time maybe you could make a case for declaring those controllers final to avoid the problems you're talking about, but introducing a change like that would significantly break a large number of Magento installations out in the wild. There's numerous cases where extending a base controllers for new store functionality (or even override/rewrite functionality) is the right move. Making them final now means you not only break applications, you break them in a way that's impossible to recover from.

    Even if you went back in time, I'm not sure your frustrations (although understandable) hold up as reasons

    No Autoloading

    This sounds like more of a case for fixing and/or adding an additional autoloader

    Cannot include them from your scripts since you cannot be certain which code pool they are in

    I'm not sure I follow the concern here. Including a base controller is as simple as

    require_once('Mage/Catalog/controllers/CategoryController.php');
    

    No, you're not certain which code pool they're in ... and that's fine. The point of code pools is they have fallback PHP include paths, allows users to use their own version of a particular class if need be without wrecking the core.

    Potentially breaks the compilation feature

    I'm not familiar with the problem being described here, but again, it sounds like more of a case to extend/fix the compiler's functionality

    Making controller classes as final to fix these problem would be like using a bazooka to handle a problem with house mice. The whole reason we have controller classes is so other URLs on our application can inherit functionality. Even if you don't believe in that for projects where you're the architect, taking that away after granting it is, at best, a bad move.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式