本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例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;
}
示例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();
}
}
示例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;
}
示例9: getClientFail
public function getClientFail()
{
$response = new HttpResponse();
$response->setStatusCode(404);
$client = new ClientNotReset();
$client->setResponse($response);
return $client;
}
示例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());
}
示例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));
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}