/** * 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)); }
/** * @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); }
/** * @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); } }
/** * @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); }
/** * 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; }
/** * 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); }
public function __construct($data = array(), $successMessage = null, $status = HTTPCode::OK) { $data['success'] = true; if ($successMessage) { $data['successMessage'] = $successMessage; } return parent::__construct($data, $status); }
public function __construct($data = null, $status = 200, $headers = array()) { if (null === $data) { $data = new \stdClass(); } parent::__construct($data, $status, $headers); $this->rawData = $data; }
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); }
/** * @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); }
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); }
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); }
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); }
/** * @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); }
/** * 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); }
/** * 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 = array()) { parent::__construct(null, $status, $headers); if (null === $data) { $data = new \ArrayObject(); } if ($data instanceof \Iterator) { $json = '['; $i = 0; foreach ($data as $item) { if ($i++ != 0) { $json .= ', '; } $json .= json_encode($item); } $json .= ']'; $this->data = $json; $this->update(); } else { $this->setData($data); } }
public function __construct($oldSize, $newSize, $saving, $binaryContent, $status = 200, array $headers = array()) { $data = ['success' => true, 'oldSize' => $oldSize, 'newSize' => $newSize, 'saving' => $saving, 'image' => base64_encode($binaryContent)]; parent::__construct($data, $status, $headers); }
/** * Constructor. * * @param mixed $data * @param int $status * @param array $headers * @param int $options */ public function __construct($data = null, $status = 200, $headers = array(), $options = 0) { $this->jsonOptions = $options; parent::__construct($data, $status, $headers); }
/** * Constructor * * @param string $data The raw JSON data * @param integer $status The status code (defaults to 200) * @param array $headers An array of response headers */ public function __construct($data = null, $status = 200, array $headers = array()) { parent::__construct('', $status, $headers); $this->setData($data); }
public function __construct(PhaxReaction $phaxReaction) { parent::__construct($phaxReaction->jsonSerialize()); }
/** * {@inheritdoc} */ public function __construct($errorMsg) { parent::__construct(['result' => 'error', 'error' => $errorMsg]); }
/** * {@inheritdoc} */ public function __construct($data = null, array $headers = []) { parent::__construct($data, 205, $headers); }
/** * @param ApiProblem $apiProblem */ public function __construct(ApiProblem $apiProblem) { parent::__construct($apiProblem->toArray(), $apiProblem->status); }
public function __construct($errorDescription, $errorDetail = "not available", $status = 500, $headers = array()) { $responseData = ['error' => $errorDescription, 'error.detail' => $errorDetail]; parent::__construct($responseData, $status, $headers); }
/** * HalJsonResponse constructor. * @param AbstractHalResource $model * @param int $status * @param array $headers */ public function __construct(AbstractHalResource $model, $status = 200, array $headers = []) { $headers['Content-type'] = 'application/hal+json'; parent::__construct('', $status, $headers); $this->rawData = $model; }
public function __construct($data = true, $status = 200, $headers = array()) { $this->jsonData = $data; parent::__construct($data, $status, $headers); }
/** * Constructor. * * @param mixed $data * @param int $status * @param array $headers * @param int $options */ public function __construct($data = null, $status = 200, $headers = [], $options = 0) { $this->encodingOptions = $options; parent::__construct($data, $status, $headers); }
public function __construct($data = null, $status = 200, $headers = array()) { $document = ["data" => $data]; parent::__construct($document, $status, $headers); }
/** * Constructor. * * @param ArraySerializableInterface $data * @param integer $status The response status code * @param array $headers An array of response headers */ public function __construct(ArraySerializableInterface $data, $status = 200, $headers = array()) { $this->object = $data; parent::__construct($data->getArrayCopy(), $status, $headers); }
/** * @param mixed $data * @param int $status * @param array $headers */ public function __construct($data = null, $status = 200, $headers = array()) { parent::__construct($this->buildResponseArray($data), $status, $headers); }