本文整理匯總了PHP中Symfony\Component\HttpFoundation\Response::getContent方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::getContent方法的具體用法?PHP Response::getContent怎麽用?PHP Response::getContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::getContent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: assertSuccess
public function assertSuccess()
{
if ($this->response->getStatusCode() != 200) {
$this->fail($this->response->getContent());
}
return $this;
}
示例2: evaluateGoodXML
private function evaluateGoodXML(Response $response)
{
$dom_doc = new \DOMDocument();
$dom_doc->loadXML($response->getContent());
$this->assertInstanceOf('DOMDocument', $dom_doc);
$this->assertEquals($dom_doc->saveXML(), $response->getContent());
}
示例3: iShouldSee
/**
* @Then /^I should see "([^"]*)"$/
*/
public function iShouldSee($match)
{
if ($this->response instanceof \Exception) {
throw $this->response;
}
PHPUnit_Framework_Assert::assertContains($match, $this->response->getContent());
}
示例4: testPlainRequest
public function testPlainRequest()
{
$testBody = 'test';
$this->response->setContent($testBody);
$this->listener->onResponse($this->event);
$this->assertEquals($testBody, $this->response->getContent());
}
示例5: doKernelResponse
protected function doKernelResponse(Request $request, Response $response)
{
if (!$response instanceof DataResponse) {
return;
}
$routeName = $request->attributes->get('_route');
$route = $this->routes->get($routeName);
if (!$route) {
return;
}
$acceptedFormat = $route->getOption(RouteOptions::ACCEPTED_FORMAT);
if (!$acceptedFormat) {
$response->setContent('');
$response->setStatusCode(406);
}
if ($this->encoder->supportsEncoding($acceptedFormat) && $acceptedFormat === 'json') {
$contentType = $request->getMimeType($acceptedFormat);
$jsonResponse = new JsonResponse($response->getContent());
$response->setContent($jsonResponse->getContent());
$response->headers->set('Content-Type', $contentType);
} elseif ($this->encoder->supportsEncoding($acceptedFormat)) {
$contentType = $request->getMimeType($acceptedFormat);
$content = $this->encoder->encode($response->getContent(), $acceptedFormat);
$response->setContent($content);
$response->headers->set('Content-Type', $contentType);
}
}
示例6: testUnspecified
public function testUnspecified()
{
$this->mapping->setParameter('missing');
$this->action->execute($this->mapping, null, $this->request, $this->response);
$this->assertNotEmpty($this->response->getContent());
$this->assertEquals(400, $this->response->getStatusCode());
}
示例7: assertForm
/**
* @param Response $response
*/
protected function assertForm(Response $response)
{
$this->assertEquals(200, $response->getStatusCode());
$this->assertRegExp('/form/', $response->getContent());
$this->assertNotRegExp('/<html/', $response->getContent());
$this->assertNotRegExp('/_username/', $response->getContent());
}
示例8: assertJsonResponse
/**
* Check if the response is valid
* tests the status code, headers, and the content
* @param Response $response
* @param integer $statusCode
* @param boolean $checkValidJson
*/
protected function assertJsonResponse(Response $response, $statusCode, $checkValidJson = true)
{
$this->assertEquals($statusCode, $response->getStatusCode(), $response->getContent());
if ($checkValidJson) {
$this->assertTrue($response->headers->contains('Content-Type', 'application/json'), $response->headers);
$decode = json_decode($response->getContent());
$this->assertTrue($decode != null && $decode != false, 'Invalid JSON: [' . $response->getContent() . ']');
}
}
示例9: logReponse
/**
* Creates a json log file containing the request and the response contents.
*
* @param Request $request
* @param Response $response
*
* @return string The new mock file path
*/
public function logReponse(Request $request, Response $response)
{
$filename = $this->getFilePathByRequest($request);
$requestJsonContent = json_decode($request->getContent(), true);
$responseJsonContent = json_decode($response->getContent(), true);
$dumpFileContent = ['request' => ['uri' => $request->getRequestUri(), 'method' => $request->getMethod(), 'parameters' => $request->request->all(), 'content' => $requestJsonContent ?: $request->getContent()], 'response' => ['statusCode' => $response->getStatusCode(), 'contentType' => $response->headers->get('Content-Type'), 'content' => $responseJsonContent ?: $response->getContent()]];
$this->filesystem->dumpFile($this->mocksDir . $filename, self::jsonEncode($dumpFileContent, true));
return $this->mocksDir . $filename;
}
示例10: after
public function after(Request $request, Response $response)
{
$now = new \DateTime("now");
$mapper = new CacheRecordSQLMapper($this->app["db"]);
$currentRouteName = $request->attributes->get("_route");
if ($this->isCacheCompromiser($currentRouteName)) {
/** @todo method check */
$mapper = new CacheRecordSQLMapper($this->app["db"]);
$compromisedCount = $mapper->compromiseAll();
return;
}
if ($this->isRouteCacheable($currentRouteName) && $response->isOk()) {
$cacheRecord = $mapper->findByUri($this->getCurrentUri());
if (!$cacheRecord) {
// $this->createCacheRecord();
$data = [];
$data["uri"] = $this->getCurrentUri();
$data["hash"] = md5($response->getContent());
$data["lmt"] = $now->format("Y-m-d H:i:s");
$cacheRecord = new CacheRecord($data);
$mapper->create($cacheRecord);
$response->setPublic();
$response->setDate($now);
$response->setMaxAge($this->config->getMaxAge());
$response->setSharedMaxAge($this->config->getMaxAgeShared());
$response->setLastModified($now);
$response->headers->addCacheControlDirective('must-revalidate', true);
return $response;
}
if ($cacheRecord->getCompromised()) {
if ($cacheRecord->getHash() === md5($response->getContent())) {
$cacheRecord->setCompromised(false);
$mapper->update($cacheRecord->getId(), $cacheRecord);
$response = $this->createResponse($cacheRecord->getLmt());
$response->setNotModified();
return $response;
} else {
$cacheRecord->setCompromised(false);
$cacheRecord->setHash(md5($response->getContent()));
$cacheRecord->setLmt(date("Y-m-d H:i:s"));
$mapper->update($cacheRecord->getId(), $cacheRecord);
return $response;
}
} else {
$now = new \DateTime("2015-12-12");
$response->setPublic();
$response->setDate($now);
$response->setMaxAge($this->config->getMaxAge());
$response->setSharedMaxAge($this->config->getMaxAgeShared() + 1);
$response->setLastModified(new \DateTime($cacheRecord->getLmt()));
return $response;
}
}
}
示例11: handle
public function handle(HTTPApiClient $apiClient, Response $response, ClientRequest $clientRequest)
{
$responseArray = @json_decode($response->getContent(), true);
if (isset($responseArray['err_code'])) {
if ($responseArray['err_code'] == '0') {
return $response;
}
}
$e = new UnknownException($response->getContent());
$this->throwException($e, $response, $clientRequest);
}
示例12: getJsonObject
/**
* Return an object from a decoded response body.
*
* @return object
* @throws InvalidArgumentException
*/
public function getJsonObject($assoc, $depth, $options)
{
if (!preg_match(static::$jsonResponse, $this->response->headers->get('content-type'))) {
throw new InvalidArgumentException("JsonParser requires response with json content type");
}
$object = json_decode($this->response->getContent(), $assoc, $depth, $options);
$error = json_last_error();
if (JSON_ERROR_NONE !== $error) {
throw new InvalidArgumentException($this->transformError($error));
}
return $object;
}
示例13: store
/**
* {@inheritDoc}
*/
public function store(Response $response, $targetPath, $filter)
{
$storageResponse = $this->storage->create_object($this->bucket, $targetPath, array('body' => $response->getContent(), 'contentType' => $response->headers->get('Content-Type'), 'length' => strlen($response->getContent()), 'acl' => $this->acl));
if ($storageResponse->isOK()) {
$response->setStatusCode(301);
$response->headers->set('Location', $this->getObjectUrl($targetPath));
} else {
if ($this->logger) {
$this->logger->warn('The object could not be created on Amazon S3.', array('targetPath' => $targetPath, 'filter' => $filter, 's3_response' => $storageResponse));
}
}
return $response;
}
示例14: injectScript
/**
* Injects the livereload script.
*
* @param Response $response A Response instance
*/
protected function injectScript(Response $response)
{
if (function_exists('mb_stripos')) {
$posrFunction = 'mb_strripos';
$substrFunction = 'mb_substr';
} else {
$posrFunction = 'strripos';
$substrFunction = 'substr';
}
$content = $response->getContent();
$pos = $posrFunction($content, '</body>');
if (false !== $pos) {
$script = "livereload.js";
if ($this->checkServerPresence) {
// GET is required, as livereload apparently does not support HEAD requests ...
$request = $this->httpClient->get($script);
try {
$checkResponse = $this->httpClient->send($request);
if ($checkResponse->getStatusCode() !== 200) {
return;
}
} catch (CurlException $e) {
// If error is connection failed, we assume the server is not running
if ($e->getCurlHandle()->getErrorNo() === 7) {
return;
}
throw $e;
}
}
$content = $substrFunction($content, 0, $pos) . "\n" . '<script src="' . $this->httpClient->getBaseUrl() . $script . '"></script>' . "\n" . $substrFunction($content, $pos);
$response->setContent($content);
}
}
示例15: withContent
/**
* @Given /^with content:$/
*/
public function withContent(PyStringNode $content)
{
$expected = (string) $content;
if ($this->response->getContent() !== $expected) {
throw new \LogicException(sprintf('Content does not match, expected %s, but got a %s', $expected, $this->response->getContent()));
}
}