
Originally Posted by
arborint
Here is a basic Handle class that I use. It is more generic than the WACT one for example as it is more like lastcraft's Invoker class.
Yeah, the class from WACT is lefthand work (Appoligies to the 10% out there). Yours looks fine, so let's stick with that. It's probably a good idea to name it ObjectHandle rather than Handle, since the latter could mean many things.

Originally Posted by
DougBTX
That strategy is basically to map a request to both a class and a function, right ? Using the class as the namespace for the functions.
That could be done by something like this :
PHP Code:
class RequestMapper_ActionPackMapper extends RequestMapper
{
function & mapRequest() {
if (isset($_GET['controller'])) {
$route = Array(
'controller' => $_GET['controller'],
'action' => isset($_GET['action']) ? $_GET['action'] : 'default'
);
return new Dispatcher_ActionPack($route);
}
}
}
class Dispatcher_ActionPack extends Dispatcher
{
var $route=Array();
function Dispatcher_ActionPack($route) {
$this->route = $route;
}
function execute() {
$controller = $this->route['controller'];
$action = $this->route['action'];
if (!class_exists($controller)) {
require_once($controller.'.php');
}
eval("$controller::pre_filters();");
eval("$controller::act_$action();");
eval("$controller::post_filters();");
}
}

Originally Posted by
DougBTX
OK, here's my hacking togetherness. I've taken out lots of return NULLs because that's what happens anyway.
Yeah, that's a bad habit I picked up doing some C-programming recently.

Originally Posted by
arborint
Please propose a Response class and we can incorporate it to set headers, cause a redirect, etc.
This is (almost) direct copy&paste from my working setup :
PHP Code:
class Response
{
var $headers=Array();
var $content="";
var $redirect=NULL;
function setHeader($key, $value=NULL) {
$this->headers[$key] = $value;
}
function getHeaders() {
return $this->headers;
}
function setRedirect($url) {
$this->redirect = $url;
}
function getRedirect() {
return $this->redirect;
}
function setContent($content) {
if (!is_null($this->redirect)) {
trigger_error("The response is set to redirect - content will not be preserved", E_USER_NOTICE);
}
$this->content = $content;
}
function getContent() {
return $this->content;
}
/**
* @returns void
*/
function execute() {
if (!is_null($this->redirect)) {
header("Location: ".$this->redirect);
exit;
}
foreach ($this->headers as $key => $value) {
if (is_null($value)) {
header($key);
} else {
// normalize headers ... not really needed
for ($tmp = explode("-", $key), $i=0, $l=count($tmp);$i<$l;$i++) {
$tmp[$i] = ucfirst($tmp[$i]);
}
header(implode("-", $tmp).": ".$value);
}
}
echo $this->content;
}
}

Originally Posted by
arborint
I think we should decide whether we want to support both dispatching actions and simply including PHP pages.
I'm confused? That's exactly what Dispatcher_ServerPage does.
Edit:
Or did you mean to discus whether we should dispose of it ?

Originally Posted by
arborint
How do we handle errors, such as the include file does not exist? At what level are these problems handled?
I think we better leave that out of scope. trigger_error() works fine to halt execution, and if people want a more subtle error-handler, they can probe into the native error-handler of php.
Bookmarks