Ms. Ramsey
2011 RESTful, Yahoo . REALLLLLLY , .
-, ( ) RESTful, ( ):
$action = 'action_' . filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING);
$params = filter_input(INPUT_GET, 'params', FILTER_SANITIZE_STRING);
if (function_exists($action))
{
$data = call_user_func_array($action, json_decode($params));
$output = json_encode($data);
echo $output;
}
else
{
trigger_error('Invalid action: ' . htmlspecialchars($action), E_USER_ERROR);
}
function action_foo($param1)
{
return "Param 1: $param1";
}
, , , , :
$ch = curl_init();
$params = json_encode(array('param1' => 'value', 'param2' => 'value'));
curl_setopt ($ch, CURLOPT_URL, 'http://site.com/restServer.php?action=foo¶ms=' . $params);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$data = json_decode($output);
.
, !