当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::setStatusCode方法代码示例

本文整理汇总了PHP中Response::setStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setStatusCode方法的具体用法?PHP Response::setStatusCode怎么用?PHP Response::setStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Response的用法示例。


在下文中一共展示了Response::setStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parse

 /**
  * Parses a raw response string, including headers and body, and returns a Response object.
  *
  * @param string $response
  *
  * @return \Brick\Http\Response
  *
  * @throws \RuntimeException
  */
 public static function parse($response)
 {
     $responseObject = new Response();
     if (preg_match('/^HTTP\\/([0-9]\\.[0-9]) ([0-9]{3}) .*\\r\\n/', $response, $matches) == 0) {
         throw new \RuntimeException('Could not parse response (error 1).');
     }
     list($line, $protocolVersion, $statusCode) = $matches;
     $responseObject->setProtocolVersion($protocolVersion);
     $responseObject->setStatusCode($statusCode);
     $response = substr($response, strlen($line));
     for (;;) {
         $pos = strpos($response, Message::CRLF);
         if ($pos === false) {
             throw new \RuntimeException('Could not parse response (error 2).');
         }
         if ($pos == 0) {
             break;
         }
         $header = substr($response, 0, $pos);
         if (preg_match('/^(\\S+):\\s*(.*)$/', $header, $matches) == 0) {
             throw new \RuntimeException('Could not parse response (error 3).');
         }
         list($line, $name, $value) = $matches;
         if (strtolower($name) == 'set-cookie') {
             $responseObject->setCookie(Cookie::parse($value));
         } else {
             $responseObject->addHeader($name, $value);
         }
         $response = substr($response, strlen($line) + 2);
     }
     $body = substr($response, 2);
     $responseObject->setContent($body);
     return $responseObject;
 }
开发者ID:brick,项目名称:http,代码行数:43,代码来源:Response.php

示例2: invalidate

 protected function invalidate(Request $request, $catch = false)
 {
     if ('PURGE' !== $request->getMethod()) {
         return parent::invalidate($request, $catch);
     }
     if ('127.0.0.1' !== $request->getClientIp()) {
         return new Response('Invalid HTTP method', Response::HTTP_BAD_REQUEST);
     }
     $response = new Response();
     if ($this->getStore()->purge($request->getUri())) {
         $response->setStatusCode(200, 'Purged');
     } else {
         $response->setStatusCode(200, 'Not found');
     }
     return $response;
 }
开发者ID:svtlichnijj,项目名称:temp_first_symfony2,代码行数:16,代码来源:AppCache.php

示例3: redirect

function redirect($url)
{
    $response = new Response();
    $completeURL = url($url);
    $response->addHeader('HTTP/1.1 302 Found');
    $response->addHeader("Location: " . $completeURL);
    $response->setStatusCode(302);
    return $response;
}
开发者ID:BenjaminLu,项目名称:ToyLara,代码行数:9,代码来源:response.helper.php

示例4: responseFromOAuth

 /**
  * Creates Phalcon response from OAuth2 Response.
  *
  * @param $oauth_response
  * @return Response
  */
 public static function responseFromOAuth($oauth_response)
 {
     $response = new Response();
     $response->setStatusCode($oauth_response->getStatusCode());
     foreach ($oauth_response->getHttpHeaders() as $header) {
         $response->setRawHeader($header);
     }
     $response->setContent($oauth_response->getResponseBody());
     return $response;
 }
开发者ID:soutoner,项目名称:api-desconecta,代码行数:16,代码来源:Response.php

示例5: get

 protected function get($path, array $query = array())
 {
     $response = null;
     try {
         $response = parent::get($path, $query);
     } catch (\Exception $e) {
         $http_response = new Response();
         $http_response->setStatusCode(Response::STATUS_CODE_500);
         $response = new ZendTwitterResponse($http_response);
     }
     return $response;
 }
开发者ID:antonio-salieri,项目名称:egctweet_plain,代码行数:12,代码来源:Twitter.php

示例6: error

 /**
  * show error page
  *
  * call error action method and set response status code
  * This will work as well for ajax call, see how ajax calls are handled in main.js
  *
  * @param int|string $code
  *
  */
 public function error($code)
 {
     $errors = [404 => "notfound", 401 => "unauthenticated", 403 => "unauthorized", 400 => "badrequest", 500 => "system"];
     if (!isset($errors[$code]) || !method_exists("ErrorsController", $errors[$code])) {
         $code = 500;
     }
     $action = isset($errors[$code]) ? $errors[$code] : "System";
     $this->response->setStatusCode($code);
     // clear, get page, then send headers
     $this->response->clearBuffer();
     (new ErrorsController($this->request, $this->response))->{$action}();
     return $this->response;
 }
开发者ID:omarelgabry,项目名称:miniphp,代码行数:22,代码来源:Controller.php

示例7: error

 /**
  * show error page
  *
  * call error action method and set response status code
  * This will work as well for ajax call, see how ajax calls are handled in main.js
  *
  * @param string $error
  *
  */
 public function error($error)
 {
     $errorController = new ErrorsController();
     if (!method_exists("ErrorsController", $error)) {
         $error = "System";
     }
     $errors = ["notfound" => 404, "system" => 500, "badrequest" => 400, "unauthorized" => 401, "forbidden" => 403];
     $code = isset($errors[strtolower($error)]) ? $errors[strtolower($error)] : 500;
     $this->response->setStatusCode($code);
     //clear, get page, then send headers
     $this->response->clearBuffer();
     $errorController->{$error}();
     $this->response->send();
 }
开发者ID:reallysend,项目名称:miniPHP,代码行数:23,代码来源:Controller.php

示例8: outputError

 public static function outputError($exception)
 {
     if (PHP_SAPI == 'cli') {
         echo $exception->getMessage() . "\nFile: " . $exception->getFile() . ' on line ' . $exception->getLine() . "\n\n" . $exception->getTraceAsString() . "\n";
         // exit with an error code
         exit(1);
     }
     // Write the error to log file
     @error_log('Error 404 Page Not Found: ' . $_SERVER['REQUEST_URI']);
     $response = new Response();
     $response->setStatusCode(404);
     $response->setBody(Controller::outputError('errors/404', ['message' => $exception->getMessage()]));
     return $response;
 }
开发者ID:finzaiko,项目名称:Panada,代码行数:14,代码来源:HttpException.php

示例9: outputError

 public static function outputError($message = null, $file = false, $line = false, $trace = false)
 {
     // Message for log
     $errorMessage = 'Error ' . $message . ' in ' . $file . ' line: ' . $line;
     // Write the error to log file
     @error_log($errorMessage);
     // Just output the error if the error source for view file or if in cli mode.
     if (PHP_SAPI == 'cli') {
         exit($errorMessage);
     }
     $code = [];
     if (!$file) {
         goto constructViewData;
     }
     $fileString = file_get_contents($file);
     $arrLine = explode("\n", $fileString);
     $totalLine = count($arrLine);
     $getLine = array_combine(range(1, $totalLine), array_values($arrLine));
     $startIterate = $line - 5;
     $endIterate = $line + 5;
     if ($startIterate < 1) {
         $startIterate = 1;
     }
     if ($endIterate > $totalLine) {
         $endIterate = $totalLine;
     }
     for ($i = $startIterate; $i <= $endIterate; $i++) {
         $html = '<span style="margin-right:10px;background:#CFCFCF;">' . $i . '</span>';
         if ($line == $i) {
             $html .= '<span style="color:#DD0000">' . htmlentities($getLine[$i]) . "</span>\n";
         } else {
             $html .= htmlentities($getLine[$i]) . "\n";
         }
         $code[] = $html;
     }
     constructViewData:
     $data = ['message' => $message, 'file' => $file, 'line' => $line, 'code' => $code, 'trace' => $trace];
     $response = new Response();
     $response->setStatusCode(500);
     $response->setBody(Controller::outputError('errors/500', $data));
     return $response;
 }
开发者ID:finzaiko,项目名称:Panada,代码行数:42,代码来源:RunException.php

示例10: supprimerfraishorsforfaitAction

 public function supprimerfraishorsforfaitAction($id)
 {
     $session = $this->get('request')->getSession();
     $idVisiteur = $session->get('id');
     $mois = getMois(date("d/m/Y"));
     $numAnnee = substr($mois, 0, 4);
     $numMois = substr($mois, 4, 2);
     $pdo = PdoGsb::getPdoGsb();
     if ($pdo->estValideSuppressionFrais($idVisiteur, $mois, $id)) {
         $pdo->supprimerFraisHorsForfait($id);
     } else {
         $response = new Response();
         $response->setContent("<h2>Page introuvable erreur 404 ");
         $response->setStatusCode(404);
         return $response;
     }
     $lesFraisForfait = $pdo->getLesFraisFrofait($idVisiteur, $mois);
     $lesFraisHorsForfait = $pdo->getLesFraisHorsForfait($idVisiteur, $mois);
     return $this->render('PgGsbFraisBundle:SaisirFrais:saisirtouslesfrais.html.twig', array('lesfraisforfait' => $lesFraisForfait, 'lesfraishorsforfait' => $lesFraisHorsForfait, 'nummois' => $numMois, 'numannee' => $numAnnee, 'leserreursforfait' => null, 'leserreurshorsforfait' => null));
 }
开发者ID:andreazambelli,项目名称:GSB,代码行数:20,代码来源:SaisirFraisController.php

示例11: testSetStatusThrowInvalidArgumentWhenStatusCodeArentInHttpFoundation

 /**
  * @expectedException \InvalidArgumentException
  * @dataProvider invalidStatusCodesProvider
  */
 public function testSetStatusThrowInvalidArgumentWhenStatusCodeArentInHttpFoundation($invalidStatusCode)
 {
     $response = new Response();
     $response->setStatusCode($invalidStatusCode);
 }
开发者ID:dafiti,项目名称:contentnegotiation-service-provider,代码行数:9,代码来源:ResponseTest.php

示例12: route

 /**
  * @param	Huxtable\Web\Request	$request
  * @return	Huxtable\Web\Response
  */
 public function route(Request $request)
 {
     $url = $request->getURL();
     $method = $request->getMethod();
     // Default response
     $response = new Response();
     $response->setStatusCode(404);
     $response->setContents('Not Found :(');
     if (isset($this->routes[$url])) {
         $routes = $this->routes[$url];
         // Route pattern + method match found
         if (isset($this->routes[$url][$method])) {
             $routeObject = $this->routes[$url][$method];
             $routeObject->setRequest($request);
             // Call authenticatiion callback if defined
             $authenticationClosure = $routeObject->getAuthenticationClosure();
             if ($authenticationClosure != false) {
                 try {
                     call_user_func($authenticationClosure);
                 } catch (Request\UnauthorizedException $e) {
                     $routeObject->response->setStatusCode(401);
                     $routeObject->response->setContents($routeObject->response->getStatusMessage());
                     return $routeObject->response;
                 }
             }
             // Confirm required headers were sent
             foreach ($routeObject->getRequiredHeaders() as $header) {
                 if ($request->getHeader($header) === false) {
                     $response->setStatusCode(400);
                     $response->setContents($routeObject->response->getContents());
                     return $response;
                 }
             }
             // Confirm required arguments were passed
             foreach ($routeObject->getRequiredArguments() as $argument) {
                 if ($request->getArgument($argument) === false) {
                     $response = new Response();
                     $response->setStatusCode(400);
                     $response->setContents("Missing required argument '{$argument}'");
                     return $response;
                 }
             }
             try {
                 // Call the main routing closure
                 $contents = call_user_func($routeObject->getClosure());
             } catch (\Exception $e) {
                 $response = new Response();
                 $response->setStatusCode(500);
                 $response->setContents($e->getMessage());
                 return $response;
             }
             $routeObject->response->setContents($contents);
             return $routeObject->response;
         }
         // No route pattern + method match found
         $response->setStatusCode(405);
         $response->setContents('Method Not Allowed :(');
     }
     return $response;
 }
开发者ID:huxtable,项目名称:web,代码行数:64,代码来源:Application.php

示例13: array

    } else {
        // Change the HTTP status
        $response->setStatusCode(409, "Conflict");
        $errors = array();
        foreach ($status->getMessages() as $message) {
            $errors[] = $message->getMessage();
        }
        $response->setJsonContent(array('status' => 'ERROR', 'messages' => $errors));
    }
    return $response;
});
// Deletes robots based on primary key
$app->delete('/api/robots/{id:[0-9]+}', function ($id) use($app) {
    $phql = "DELETE FROM Robots WHERE id = :id:";
    $status = $app->modelsManager->executeQuery($phql, array('id' => $id));
    // Create a response
    $response = new Response();
    if ($status->success() == true) {
        $response->setJsonContent(array('status' => 'OK'));
    } else {
        // Change the HTTP status
        $response->setStatusCode(409, "Conflict");
        $errors = array();
        foreach ($status->getMessages() as $message) {
            $errors[] = $message->getMessage();
        }
        $response->setJsonContent(array('status' => 'ERROR', 'messages' => $errors));
    }
    return $response;
});
$app->handle();
开发者ID:silvranz,项目名称:api,代码行数:31,代码来源:index.php

示例14: handle

 /**
  * Handles the authentication for user.
  *
  * @param GetResponseEvent $event The response event.
  *
  * @throws AuthenticationException When the request is not authenticated.
  *
  * @return void
  */
 public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/';
     if (!$request->headers->has('x-wsse') || 1 !== preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) {
         return;
     }
     $token = new WsseUserToken($this->providerKey);
     $token->setUser($matches[1]);
     $token->setDigest($matches[2]);
     $token->setNonce($matches[3]);
     $token->setCreated($matches[4]);
     try {
         $authToken = $this->authenticationManager->authenticate($token);
         $this->securityContext->setToken($authToken);
         return;
     } catch (AuthenticationException $failed) {
         $failedMessage = 'WSSE Login failed for ' . $token->getUsername() . '.  Because: ' . $failed->getMessage();
         $token = $this->securityContext->getToken();
         if ($token instanceof WsseUserToken && $this->providerKey === $token->getProviderKey()) {
             $this->securityContext->setToken(null);
         }
         // deny authentication with a '403 Forbidden' HTTP response
         $response = new Response();
         $response->setStatusCode(403);
         $event->setResponse($response);
         return;
     }
     // by default deny authorization
     $response = new Response();
     $response->setStatusCode(403);
     $event->setResponse($response);
 }
开发者ID:fattouchsquall,项目名称:AMFWebServicesSecurityBundle,代码行数:42,代码来源:WsseListener.php

示例15: getNotFoundResponse

 /**
  * Creates default Response in case of emergency.
  *
  * @param $message
  *
  * @return Response
  */
 private function getNotFoundResponse($message)
 {
     $response = new Response($message);
     $response->setStatusCode(404);
     return $response;
 }
开发者ID:serkin,项目名称:blog,代码行数:13,代码来源:Application.php


注:本文中的Response::setStatusCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。