本文整理汇总了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));
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}