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条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法