Response macro to send a response based on a payload.

@return mixed
4665
public function viewWithPayload()
    {
        return function (string $view, PayloadContract $payload, string $key = 'payload') {
            return ResponseFactory::view($view, [$key => $payload->getUnwrappedOutput()], $payload->getStatus());
        };
    }
265753
protected function processResponse()
    {
        $body = $this->response->getBody();

        // Look for UTF-8 BOM and remove.
        if (0 === strpos(bin2hex(substr($body, 0, 4)), 'efbbbf')) {
            $body = substr($body, 3);
        }

        $parsedResponse = \json_decode($body);

        // Test if return a valid JSON.
        if (JSON_ERROR_NONE !== json_last_error()) {
            $message = function_exists('json_last_error_msg') ? json_last_error_msg() : 'Invalid JSON returned';
            throw new HttpClientException(
                sprintf('JSON ERROR: %s', $message),
                $this->response->getCode(),
                $this->request,
                $this->response
            );
        }

        $this->lookForErrors($parsedResponse);

        return $parsedResponse;
    }
753657
protected function getResponse()
	{
		$response = trim($this->connection->readLine());

		switch(substr($response, 0, 1))
		{
			case '-': // error reply
				return $this->handleErrorResponse($response);
				break;
			case '+': // status reply
				return $this->handleStatusResponse($response);
				break;
			case ':': // integer reply
				return $this->handleIntegerResponse($response);
				break;
			case '$': // bulk reply
				return $this->handleBulkResponse($response);
				break;
			case '*': // multi-bulk reply
				return $this->handleMultiBulkResponse($response);
				break;
			default:
				throw new RedisException(vsprintf('Unable to handle server response [ %s ].', [$response]));
		}
	}
844508
public function handler(): Response
    {
        $response = [];
        foreach (Bulletin::all() as $bulletin) {
            $response[] = [
                'id' => $bulletin->getId(),
                'createdAt' => $bulletin->getCreatedAt()->getTimestamp(),
                'title' => $bulletin->getTitle(),
                'abstract' => $bulletin->getAbstract(),
                'isDraft' => $bulletin->isDraft(),
                'statistics' => $bulletin->getStatistics()
            ];
        }
        return response($response);
    }
831542
public function send()
    {
        if (!$this->hasBeenInitialized())
            $this->_curlPrep();

        $result = curl_exec($this->_ch);

        $response = $this->buildResponse($result);

        curl_close($this->_ch);
        unset($this->_ch);

        return $response;
    }
1060258
public function exec(): Response
    {
        $url = $this->getUrl();

        $ch = curl_init($url);

        foreach ($this->getCurlOptions() as $option => $value) {
            // iterating it so we have all options applied in given order
            curl_setopt($ch, $option, $value);
        }

        $body = curl_exec($ch);

        if (curl_errno($ch)) {
            throw new HttpException(curl_error($ch));
        }

        return new Response($ch, $body, $this);
    }
251762
public function handler(): Response
    {
        $data = $this->validate([
            'name' => [
                new NotBlank()
            ],
            'slug' => [
                new NotBlank()
            ],
            'icon' => [],
            'color' => []
        ]);
        $role = new Role($data);
        $role->save();
        $this->log('info', 'Create a role [' . $role->getSlug() . ']');
        return response([
            'id' => $role->getId()
        ]);
    }
741635
public function checkResponse()
    {
        if (!isset($this->order_ref)) {
            $this->errorMessage[] = 'CHECK RESPONSE: Missing order_ref variable!';
            return false;
        }
        $this->logFunc("BackRef", $this->getData, $this->order_ref);

        if (!$this->checkCtrl()) {
            $this->errorMessage[] = 'CHECK RESPONSE: INVALID CTRL!';
            return false;
        }

        $ios = new SimpleIos($this->iosConfig, $this->getData['order_currency'], $this->order_ref);

        foreach ($ios->errorMessage as $msg) {
            $this->errorMessage[] = $msg;
        }
        foreach ($ios->debugMessage as $msg) {
            $this->debugMessage[] = $msg;
        }

        if (is_object($ios)) {
            $this->checkIOSStatus($ios);
        }
        $this->logFunc("BackRef_BackStatus", $this->backStatusArray, $this->order_ref);
        if (!$this->checkRtVariable($ios)) {
            return false;
        }
        if (!$this->backStatusArray['RESULT']) {
            return false;
        }
        return true;
    }
9823
private function responses() {return dfc($this, function() {return array_map(function(T $t) {return
		F::s($this->_m, df_trd($t))->e()
	;}, $this->tResponses());});}
59993
protected function getResponseMessage()
    {

        // read the first 4 bytes which include the length of the response
        $lengthEncoded = $this->client->read(4);

        if (strlen($lengthEncoded) < 4) {
            return new Message('', Message::TYPE_RESPONSE_VALUE);
        }

        $lengthInBytes = unpack('V1size', $lengthEncoded)['size'];

        if ($lengthInBytes <= 0) {
            return new Message('', Message::TYPE_RESPONSE_VALUE);
        }

        $responseData = $this->client->read($lengthInBytes);

        // return an empty message if the server did not send any response
        if (null === $responseData) {
            return new Message('', Message::TYPE_RESPONSE_VALUE);
        }

        $responseMessage = new Message();
        $responseMessage->initializeFromRconData($responseData);

        if ($lengthInBytes >= 4000) {
            $this->handleFragmentedResponse($responseMessage);
        }

        return $responseMessage;
    }
1240773
public function toResponse(): Response
    {
        return new Response(
            $this->status,
            $this->headers,
            $this->body,
            $this->httpVersion,
            $this->reason
        );
    }
862603
private function prepareResponse() {
    if (is_null($this->response)) {
      return false;
    }

    $response = "";

    $this->response_header_block = $this->extractHeadersFromResponse();
    if ($this->tryGetOption(CURLOPT_HEADER, $value) && $value) {
      $response .= $this->response_header_block;
    }
    $response .= $this->response->getContent();

    return $response;
  }
884938
public function handler(): Response
    {
        $bulletin = (new Bulletin())
            ->title(date('Ymd', time()) . '公告')
            ->content('全体 ' . Config::get('name') . ' 成员:')
            ->save();
        $this->log('info', 'Create a bulletin [' . $bulletin->getId() . ']');
        return response([
            'id' => $bulletin->getId()
        ]);
    }
1229063
public function response()
    {
        return new MultiErrorResponse($this->httpStatusCode, $this->code, $this->message, $this->validationMessages);
    }
709152
protected function prepareResponse()
    {
        $response = new Response;
        $response->method = $this->method;
        $response->zlib_compression = $this->zlib_compression;
        return $response;
    }
878823
public function getResponse()
    {
        $this->addParameters()->addHeaders();
        $this->options[CURLOPT_RETURNTRANSFER] = true;

        $this->meta = call_user_func($this->map, $this->options);

        return $this->meta['response'];
    }
1096413
public function getResponse()
	{
		if (method_exists($this->controller, 'getResponse'))
		{
			/** @var HttpResponse $response */
			$response = $this->controller->getResponse();
		}
		else
		{
			$response = new HttpResponse;
		}

		$fp = fopen('php://output', 'w');
		ob_start();
		fputcsv($fp, $this->header, $this->delimiter, $this->enclosure);
		foreach ($this->content as $i => $item)
		{
			try
			{
				$fields = $this->callback ? call_user_func($this->callback, $item) : $item;
				if (!is_array($fields))
				{
					throw new \RuntimeException('CsvExport can only accept arrays, '. gettype($fields) .' provided at index '. $i .'. Either use arrays when setting the records or use a callback to convert each record into an array.');
				}
				fputcsv($fp, $fields, $this->delimiter, $this->enclosure);
			}
			catch (\Exception $ex)
			{
				ob_end_clean();
				throw $ex;
			}
		}
		fclose($fp);
		$response->setContent(ob_get_clean());

		$response->getHeaders()->addHeaders(array(
			'Content-Type' => 'text/csv',
			'Content-Disposition' => 'attachment;filename="'. str_replace('"', '\\"', $this->name) .'.csv"',
		));

		return $response;
	}