HTTPDispatcher::dispatch PHP Method

dispatch() public method

public dispatch ( $request )
    public function dispatch($request)
    {
        foreach ($this->rules as $rule) {
            //JAXLLogger::debug("matching $request->path with pattern $rule->pattern");
            if (($matches = $rule->match($request->path, $request->method)) !== false) {
                JAXLLogger::debug("matching rule found, dispatching");
                $params = array($request);
                // TODO: a bad way to restrict on 'pk', fix me for generalization
                if (isset($matches['pk'])) {
                    $params[] = $matches['pk'];
                }
                call_user_func_array($rule->cb, $params);
                return true;
            }
        }
        return false;
    }

Usage Example

Beispiel #1
0
*
* This is a modified BSD license (the third clause has been removed).
* The BSD license may be found here:
* 
* http://www.opensource.org/licenses/bsd-license.php
*
*/
// include heavy metal
include '../sys/sys.php';
// init the framework
init(dirname(dirname(__FILE__) . "..") . "/");
uses('sys.app.http.http_dispatcher');
uses('sys.app.config');
// load the environment
Config::LoadEnvironment();
// start buffering
ob_start();
// dispatch the request
try {
    $dispatcher = new HTTPDispatcher();
    print trim($dispatcher->dispatch());
} catch (DispatcherException $ex) {
    ob_end_clean();
    header('HTTP/1.0 404 Not Found');
} catch (ErrorResponseException $ex) {
    ob_end_clean();
    header('HTTP/1.0 ' . $ex->error_code());
}
Config::ShutdownEnvironment();
// flush the buffer
ob_flush();
All Usage Examples Of HTTPDispatcher::dispatch