當前位置: 首頁>>代碼示例>>PHP>>正文


PHP JsonResponse::__construct方法代碼示例

本文整理匯總了PHP中Symfony\Component\HttpFoundation\JsonResponse::__construct方法的典型用法代碼示例。如果您正苦於以下問題:PHP JsonResponse::__construct方法的具體用法?PHP JsonResponse::__construct怎麽用?PHP JsonResponse::__construct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\HttpFoundation\JsonResponse的用法示例。


在下文中一共展示了JsonResponse::__construct方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * Construct the basic instance properties.
  *
  * @param mixed|null  $content              The response content {@see setFinalContent()}
  * @param int|null    $status               Status for this response.
  * @param array       $headers              Headers specific to this response.
  * @param array       $headersGlobal        The global headers configured.
  * @param array       $headersTypeSpecific  The type-specific headers configured.
  * @param string|null $charsetGlobal        The global charset configured.
  * @param string|null $charsetTypeSpecific  The type-specific charset configured.
  * @param float|null  $protocolGlobal       The global charset configured.
  * @param float|null  $protocolTypeSpecific The type-specific charset configured.
  *
  * @throws \InvalidArgumentException When the HTTP status code is not valid
  *
  * @api
  */
 public function __construct($content = null, $status = null, $headers = [], $headersGlobal = [], $headersTypeSpecific = [], $charsetGlobal = null, $charsetTypeSpecific = null, $protocolGlobal = null, $protocolTypeSpecific = null)
 {
     parent::__construct(null, $this->getFinalStatus($status), $this->getFinalHeaders($headersGlobal, $headersTypeSpecific, $headers));
     $this->setData($this->getFinalContent($content));
     $this->setCharset($this->getFinalCharset($charsetGlobal, $charsetTypeSpecific));
     $this->setProtocolVersion($this->getFinalProtocol($protocolGlobal, $protocolTypeSpecific));
 }
開發者ID:scr-be,項目名稱:mantle-bundle,代碼行數:24,代碼來源:JsonResponse.php

示例2: __construct

 /**
  * @see SymfonyHttpResponse::__construct
  */
 public function __construct($data = NULL, $status = 200, $headers = [])
 {
     parent::__construct($data, $status, $headers);
     $this->headers->set('Content-Type', JsonApiSpec::HATEOAS_CONTENT_TYPE);
     // Keeps the data NULL if NULL it is.
     $this->setData($data);
 }
開發者ID:mb3rnard,項目名稱:hateoas-bundle,代碼行數:10,代碼來源:JsonResponse.php

示例3: __construct

 /**
  * @param Response|null $response
  * @param int                   $status
  * @param array                 $headers
  */
 public function __construct(Response $response = null, $status = 200, $headers = array())
 {
     parent::__construct(null, $status, $headers);
     if ($response !== null) {
         $this->setResponse($response);
     }
 }
開發者ID:teqneers,項目名稱:ext-direct,代碼行數:12,代碼來源:UploadResponse.php

示例4: __construct

 /**
  * @param type $errorMessage
  * @param type $errorCode
  * @param type $status
  */
 public function __construct($errorMessage, $errorCode = 0, $status = HTTPCode::OK)
 {
     $data['success'] = false;
     $data['errorMessage'] = $errorMessage;
     $data['errorCode'] = $errorCode;
     return parent::__construct($data, $status);
 }
開發者ID:redefinelab,項目名稱:silexresponse,代碼行數:12,代碼來源:JsonErrorResponse.php

示例5: __construct

 /**
  * Constructor
  *
  * @param array $data
  * @param int $code
  * @param array $headers
  *
  * @return self
  */
 public function __construct(array $data = [], $code = 200, array $headers = [])
 {
     $data = [self::KEY_DATA => $data];
     parent::__construct($data, $code, $headers);
     $this->pristineData = $data;
     $this->resolveData();
     return $this;
 }
開發者ID:epfremmer,項目名稱:swagger-behat-demo,代碼行數:17,代碼來源:JsonResponse.php

示例6: __construct

 /**
  * Constructor.
  *
  * @param mixed $data The response data
  * @param int $status The response status code
  * @param array $headers An array of response headers
  */
 public function __construct($data = null, $status = 200, $headers = [])
 {
     parent::__construct('', $status, $headers);
     if (null === $data) {
         $data = new \ArrayObject();
     }
     $this->setContent($data);
 }
開發者ID:mediamonks,項目名稱:symfony-rest-api-bundle,代碼行數:15,代碼來源:JsonResponse.php

示例7: __construct

 public function __construct($data = array(), $successMessage = null, $status = HTTPCode::OK)
 {
     $data['success'] = true;
     if ($successMessage) {
         $data['successMessage'] = $successMessage;
     }
     return parent::__construct($data, $status);
 }
開發者ID:redefinelab,項目名稱:silexresponse,代碼行數:8,代碼來源:JsonSuccessResponse.php

示例8: __construct

 public function __construct($data = null, $status = 200, $headers = array())
 {
     if (null === $data) {
         $data = new \stdClass();
     }
     parent::__construct($data, $status, $headers);
     $this->rawData = $data;
 }
開發者ID:mat33470,項目名稱:PFA,代碼行數:8,代碼來源:JsonResponse.php

示例9: __construct

 public function __construct(ApiProblem $problem, $status = 200, $headers = array())
 {
     $headers += ['Content-Type' => 'application/problem+json'];
     if (null !== $problem->getStatus()) {
         $headers += ['X-Status-Code' => $problem->getStatus()];
     }
     $data = $problem->asArray();
     parent::__construct($data, $status, $headers);
 }
開發者ID:Axxon,項目名稱:udb3-silex,代碼行數:9,代碼來源:ApiProblemJsonResponse.php

示例10: __construct

 /**
  * @param string $message
  * @param int    $status
  * @param null   $logref
  * @param array  $headers
  */
 public function __construct($message, $status = self::DEFAULT_STATUS, $logref = null, $headers = [])
 {
     $data = ['message' => $message];
     if (null !== $logref) {
         $data['logref'] = $logref;
     }
     $headers = array_merge(['Content-Type' => 'application/vnd.error+json'], $headers);
     parent::__construct($data, $status, $headers);
 }
開發者ID:krizon,項目名稱:swagger-bundle,代碼行數:15,代碼來源:VndErrorResponse.php

示例11: __construct

 public function __construct($data, $alias, $route)
 {
     parent::__construct('', 200, array('Content-Type' => sprintf('application/%s+json', $alias), 'Link' => sprintf('<%s>; rel="describedBy"', $route)));
     // Add pretty printing to the default encoding options supplied by
     // symfony's JsonResponse
     if (isset($this->encodingOptions) && defined('JSON_PRETTY_PRINT')) {
         $this->encodingOptions = $this->encodingOptions | JSON_PRETTY_PRINT;
     }
     $this->setData($data);
 }
開發者ID:brayansdt,項目名稱:KnpJsonSchemaBundle,代碼行數:10,代碼來源:JsonSchemaResponse.php

示例12: __construct

 public function __construct($success = FALSE, $data = NULL, $statusCode = 200, array $headers = [])
 {
     $resultData = function ($data, $default = []) {
         return empty($data) ? $default : (array) $data;
     };
     $json['success'] = (bool) $success;
     if (is_array($data) and array_key_exists('result', $data)) {
         $json += $resultData($data);
     } else {
         $json['result'] = $resultData($data);
     }
     parent::__construct($json, (int) $statusCode, $headers);
 }
開發者ID:otar,項目名稱:restly-friendly,代碼行數:13,代碼來源:Response.php

示例13: __construct

 public function __construct(ValidationError $validationErrorException)
 {
     $violations = $validationErrorException->getViolations();
     $errors = [];
     /** @var ConstraintViolationInterface $violation */
     foreach ($violations as $violation) {
         $errors[$violation->getPropertyPath()][] = $violation->getMessage();
     }
     $errors = array_map(function (array $messages) {
         return implode(', ', $messages);
     }, $errors);
     parent::__construct(['message' => 'Validation error', 'errors' => $errors], self::HTTP_BAD_REQUEST);
 }
開發者ID:microservices-playground,項目名稱:api-comments,代碼行數:13,代碼來源:ValidationErrorResponse.php

示例14: __construct

 /**
  * @param mixed      $status
  * @param string     $tokenType
  * @param string     $realm
  * @param mixed|null $data
  */
 public function __construct($status, $tokenType, $realm, $data = null)
 {
     if (is_null($data)) {
         $data = array();
     }
     $defaultData = array('error' => 'access_denied', 'error_description' => 'OAuth2 authentication required');
     $data = array_merge($defaultData, $data);
     $header = sprintf('%s realm=%s', ucwords($tokenType), $realm);
     foreach ($data as $key => $value) {
         $header .= sprintf(', %s=%s', $key, $value);
     }
     $headers = array('WWW-Authenticate' => $header);
     parent::__construct($data, $status, $headers);
 }
開發者ID:atokovoy,項目名稱:oauth-security-proxy,代碼行數:20,代碼來源:ForbiddenResponse.php

示例15: __construct

 /**
  * JsonRpcHttpResponse constructor.
  *
  * @param JsonRpcResponseInterface|JsonRpcResponseInterface[] $jsonRpc
  * @param int                                                 $status
  * @param array                                               $headers
  */
 public function __construct($jsonRpc = null, $status = 200, array $headers = [])
 {
     if (null === $jsonRpc) {
         parent::__construct(null, $status, $headers);
         return;
     }
     if (!is_array($jsonRpc)) {
         parent::__construct($this->formatJsonRpcResponse($jsonRpc), $status, $headers);
         return;
     }
     $data = [];
     foreach ($jsonRpc as $response) {
         $data[] = $this->formatJsonRpcResponse($response);
     }
     parent::__construct($data, $status, $headers);
 }
開發者ID:bankiru,項目名稱:jsonrpc-server-bundle,代碼行數:23,代碼來源:JsonRpcHttpResponse.php


注:本文中的Symfony\Component\HttpFoundation\JsonResponse::__construct方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。