本文整理汇总了PHP中OCP\AppFramework\Controller::buildResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::buildResponse方法的具体用法?PHP Controller::buildResponse怎么用?PHP Controller::buildResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\AppFramework\Controller
的用法示例。
在下文中一共展示了Controller::buildResponse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeController
/**
* Uses the reflected parameters, types and request parameters to execute
* the controller
* @param Controller $controller the controller to be executed
* @param string $methodName the method on the controller that should be executed
* @return Response
*/
private function executeController($controller, $methodName)
{
$arguments = array();
// valid types that will be casted
$types = array('int', 'integer', 'bool', 'boolean', 'float');
foreach ($this->reflector->getParameters() as $param => $default) {
// try to get the parameter from the request object and cast
// it to the type annotated in the @param annotation
$value = $this->request->getParam($param, $default);
$type = $this->reflector->getType($param);
// if this is submitted using GET or a POST form, 'false' should be
// converted to false
if (($type === 'bool' || $type === 'boolean') && $value === 'false' && ($this->request->method === 'GET' || strpos($this->request->getHeader('Content-Type'), 'application/x-www-form-urlencoded') !== false)) {
$value = false;
} elseif ($value !== null && in_array($type, $types)) {
settype($value, $type);
}
$arguments[] = $value;
}
$response = call_user_func_array(array($controller, $methodName), $arguments);
// format response
if ($response instanceof DataResponse || !$response instanceof Response) {
// get format from the url format or request format parameter
$format = $this->request->getParam('format');
// if none is given try the first Accept header
if ($format === null) {
$headers = $this->request->getHeader('Accept');
$format = $controller->getResponderByHTTPHeader($headers);
}
$response = $controller->buildResponse($response, $format);
}
return $response;
}
示例2: testCustomFormatter
public function testCustomFormatter()
{
$response = $this->controller->custom('hi');
$response = $this->controller->buildResponse($response, 'json');
$this->assertEquals(array(2), $response->getData());
}