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


PHP Response::setContent方法代码示例

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


在下文中一共展示了Response::setContent方法的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: 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

示例4: 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

示例5: setResponseContent

 protected function setResponseContent(Response $response, array $data)
 {
     if ($response instanceof \Zend\Http\PhpEnvironment\Response) {
         $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
         $response->setContent(json_encode(array_merge(array('status' => $response->getStatusCode()), $data)));
     }
     return $response;
 }
开发者ID:fousheezy,项目名称:auth,代码行数:8,代码来源:Api.php

示例6: testIsValidDetectsGoodResponse

 public function testIsValidDetectsGoodResponse()
 {
     $body = 'oauth_token=jZaee4GF52O3lUb9&oauth_token_secret=J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri';
     $response = new HTTPResponse();
     $response->setContent($body)->setStatusCode(200);
     $token = new AccessToken($response);
     $this->assertTrue($token->isValid());
 }
开发者ID:binary-data,项目名称:ZendOAuth,代码行数:8,代码来源:AccessTest.php

示例7: testSet201StatusCodeIfPost

 public function testSet201StatusCodeIfPost()
 {
     $request = new HttpRequest();
     $request->setMethod(HttpRequest::METHOD_POST);
     $this->event->setRequest($request);
     $this->response->setContent('foo');
     $this->resourceResponseListener->finishResponse($this->event);
     $this->assertEquals(201, $this->response->getStatusCode());
 }
开发者ID:omusico,项目名称:zfr-rest,代码行数:9,代码来源:ResourceResponseListenerTest.php

示例8: testExceptionsAreThrownOnErrors

 /**
  * @dataProvider exceptionDataProvider
  */
 public function testExceptionsAreThrownOnErrors($statusCode, $content, $expectedException)
 {
     $method = new ReflectionMethod('EzMail\\Service\\MandrillService', 'parseResponse');
     $method->setAccessible(true);
     $response = new HttpResponse();
     $response->setStatusCode($statusCode);
     $response->setContent($content);
     $this->setExpectedException($expectedException);
     $method->invoke($this->service, $response);
 }
开发者ID:misarji,项目名称:ez-mail,代码行数:13,代码来源:MandrillServiceTest.php

示例9: 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

示例10: 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

示例11: httpResponse

 /**
  * Wrap the Jaxon response into an HTTP response.
  *
  * @param  $code        The HTTP Response code
  *
  * @return \Zend\Http\Response
  */
 public function httpResponse($code = '200')
 {
     // Send HTTP Headers
     // $this->response->sendHeaders();
     // Create and return a ZF2 HTTP response
     $response = new HttpResponse();
     $headers = $response->getHeaders();
     $headers->addHeaderLine('Content-Type', $this->response->getContentType() . '; charset=' . $this->response->getCharacterEncoding());
     $response->setStatusCode(intval($code));
     $response->setContent($this->response->getOutput());
     return $response;
 }
开发者ID:jaxon-php,项目名称:jaxon-zend,代码行数:19,代码来源:JaxonPlugin.php

示例12: generateSnapshots

 /**
  * @return \WebArchive\SnapshotCollection
  */
 private function generateSnapshots()
 {
     $uri = 'http://pokap.io/';
     $provider = new MementoProvider();
     $client = new Client($provider->createUrlRequest($uri));
     $response = new Response();
     $response->setContent(implode(gzfile(__DIR__ . '/fixtures/pokap.io-memento.gz')));
     $adapter = new TestAdapter();
     $adapter->setResponse($response);
     $client->setAdapter($adapter);
     return $provider->generateSnapshots($client->send(), $uri);
 }
开发者ID:pokap,项目名称:webarchive,代码行数:15,代码来源:MementoProviderTest.php

示例13: generateSnapshots

 /**
  * @param int $year
  *
  * @return \WebArchive\SnapshotCollection
  */
 private function generateSnapshots($year)
 {
     $uri = 'http://archive.org/';
     $provider = new WayBackProvider($year);
     $client = new Client($provider->createUrlRequest($uri));
     $response = new Response();
     $response->setContent(implode(gzfile(__DIR__ . '/fixtures/archive.org-' . $year . '.html.gz')));
     $adapter = new TestAdapter();
     $adapter->setResponse($response);
     $client->setAdapter($adapter);
     return $provider->generateSnapshots($client->send(), $uri);
 }
开发者ID:pokap,项目名称:webarchive,代码行数:17,代码来源:WayBackProviderTest.php

示例14: testConstructorWithHttpResponse

 public function testConstructorWithHttpResponse()
 {
     $status = 'false';
     $errorCode = 'foobar';
     $responseBody = $status . "\n" . $errorCode;
     $httpResponse = new Response();
     $httpResponse->setStatusCode(200);
     $httpResponse->getHeaders()->addHeaderLine('Content-Type', 'text/html');
     $httpResponse->setContent($responseBody);
     $response = new ReCaptcha\Response(null, null, $httpResponse);
     $this->assertSame(false, $response->getStatus());
     $this->assertSame($errorCode, $response->getErrorCode());
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:13,代码来源:ResponseTest.php

示例15: testWrongContentTypeThrowsInvalidResponseException

 public function testWrongContentTypeThrowsInvalidResponseException()
 {
     $this->setExpectedException('Magium\\Mail\\Api\\InvalidResponseException');
     $builder = $this->getMockBuilder('Zend\\Http\\Client')->setMethods(['send']);
     $client = $builder->getMock();
     /* @var $client \Zend\Http\Client */
     $response = new Response();
     $response->setContent(json_encode(['error' => 'error message']));
     $response->setHeaders(Headers::fromString('Content-Type: wrong'));
     $client->expects($this->once())->method('send')->willReturn($response);
     $generator = new Generator(new Configuration(), $client, 'abcd');
     $generator->generate();
 }
开发者ID:magium,项目名称:MagiumMail,代码行数:13,代码来源:ErrorTest.php


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