當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::getContent方法代碼示例

本文整理匯總了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;
 }
開發者ID:yasoon,項目名稱:yasoon,代碼行數:7,代碼來源:AuthControllerTest.php

示例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());
 }
開發者ID:luisbrito,項目名稱:Phraseanet,代碼行數:7,代碼來源:RSSFeedTest.php

示例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());
 }
開發者ID:kieljohn,項目名稱:TenantBundle,代碼行數:10,代碼來源:TenantBundleContext.php

示例4: testPlainRequest

 public function testPlainRequest()
 {
     $testBody = 'test';
     $this->response->setContent($testBody);
     $this->listener->onResponse($this->event);
     $this->assertEquals($testBody, $this->response->getContent());
 }
開發者ID:pierallard,項目名稱:pim-community-dev,代碼行數:7,代碼來源:ResponseHashnavListenerTest.php

示例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);
     }
 }
開發者ID:bcen,項目名稱:silex-dispatcher,代碼行數:27,代碼來源:Serializer.php

示例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());
 }
開發者ID:cammanderson,項目名稱:phruts,代碼行數:7,代碼來源:ActionDispatcherTest.php

示例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());
 }
開發者ID:open-orchestra,項目名稱:open-orchestra,代碼行數:10,代碼來源:AbstractFormTest.php

示例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() . ']');
     }
 }
開發者ID:profcab,項目名稱:ilios,代碼行數:16,代碼來源:JsonControllerTest.php

示例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;
 }
開發者ID:mRoca,項目名稱:MrocaRequestLogBundle,代碼行數:17,代碼來源:ResponseLogger.php

示例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;
         }
     }
 }
開發者ID:konstantin-s,項目名稱:silex-lazycache,代碼行數:54,代碼來源:LazyCache.php

示例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);
 }
開發者ID:xjtuwangke,項目名稱:laravel-bundles,代碼行數:11,代碼來源:Tui3ResponseMiddleware.php

示例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;
 }
開發者ID:peridot-php,項目名稱:leo-http-foundation,代碼行數:18,代碼來源:JsonParser.php

示例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;
 }
開發者ID:ashutosh-srijan,項目名稱:findit_akeneo,代碼行數:16,代碼來源:AmazonS3Resolver.php

示例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);
     }
 }
開發者ID:bakie,項目名稱:KunstmaanBundlesCMS,代碼行數:38,代碼來源:ScriptInjectorListener.php

示例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()));
     }
 }
開發者ID:bcen,項目名稱:silex-dispatcher,代碼行數:10,代碼來源:FeatureContext.php


注:本文中的Symfony\Component\HttpFoundation\Response::getContent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。