Re: Modular PHP
From: Terence (tk.lists_at_fastmail.fm)
Date: 03/16/04
- Next message: William Ahern: "Re: findfile?"
- Previous message: Steven C. Gallafent: "Re: Select query problem"
- Maybe in reply to: Henk Verhoeven: "Re: Modular PHP"
- Next in thread: Terence: "Re: Modular PHP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 16 Mar 2004 16:12:19 +1100
Hayden Kirk wrote:
> What im finding hard is the API
>
> Im use to Windows C++ Programming with API, this is much harded to do in
> PHP. How can I catch an event in PHP. Is there a way, like, if someone
> executes a function a module can pick that up and see what is happening,
> like in Windows?
>
> I have a basic outline of how I want to do this, but ill save you the time.
> I just can't get my head around making modules interact with my system that
> im going to design. I hope you get what I mean?
>
> Say if I print an invoice, I have an invoice module that someone else has
> created, can this pickup on that event?
>
> Thanks in advanced.
>
I'm doing some work on an opensource PHP framework which supports the
modularity you are speaking of. I haven't release the event-handling
component yet but if you are still interested, send me an email and I
will send you the source.
Everything is done with XML, so you will want to be familiar with XSLT
to use the framework (I detest proprietary templating systems).
Basically it listens for cirtain post(or other hash) variables that you
declare (these are the events) in an XML file which looks like so.
<?xml version="1.0" encoding="UTF-8"?>
<xao:RequestMap
xao:xmlns="http://xao-php.sourceforge.net/schema/xao_1-0.xsd">
<xao:RequestSet ReqName="GameTasks">
<xao:Request ReqValue="rounds" Handler="Handle_GT_rounds" />
<xao:Request ReqValue="edit" Handler="Handle_GT_edit" />
<xao:Request ReqValue="close" Handler="Handle_GT_close" />
<xao:Request ReqValue="players" Handler="Handle_GT_players" />
<xao:Request ReqValue="docs" Handler="Handle_GT_docs" />
<xao:Request ReqValue="add" Handler="Handle_GT_add" />
</xao:RequestSet>
</xao:RequestMap>
In the above example you might be delacring events for the variable
$_REQUEST["GameTasks"] but if you like, you could do
$arrRequests = $_POST;
or $arrRequests = $_REQUEST;
or $arrRequests = $_COOKIE;
or $arrRequests = $_POST["arrEvents"];
(where <select name="arrEvents[]" />)
It really doesn't matter where you get the hash from. The framework
checks the value of the "GameTasks" item (in this case) and then calls
the function itentified by the Handler attribute in the above XML,
passing the $arrRequests to it.
This is how it is called.
$objReqMap = new RequestMap("RequestMap.xml");
$objReqMap->ExecuteRequests(
new HandleGameEdit(...),
$arrRequests
);
In this case, the module would be the HandleGameEdit class which
contains methods named after those in the Handler attributes. Here's
what a module make look like...
class HandleGameEdit extends HandlerBase {
function HandleGameEdit(&$objHost) {
$this->HandlerBase($objHost);
}
function Handle_GE_update($arrReq) {
$this->objHost->objLgDb->UpdateGame(
$arrReq["game_id"],
$arrReq["title"],
$arrReq["start_ts"],
$arrReq["end_ts"],
$arrReq["summary"]
);
}
}
You could call ExecuteRequests multiple times, if you want to, with
different modules (object instances) which might implement an arbitary
selection of the declared event-handlers.
http://xao-php.sourceforge.net/
when it is finally released.
I admit that some poeple may find this complex, but then you wouldn't be
using the RequestMap feature unless you were writing a complex app!
It's also worth noting that all the XML parsing for the request map
config file is only done once, it then creates a cache file containing a
serialize()d version of the (internal) array generated by the request
map file. So performance is quite good.
To update the request map config file with new modules, simply edit it,
then delete the cache file. (I could probably do this automatically by
checking the timestamp but that's overhead for every single hit - I'm
still considdering it).
email me for the current source if you're keen.
- Next message: William Ahern: "Re: findfile?"
- Previous message: Steven C. Gallafent: "Re: Select query problem"
- Maybe in reply to: Henk Verhoeven: "Re: Modular PHP"
- Next in thread: Terence: "Re: Modular PHP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|