本文整理汇总了PHP中Response::setCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setCode方法的具体用法?PHP Response::setCode怎么用?PHP Response::setCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::setCode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: call
/**
* @param Request $request
* @return Response
*/
public function call(Request $request)
{
// Create cURL
$ch = curl_init();
// Set-up URL
curl_setopt($ch, CURLOPT_URL, $request->getUrl());
// Set-up headers
$headers = $request->getHeaders();
array_walk($headers, function (&$item, $key) {
$item = "{$key}: {$item}";
});
curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($headers));
// Set-up others
curl_setopt_array($ch, $request->getOpts());
// Receive result
$result = curl_exec($ch);
// Parse response
$response = new Response();
if ($result === FALSE) {
$response->setError(curl_strerror(curl_errno($ch)));
$response->setData(FALSE);
$response->setCode(curl_errno($ch));
$response->setHeaders(curl_getinfo($ch));
} else {
$response->setData(json_decode($result));
$response->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
$response->setHeaders(curl_getinfo($ch));
}
// Close cURL
curl_close($ch);
return $response;
}
示例2: __invoke
/**
* @param Request $req
* @param Response $res
*
* @return Response
*/
public function __invoke($req, $res)
{
if ($req->isHtml()) {
$res->render(new View('not_found', ['title' => 'Not Found']));
}
return $res->setCode(404);
}
示例3: __invoke
/**
* @param Request $req
* @param Response $res
* @param array $allowedMethods
*
* @return Response
*/
public function __invoke($req, $res, $allowedMethods)
{
if ($req->isHtml()) {
$res->render(new View('method_not_allowed', ['title' => 'Method Not Allowed', 'allowedMethods' => $allowedMethods]));
}
return $res->setCode(405);
}
示例4: __invoke
/**
* @param Request $req
* @param Response $res
* @param \Exception $e
*
* @return Response
*/
public function __invoke($req, $res, \Exception $e)
{
$this->app['logger']->error('An uncaught exception occurred while handling a request.', ['exception' => $e]);
if ($req->isHtml()) {
$res->render(new View('exception', ['title' => 'Internal Server Error', 'exception' => $e]));
}
return $res->setCode(500);
}
示例5: createResponse
/**
* {@inheritdoc}
* @see \InoOicClient\Oic\Authorization\ResponseFactoryInterface::createResponse()
*/
public function createResponse($code, $state = null)
{
$response = new Response();
$response->setCode($code);
if (null !== $state) {
$response->setState($state);
}
return $response;
}
示例6: report
/**
*
* Report the error
*
* @param [string] The message to be displayed
* @param [boolean] Whether or not to display PHP backtrace
*/
function report($msg, $backtrace = true)
{
// Check for error reporting flag
if ($this->config['error_reporting']) {
Template::load('error_reporting.html', array("msg" => $msg, "backtrace" => print_r(debug_backtrace(), true)));
exit;
} else {
// Prepare 404 response
$Response = new Response();
$Response->setCode(404);
$Response->send();
Template::load('404.html');
}
exit;
}
示例7: createAction
/**
* @route POST /?method=users.create&format=json
* @route POST /users/create.json
*
* @param Request $request
* @return Response
* @throws Exception
*/
public function createAction($request)
{
$request->acceptContentTypes(array('json'));
if ('POST' != $request->getMethod()) {
throw new Exception('HTTP method not allowed', Response::NOT_ALLOWED);
}
try {
$user = new User(array('name' => $request->getPost('name'), 'username' => $request->getPost('username'), 'email' => $request->getPost('email'), 'gender' => $request->getPost('gender')));
} catch (ValidationException $e) {
throw new Exception($e->getMessage(), Response::OK);
}
$id = $this->getModel('User')->save($user);
if (!is_numeric($id)) {
throw new Exception('An error occurred while creating user', Response::OK);
}
$response = new Response();
$response->setCode(Response::CREATED);
$response->setEtagHeader(md5('/users/' . $id));
return $response;
}
示例8: runApp
public static function runApp()
{
if (!Request::isАuthorized()) {
Response::setCode(401);
return;
}
$matchedResource = Router::getMatchedRouterResource(Request::getMethod(), Request::getCleanRequestUrl());
if ($matchedResource === null) {
Response::setCode(404);
return;
}
try {
$response = self::executeResoruceAction($matchedResource[0], $matchedResource[1], Router::getMachedRouteParameters());
if ($response === false) {
Response::setCode(404);
} else {
Response::setBody($response);
}
} catch (\Exception $e) {
Response::setCode(500);
}
}
示例9: buildTransferReversal
private function buildTransferReversal($xml)
{
$transferReversal = new TransferReversal();
$transferReversal->setRequestId((string) $xml->RequestId);
$transferReversal->setOriginalRequestId((string) $xml->OriginalRequestId);
$transferReversal->setTransactionReference((string) $xml->TransactionReference);
$transactionHistory = new TransactionHistory();
$tmpTransaction = new Transaction();
$transaction = $xml->TransactionHistory->Transaction;
$tmpTransaction->setType((string) $transaction->Type);
$tmpTransaction->setSystemTraceAuditNumber((string) $transaction->SystemTraceAuditNumber);
$tmpTransaction->setNetworkReferenceNumber((string) $transaction->NetworkReferenceNumber);
$tmpTransaction->setSettlementDate((string) $transaction->SettlementDate);
$tmpResponse = new Response();
$response = $transaction->Response;
$tmpResponse->setCode((string) $response->Code);
$tmpResponse->setDescription((string) $response->Description);
$tmpTransaction->setSubmitDateTime((string) $transaction->SubmitDateTime);
$tmpTransaction->setResponse($tmpResponse);
$transactionHistory->setTransaction($tmpTransaction);
$transferReversal->setTransactionHistory($transactionHistory);
return $transferReversal;
}
示例10: redirect
/**
* @param string $uri
* @param integer $code HTTP status codes
* @return void
*/
public function redirect($uri, $code = Response::FOUND)
{
$response = new Response();
$response->setCode($code);
$response->addHeader('Location: ' . $uri);
$response->sendHeaders();
exit;
}
示例11: buildTransfer
private function buildTransfer($xml)
{
$transfer = new Transfer();
$transfer->setRequestId((string) $xml->RequestId);
$transfer->setTransactionReference((string) $xml->TransactionReference);
$transactionHistory = new TransactionHistory();
$transactionArray = array();
foreach ($xml->TransactionHistory->Transaction as $transaction) {
$tmpTransaction = new Transaction();
$tmpTransaction->setType((string) $transaction->Type);
$tmpTransaction->setSystemTraceAuditNumber((string) $transaction->SystemTraceAuditNumber);
$tmpTransaction->setNetworkReferenceNumber((string) $transaction->NetworkReferenceNumber);
$tmpTransaction->setSettlementDate((string) $transaction->SettlementDate);
$tmpResponse = new Response();
$response = $transaction->Response;
$tmpResponse->setCode((string) $response->Code);
$tmpResponse->setDescription((string) $response->Description);
$tmpTransaction->setSubmitDateTime((string) $transaction->SubmitDateTime);
$tmpTransaction->setResponse($tmpResponse);
array_push($transactionArray, $tmpTransaction);
}
$transactionHistory->setTransaction($transactionArray);
$transfer->setTransactionHistory($transactionHistory);
return $transfer;
}
示例12: setResponseCode
public function setResponseCode($code)
{
Response::setCode($code);
}