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


PHP Response::setStatusCode方法代码示例

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


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

示例1: onRoute

 public function onRoute(MvcEvent $e)
 {
     $request = $e->getRequest();
     if (!$request instanceof HttpRequest) {
         return;
     }
     $application = $e->getApplication();
     $serviceLocator = $application->getServiceManager();
     // Load the configuration for maintenance mode
     if ($serviceLocator->has('MaintenanceConfig')) {
         $config = $serviceLocator->get('MaintenanceConfig');
     } else {
         $config = new Config();
     }
     if (!$config->isEnabled()) {
         // Maintenance mode is disabled.
         return;
     }
     // Check the white list
     if ($request instanceof PhpRequest) {
         $address = $request->getServer('REMOTE_ADDR', null);
     } else {
         $address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
     }
     if (!empty($address)) {
         if (in_array($address, $config->getWhitelist())) {
             return;
         }
     }
     // Render the maintenance layout
     $renderer = new PhpRenderer();
     if ($serviceLocator->has('ViewHelperManager')) {
         $renderer->setHelperPluginManager($serviceLocator->get('ViewHelperManager'));
     }
     $resolver = new TemplateMapResolver();
     $resolver->add('maintenance', $config->getTemplate());
     $renderer->setResolver($resolver);
     $content = $renderer->render('maintenance');
     // Set the response
     $response = $e->getResponse();
     if (!$response instanceof HttpResponse) {
         $response = new HttpResponse();
     }
     $statusCode = $config->getStatusCode();
     $response->setStatusCode($statusCode);
     if ($statusCode === 503 && !$response->getHeaders()->has('Retry-After')) {
         $retryDate = $config->getRetryAfter();
         if ($retryDate instanceof DateTime) {
             $retryAfter = new RetryAfter();
             $retryAfter->setDate($retryDate);
             $response->getHeaders()->addHeader($retryAfter);
         }
     }
     $response->setContent($content);
     $e->setResponse($response);
     // Return the response
     return $response;
 }
开发者ID:zend-modules,项目名称:maintenance,代码行数:58,代码来源:MaintenanceListener.php

示例2: vCardAction

 public function vCardAction()
 {
     $contact = $this->contactService->find($this->params('id'));
     if (!$contact) {
         return $this->notFoundAction();
     }
     $builder = new VCardBuilder();
     switch (true) {
         case $contact instanceof Company:
             $vcard = $builder->buildCompany($contact);
             break;
         case $contact instanceof Person:
             $vcard = $builder->buildPerson($contact);
             break;
         default:
             throw new RuntimeException('Invalid type provided.');
     }
     $data = $vcard->serialize();
     $response = new Response();
     $response->setStatusCode(Response::STATUS_CODE_200);
     $response->setContent($data);
     $headers = $response->getHeaders();
     $headers->addHeaderLine('Content-Disposition', 'attachment; filename="' . $contact->getDisplayName() . '.vcf"');
     $headers->addHeaderLine('Content-Length', strlen($data));
     $headers->addHeaderLine('Content-Type', 'text/plain');
     return $response;
 }
开发者ID:zource,项目名称:zource,代码行数:27,代码来源:VCard.php

示例3: plugin_preview_action

function plugin_preview_action()
{
    global $vars;
    $page = isset($vars['page']) ? $vars['page'] : '';
    $modified = 0;
    $response = new Response();
    if (!empty($page)) {
        $wiki = Factory::Wiki($page);
        if ($wiki->isReadable()) {
            $source = $wiki->get();
            array_splice($source, 10);
            $response->setStatusCode(Response::STATUS_CODE_200);
            $response->setContent('<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n" . RendererFactory::factory($source));
            $headers = Header::getHeaders('text/xml', $wiki->time());
        } else {
            $response->setStatusCode(Response::STATUS_CODE_404);
            $headers = Header::getHeaders('text/xml');
        }
    } else {
        $response->setStatusCode(Response::STATUS_CODE_404);
        $headers = Header::getHeaders('text/xml');
    }
    $response->getHeaders()->addHeaders($headers);
    header($response->renderStatusLine());
    foreach ($response->getHeaders() as $_header) {
        header($_header->toString());
    }
    echo $response->getBody();
    exit;
}
开发者ID:logue,项目名称:pukiwiki_adv,代码行数:30,代码来源:preview.inc.php

示例4: getXmlAction

 public function getXmlAction($isin)
 {
     $display = new DisplayHelper();
     $certificate = $this->certificateRepository->load($isin);
     if (empty($certificate)) {
         return $this->response->setStatusCode(404);
     }
     try {
         $xml = $display->displayAsXml($certificate);
     } catch (\RuntimeException $e) {
         return $this->response->setStatusCode(405)->setContent($e->getMessage());
     }
     $this->response->headers()->addHeaderLine('Content-type', 'application/xml');
     return $this->response->setContent($xml);
 }
开发者ID:nfx,项目名称:zf2-casestudy,代码行数:15,代码来源:CertificateController.php

示例5: testSubmitBookmarkHttpError

 /**
  * @expectedException Exception
  * @expectedExceptionMessage request failed
  * @excpetedExceptionCode 1
  */
 public function testSubmitBookmarkHttpError()
 {
     $response = new Response();
     $response->setStatusCode(Response::STATUS_CODE_403);
     $this->mockSubmitClient($response);
     $this->sut->submitBookmark($this->getBookmark());
 }
开发者ID:nickel715,项目名称:pinboard-archive,代码行数:12,代码来源:WaybackMachineTest.php

示例6: onRoute

 public function onRoute(MvcEvent $e)
 {
     $serviceManager = $e->getApplication()->getServiceManager();
     $routeMatchName = $e->getRouteMatch()->getMatchedRouteName();
     if (strpos($routeMatchName, '.rest.') !== false || strpos($routeMatchName, '.rpc.') !== false) {
         return;
     }
     $config = $serviceManager->get('Config');
     $identityGuards = $config['zource_guard']['identity'];
     $needsIdentity = null;
     foreach ($identityGuards as $guard => $needed) {
         if (fnmatch($guard, $routeMatchName)) {
             $needsIdentity = $needed;
             break;
         }
     }
     if ($needsIdentity === null) {
         throw new RuntimeException(sprintf('The identity guard "%s" has not been configured.', $routeMatchName));
     }
     if (!$needsIdentity) {
         return;
     }
     $authenticationService = $serviceManager->get('Zend\\Authentication\\AuthenticationService');
     if ($authenticationService->hasIdentity()) {
         return;
     }
     $returnUrl = $e->getRouter()->assemble([], ['name' => $routeMatchName, 'force_canonical' => true, 'query' => $e->getRequest()->getUri()->getQuery()]);
     $url = $e->getRouter()->assemble([], ['name' => 'login', 'query' => ['redir' => $returnUrl]]);
     $response = new Response();
     $response->setStatusCode(Response::STATUS_CODE_302);
     $response->getHeaders()->addHeaderLine('Location: ' . $url);
     return $response;
 }
开发者ID:zource,项目名称:zource,代码行数:33,代码来源:IdentityGuard.php

示例7: sendHandshakeResponse

 private function sendHandshakeResponse()
 {
     try {
         $challengeHeader = $this->getHandshakeRequest()->getHeader('Sec-Websocket-Key', null);
         if (!$challengeHeader) {
             throw new Exception("No Sec-WebSocket-Key received!");
         }
         // Check for newer handshake
         $challenge = $challengeHeader->getFieldValue();
         // Build response
         $response = new Response();
         $response->setStatusCode(101);
         $response->setReasonPhrase("WebSocket Protocol Handshake");
         $headers = new Headers();
         $response->setHeaders($headers);
         $headers->addHeaderLine("Upgrade", "WebSocket");
         $headers->addHeaderLine("Connection", "Upgrade");
         $headers->addHeaderLine("Sec-WebSocket-Accept", self::calcHybiResponse($challenge));
         $this->setResponse($response);
         $handshakeRequest = new Handshake($this->getHandshakeRequest(), $this->getHandshakeResponse());
         $this->emit("handshake", array($handshakeRequest));
         if ($handshakeRequest->isAborted()) {
             $this->close();
         } else {
             $this->_socket->write($response->toString());
             $this->logger->debug("Got an HYBI style request, sent HYBY handshake response");
             $this->connected = true;
             $this->emit("connect");
         }
     } catch (Exception $e) {
         $this->logger->err("Connection error, message: " . $e->getMessage());
         $this->close();
     }
 }
开发者ID:rb-cohen,项目名称:phpws,代码行数:34,代码来源:WebSocketTransportHybi.php

示例8: createResponse

 /**
  * Creates the response to be returned for a QR Code
  * @param $content
  * @param $contentType
  * @return HttpResponse
  */
 protected function createResponse($content, $contentType)
 {
     $resp = new HttpResponse();
     $resp->setStatusCode(200)->setContent($content);
     $resp->getHeaders()->addHeaders(array('Content-Length' => strlen($content), 'Content-Type' => $contentType));
     return $resp;
 }
开发者ID:acelaya,项目名称:zf2-acqrcode,代码行数:13,代码来源:QrCodeController.php

示例9: getClientFail

 public function getClientFail()
 {
     $response = new HttpResponse();
     $response->setStatusCode(404);
     $client = new ClientNotReset();
     $client->setResponse($response);
     return $client;
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:8,代码来源:PublisherTest.php

示例10: testConstructorWithHttpResponse

 public function testConstructorWithHttpResponse()
 {
     $httpResponse = new Response();
     $httpResponse->setStatusCode(200);
     $httpResponse->getHeaders()->addHeaderLine('Content-Type', 'text/html');
     $response = new CaptchaResponse($httpResponse);
     $this->assertSame(true, $response->getStatus());
 }
开发者ID:szmnmichalowski,项目名称:zf2-nocaptcha,代码行数:8,代码来源:ResponseTest.php

示例11: rawResponse

 /**
  * @param int $status
  * @param array $body
  */
 private function rawResponse($status, $body)
 {
     $zfResponse = new ZfResponse();
     $zfResponse->setStatusCode($status);
     $reasonPhrase = $zfResponse->getReasonPhrase();
     \header('HTTP/1.0 ' . $status . ' ' . $reasonPhrase);
     \header('Content-Type: application/json');
     die(json_encode($body));
 }
开发者ID:rockeinstein,项目名称:library,代码行数:13,代码来源:Response.php

示例12: unset

 function it_traps_unauthorized(MvcEvent $event, Response $response, Application $application)
 {
     unset($_SERVER['HTTP_X_REQUESTED_WITH']);
     $event->getTarget()->willReturn($application);
     $event->setRouteMatch(new RouteMatch(['controller' => 'Controller', 'action' => 'Action']))->shouldBeCalled();
     $response->setStatusCode(403)->shouldBeCalled();
     $event->getResponse()->willReturn($response);
     $this->handle($event, AccessService::ACCESS_UNAUTHORIZED)->shouldBe(true);
 }
开发者ID:saeven,项目名称:zf3-circlical-user,代码行数:9,代码来源:RedirectStrategySpec.php

示例13: testExceptionsAreThrownOnErrors

 /**
  * @dataProvider exceptionDataProvider
  */
 public function testExceptionsAreThrownOnErrors($statusCode, $expectedException)
 {
     $method = new ReflectionMethod('SlmMail\\Service\\MailgunService', 'parseResponse');
     $method->setAccessible(true);
     $response = new HttpResponse();
     $response->setStatusCode($statusCode);
     $this->setExpectedException($expectedException);
     $method->invoke($this->service, $response);
 }
开发者ID:erik-maas,项目名称:SlmMail,代码行数:12,代码来源:MailgunServiceTest.php

示例14: testConstructorWithMissingStatus

 public function testConstructorWithMissingStatus()
 {
     $params = array('error' => 'error');
     $httpResponse = new Response();
     $httpResponse->setStatusCode(200);
     $httpResponse->getHeaders()->addHeaderLine('Content-Type', 'text/html');
     $httpResponse->setContent(json_encode($params));
     $response = new CaptchaResponse($httpResponse);
     $this->assertSame(false, $response->getStatus());
 }
开发者ID:as-sar,项目名称:ZF2-NoCaptcha,代码行数:10,代码来源:ResponseTest.php

示例15: create

 /**
  * Creates a new entry
  *
  * @param mixed $data
  * @return Response
  */
 public function create($data)
 {
     $sintegra = new Sintegra();
     $sintegra->exchangeArray($data);
     $this->getSintegraTable()->saveSintegra($sintegra);
     $response = new Response();
     $response->setStatusCode(200);
     $response->setContent(json_encode(array('status' => 'ok')));
     return $response;
 }
开发者ID:GilTSN,项目名称:sample_rest_app,代码行数:16,代码来源:SintegraController.php


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