dourukeng5302 2011-11-18 11:50
浏览 19
已采纳

在PHP中组织/使用可重用的代码库[关闭]

My goal is to write some reusable (OO) code for communicating with an external API, but as I'm not well versed in this kind of stuff in PHP, I'm not sure what is the best way to organize and load my code.

Stuff like limiting the amount of knowledge the client code needs to have about the libraries classes and making sure there are no naming collisions has led me to experiments with namespacing and avoiding having to inlude all the library files have led to experiments with autoloading, but I have so many questions on the subject that in stead of a lengthy process of trial and error, I thought I'd see if I anyone here possessed some wisdom on the subject.

So I guess my main questions are:

  • How to best encapsulate the library code, making it stand on it's own as much as possible.
  • How to best load/call this library code from the client code.

... but feel free to expand on whatever you think should be considered. :)

  • 写回答

2条回答 默认 最新

  • douhuan1905 2011-11-18 12:15
    关注

    The best way to go about it is simply to check how others do it Both Zend Framework and Symfony for instance will have a clear separation between these two. May not be a bad idea to borrow some concepts and make them your own.

    I tend to simply put my library code and 'client code' in separate namespaces.

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

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置