Documentation incorrect for handler arguments
coltrane - June 15, 2009 - 04:19
| Project: | REST Provider |
| Version: | 6.x-1.0-beta1 |
| Component: | Documentation |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
When a controller page arguments are specified they aren't passed alone as the README dictates. Instead they are merged with the default response data. The problem is the user-defined argument isn't correctly passed to the handler function, it appears to be lost.
Example service:
<?php
function urlshrink_menu() {
$items['shrink/%'] = array(
'title' => 'Shorten',
'type' => MENU_CALLBACK,
'page callback' => 'rest_provider_controller',
'page arguments' => array('urlshrink', 'controller', 1),
'access callback' => 'rest_provider_access',
);
return $items;
}
function urlshrink_controller_GET($args) {
return array(
'response_code' => '200', // OK
'headers' => array(),
'body' => print_r($args, TRUE),
'media_type' => 'text/plain',
'charset' => 'utf-8',
);
}
?>The response for shrink/foobar is
Array
(
[uri] => /d610/shrink/foobar
[method] => GET
[headers] => Array
(
[Host] => localhost
[User-Agent] => Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko/2008121621 Ubuntu/8.04 (hardy) Firefox/3.0.5
[Accept] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[Accept-Language] => en-us,en;q=0.5
[Accept-Encoding] => gzip,deflate
[Accept-Charset] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
[Keep-Alive] => 300
[Connection] => keep-alive
[Cookie] => xxx
[If-Modified-Since] => Mon, 15 Jun 2009 04:17:45 GMT
[Cache-Control] => max-age=0
)
[body] =>
)I'm not clear where my defined page argument is lost. It's available up to the call_user_func_array() in _rest_provider_invoke_handler_function().

#1
If I change from call_user_func_array() to variable function in
_rest_provider_invoke_handler_function()my argument is available at$args[1]:Array
(
[0] => Array
(
[uri] => /d610/shrink/foobar
[method] => GET
[headers] => Array
(
[Host] => localhost
[User-Agent] => Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko/2008121621 Ubuntu/8.04 (hardy) Firefox/3.0.5
[Accept] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[Accept-Language] => en-us,en;q=0.5
[Accept-Encoding] => gzip,deflate
[Accept-Charset] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
[Keep-Alive] => 300
[Connection] => keep-alive
[Cookie] => xxx
[If-Modified-Since] => Mon, 15 Jun 2009 04:21:13 GMT
[Cache-Control] => max-age=0
)
[body] =>
)
[1] => foobar
)
#2
Ah, the problem was my lack of understanding of call_user_func_array() and the incorrect README documentation ;). Additional page arguments must be specified on the function declaration.
<?phpfunction urlshrink_controller_GET($request, $url) {
return array(
'response_code' => '200', // OK
'headers' => array(),
'body' => $url,
'media_type' => 'text/plain',
'charset' => 'utf-8',
);
}
?>