在PHP中的插件架构 [英] Plugin Architecture in PHP

查看:112
本文介绍了在PHP中的插件架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算做关于如何实现PHP中的插件架构研究。我试图寻找可能的参考网页,但我想,也许我寻找一个很好的参考会更快,更相关的,如果我在这里问。

I am planning on doing a research on how to implement a plug-in architecture in PHP. I have tried searching the web for possible references, but I thought that maybe my search for a good reference would be faster and more relevant if I asked here.

在这里使用人尝试的插件架构对于Web项目?

Has anyone here tried using plug-in architecture for web projects?

谢谢,
欧文

推荐答案

我已经写了字preSS的插件,他们靠的就是变函数名称的魔力。例如,这是有效的PHP,在函数调用phpinfo()函数将被调用:

I have written wordpress plugins and the magic that they rely on is "Variable Function Names". For instance this is valid php, in which the function call phpinfo() will be called:

$func_name="phpinfo";
$func_name();

这可以让开发者钩子函数调用,如覆盖它们自己的功能,而无需更改应用程序的其余部分。 Linux内核模块都是关于挂钩,他们不会没有这种行为的工作。

This allows developer to "Hook" function calls, as in override them with their own functions without having change the rest of the application. Linux Kernel modules are all about "hooking", they wouldn't work without this behavior.

不幸的是,PHP变量函数名是一个恶心的黑客工具,消耗了大量的资源。在名称空间中的所有功能都放在一个列表和该列表具有要搜索虽然被称为功能之前,这是O(LOG2(正))。此外,还要注意该变量的函数名称不能被正确的街舞加速虽然code还是会转化成有效的C ++。更好的方法是重新申报功能,例如你可以在Python这将是O(1)复杂性,但PHP开发小组的不喜欢这个想法(是的,我问过此功能! )。

Unfortunately for PHP variable function names are a disgusting hack that consumes a lot of resources. All functions in a name space are put in a list and this list has to be searched though before the function is called, this is O(log2(n)). Also keep in mind that Variable Function Names can not be accelerated properly in HipHop although the code will still be transformed into valid C++. A better approach would be to re-declare functions like you can in python which would be O(1) complexity, but the PHP development team HATES this idea (Yes, I've asked for this feature!).

祝你好运!

这篇关于在PHP中的插件架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆