Created
February 28, 2010 02:06
-
-
Save dingram/317117 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function echoRequest(ReqtRequest $request) { | |
$resp = new RestResponseOk(array( | |
'url' => $url, | |
'verb' => $verb, | |
'headers' => $headers, | |
'args' => $get_args, | |
'body' => $body, | |
), $request); | |
$resp->render(); | |
return true; | |
} | |
function echoRequest2(RestRequest $request) { | |
$resp = new RestResponseOk(array( | |
'echoRequest' => array( | |
'url' => $url, | |
'verb' => $verb, | |
'headers' => $headers, | |
'args' => $get_args, | |
'body' => $body, | |
'matches' => $matches, | |
) | |
), $request); | |
$resp->render(); | |
return true; | |
} | |
function wink(RestRequest $request) { | |
$resp = new RestResponseOk(array( | |
'wink' => ';)', | |
), $request); | |
$resp->render(); | |
return true; | |
} | |
RestRequest::setBasePath('/rest-test'); | |
// handle GET requests to root with the echoRequest function | |
RestRequest::registerHandler('/', 'echoRequest'); | |
// handle GET and POST to /echo or anything under it with echoRequest2 | |
RestRequest::registerPatternHandler('^/echo(/.*)?$', 'echoRequest2', array('GET', 'POST')); | |
// easter egg for anyone using the non-standard WINK verb | |
RestRequest::registerPatternHandler('^/', 'wink', array('WINK')); | |
RestRequest::dispatchFromCurrent(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment