本文整理汇总了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;
}
示例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: 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);
}
示例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;
}
示例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;
}
示例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());
}
示例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());
}
示例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);
}
示例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;
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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();
}