douwen4178 2013-02-24 22:01
浏览 51
已采纳

禁用命名空间使用是某些类/文件

I'm working on a plugin system for my CMS, inside my CMS I use namespaces a lot. What I would like to have is that the developers of the plugins don't have to use namespaces inside their plugin, because they can be very complicated for developers who doesn't have used namespaces before. The main problem with the namespaces is the events which can be registered. Right now, plugin developers have to load an Event class using use \events\Event;, and if they just import the class they are still not able to use new Event(); because it uses namespaces. What I would like to have is that they can just use new Event(); (The class itself would be autoloaded by the CMS's auto loader, so no include required).

So basically, I would like to have namespaces disabled in certain classes or files. So new \events\Event(); will just look like new Event(); without removing the namespace events; from the Event class.

I hope I explained it clear, I'm not the best in explaining this kind of stuff.

  • 写回答

3条回答 默认 最新

  • dsafq2131321 2013-02-24 22:07
    关注

    No. In other words, this won't work:

    namespace Foo {
        class Event {}
        include('plugin.php');   // plugin.php cannot just do new Event();
    }
    

    That shouldn't be a problem really, since your CMS's plugin development documentation should be clear about the namespace usage and plugin developers would simply need to write something like

    use Plugin\Namespace\Events\MyEventType;
    

    to refer to MyEventType without needing to qualify it. Surely that's not too much to ask of plugin authors?

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

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度