当前位置: 首页>>代码示例>>PHP>>正文


PHP Controller::buildResponse方法代码示例

本文整理汇总了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;
 }
开发者ID:kenwi,项目名称:core,代码行数:40,代码来源:dispatcher.php

示例2: testCustomFormatter

 public function testCustomFormatter()
 {
     $response = $this->controller->custom('hi');
     $response = $this->controller->buildResponse($response, 'json');
     $this->assertEquals(array(2), $response->getData());
 }
开发者ID:Romua1d,项目名称:core,代码行数:6,代码来源:ControllerTest.php


注:本文中的OCP\AppFramework\Controller::buildResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。