コード例 #1
1
 /**
  * Prepare the PJAX-specific response content.
  *
  * @param Response $response
  * @param string   $container
  *
  * @return $this
  */
 protected function filterResponse(Response $response, $container)
 {
     if (!$response->isSuccessful()) {
         $crawler = new Crawler($response->getContent());
         $response->setContent($this->fetchContents($crawler, '.exception_message'));
         return $this;
     }
     $crawler = new Crawler($response->getContent());
     $response->setContent($this->makeTitle($crawler) . $this->fetchContents($crawler, $container));
     return $this;
 }
コード例 #2
0
 /**
  * @param \Illuminate\Http\Response $response
  *
  * @return $this
  */
 protected function addCookieConsentScriptToResponse(Response $response)
 {
     $content = $response->getContent();
     $closingBodyTagPosition = $this->getLastClosingBodyTagPosition($content);
     $content = '' . substr($content, 0, $closingBodyTagPosition) . view('cookieConsent::index')->render() . substr($content, $closingBodyTagPosition);
     return $response->setContent($content);
 }
コード例 #3
0
 /**
  * Get the DomCrawler instance.
  *
  * @param \Illuminate\Http\Response $response
  *
  * @return \Symfony\Component\DomCrawler\Crawler
  */
 protected function getCrawler(Response $response)
 {
     if ($this->crawler) {
         return $this->crawler;
     }
     return $this->crawler = new Crawler($response->getContent());
 }
コード例 #4
0
ファイル: Handler.php プロジェクト: hrslash/luminous
 /**
  * Render an exception into a response.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Exception $exception
  * @return \Illuminate\Http\Response
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function render($request, Exception $exception)
 {
     $response = (new SymfonyExceptionHandler(env('APP_DEBUG', false)))->createResponse($exception);
     $response = new Response($response->getContent(), $response->getStatusCode(), $response->headers->all());
     $response->exception = $exception;
     return $response;
 }
コード例 #5
0
    /**
     * Append disqus script on the end of the page.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Illuminate\Http\Response $response
     * @return mixed
     */
    protected function appendDisqusScript($request, $response)
    {
        $content = $response->getContent();
        if (!Str::contains($content, '<div id="disqus_thread"></div>')) {
            return;
        }
        $uri = $request->getRequestUri();
        $pageUrl = url($uri);
        $pageId = 'route' . implode('.', explode('/', $uri));
        $username = config('disqus.username');
        $disqusHtml = <<<CDATA
<script>
     var disqus_config = function () {
         this.page.url = '{$pageUrl}';
         this.page.identifier = '{$pageId}';
     };

    (function() {  // DON'T EDIT BELOW THIS LINE
        var d = document, s = d.createElement('script');

        s.src = '//{$username}.disqus.com/embed.js';

        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href=\\"https://disqus.com/?ref_noscript\\" rel=\\"nofollow\\">comments powered by Disqus.</a></noscript>
CDATA;
        $bodyPosition = strripos($content, '</body>');
        if (false !== $bodyPosition) {
            $content = substr($content, 0, $bodyPosition) . $disqusHtml . substr($content, $bodyPosition);
        }
        $response->setContent($content);
    }
コード例 #6
0
 /**
  * Serialize a response.
  *
  * @param \Illuminate\Http\Response $response
  *
  * @return string
  */
 public function serialize(Response $response)
 {
     $content = $response->getContent();
     $statusCode = $response->getStatusCode();
     $headers = $response->headers;
     return serialize(compact('content', 'statusCode', 'headers'));
 }
コード例 #7
0
 /**
  * Make a request to the application and create a Crawler instance.
  *
  * @param  string $method
  * @param  string $uri
  * @param  array $parameters
  * @param  array $cookies
  * @param  array $files
  *
  * @return $this
  */
 protected function makeRequest($method, $uri, $parameters = [], $cookies = [], $files = [])
 {
     $uri = $this->prepareUrlForRequest($uri);
     $this->call($method, $uri, $parameters, $cookies, $files);
     $this->clearInputs()->followRedirects()->assertPageLoaded($uri);
     $this->currentUri = $this->app->make('request')->fullUrl();
     $this->crawler = new Crawler($this->response->getContent(), $uri);
     return $this;
 }
コード例 #8
0
ファイル: PjaxMiddleware.php プロジェクト: projnoah/noah
 /**
  * Prepare the PJAX-specific response content.
  *
  * @param  Response $response
  * @param  string   $container
  * @return $this
  */
 protected function filterResponse(Response $response, $container)
 {
     $crawler = new Crawler($response->getContent());
     $response->setContent($this->makeTitle($crawler) . $this->fetchContents($crawler, $container));
     if ($crawler->filter('script[pjax-script]')->count() > 0) {
         $response->header('X-PJAX-Script', $crawler->filter('script[pjax-script]')->attr('src'));
     }
     return $this;
 }
コード例 #9
0
 /**
  * Assert that the response contains the given JSON.
  *
  * @param  array  $data
  * @return $this
  */
 protected function seeJsonContains(array $data)
 {
     $actual = json_encode(array_sort_recursive(json_decode($this->response->getContent(), true)));
     foreach (array_sort_recursive($data) as $key => $value) {
         $expected = $this->formatToExpectedJson($key, $value);
         $this->assertTrue(str_contains($actual, $this->formatToExpectedJson($key, $value)), "Unable to find JSON fragment [{$expected}] within [{$actual}].");
     }
     return $this;
 }
コード例 #10
0
 /**
  * Dump the content from the last response.
  *
  * @return void
  */
 public function dump()
 {
     $content = $this->response->getContent();
     $json = json_decode($content);
     if (json_last_error() === JSON_ERROR_NONE) {
         $content = $json;
     }
     dd($content);
 }
コード例 #11
0
ファイル: CodexDev.php プロジェクト: codexproject/core
 /**
  * @param \Illuminate\Http\Response $response
  */
 protected function handleDebugbar($response)
 {
     $content = $response->getContent();
     $assets = ['debugbar.css', 'codex-debugbar.css'];
     $out = '';
     foreach ($assets as $style) {
         $out .= '<link type="text/css" rel="stylesheet" href="' . asset('vendor/codex-dev/' . $style) . '"/>';
     }
     $content = str_replace('</body>', $out . '</body>', $content);
     $response->setContent($content);
 }
コード例 #12
0
ファイル: MailDebug.php プロジェクト: laravelflare/mail-debug
 /**
  * Injects the Mail Debug Popup into the Response.
  *
  * @param \Illuminate\Http\Response
  */
 protected function appendToResponse(Response $response)
 {
     $existingContent = $response->getContent();
     $closeBodyPosition = strripos($existingContent, '</body>');
     $appendedContent = "\n            <script>\n                window.open('" . route('mail-debug', ['file' => $this->debug->preview()]) . "','width=680,height=800,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');\n            </script>";
     if ($closeBodyPosition !== false) {
         $response->setContent(substr($existingContent, 0, $closeBodyPosition) . $appendedContent . substr($existingContent, $closeBodyPosition));
         return;
     }
     $response->setContent($existingContent . $appendedContent);
 }
コード例 #13
0
 /**
  * Convert the given response into a TestResponse.
  *
  * @param  \Illuminate\Http\Response  $response
  * @return static
  */
 public static function fromBaseResponse($response)
 {
     $testResponse = new static($response->getContent(), $response->status());
     $testResponse->headers = $response->headers;
     if (isset($response->original)) {
         $testResponse->original = $response->original;
     }
     if (isset($response->exception)) {
         $testResponse->exception = $response->exception;
     }
     return $testResponse;
 }
コード例 #14
0
 /**
  * Assert that the response contains the given JSON.
  *
  * @param  array  $data
  * @param  bool  $negate
  * @return $this
  */
 protected function seeJsonContains(array $data, $negate = false)
 {
     $method = $negate ? 'assertFalse' : 'assertTrue';
     $actual = json_decode($this->response->getContent(), true);
     if (is_null($actual) || $actual === false) {
         return $this->fail('Invalid JSON was returned from the route. Perhaps an exception was thrown?');
     }
     $actual = json_encode(array_sort_recursive((array) $actual));
     foreach (array_sort_recursive($data) as $key => $value) {
         $expected = $this->formatToExpectedJson($key, $value);
         $this->{$method}(Str::contains($actual, $expected), ($negate ? 'Found unexpected' : 'Unable to find') . " JSON fragment [{$expected}] within [{$actual}].");
     }
     return $this;
 }
コード例 #15
0
ファイル: Handler.php プロジェクト: notadd/framework
 /**
  * @param \Symfony\Component\HttpFoundation\Response $response
  * @param \Exception                                 $exception
  *
  * @return \Illuminate\Http\Response
  */
 protected function toIlluminateResponse($response, Exception $exception)
 {
     if ($response instanceof SymfonyRedirectResponse) {
         $response = new RedirectResponse($response->getTargetUrl(), $response->getStatusCode(), $response->headers->all());
     } else {
         $response = new Response($response->getContent(), $response->getStatusCode(), $response->headers->all());
     }
     return $response->withException($exception);
 }
コード例 #16
0
 /**
  * Read JSON-API string in given response, validate response,
  * return document.
  * @param Response $response
  * @return Document
  * @throws \RuntimeException
  */
 public function deserializeResponse(Response $response)
 {
     $data = $response->getContent();
     $this->validator->validateResponse($response);
     return $this->deserialize($data);
 }
コード例 #17
0
ファイル: JsonLapiFormatHandler.php プロジェクト: kyjan/lapi
 /**
  * Encodes the given data to a specific data format.
  *
  * @param array $data
  *
  * @return string
  */
 public function format(array $data)
 {
     $res = new Response($data);
     return $res->getContent();
 }
コード例 #18
0
 /**
  * Creates PSR 7 response object from Laravel response.
  *
  * @param  Response  $response
  *
  * @return ResponseInterface
  */
 protected function createPsr7Response(Response $response)
 {
     return new PsrResponse($response->getStatusCode(), $response->headers->all(), $response->getContent(), $response->getProtocolVersion());
 }
コード例 #19
0
 /**
  * @param Response $response
  */
 public function setCacheFromResponse(Response $response)
 {
     $this->setCacheFromContent($response->getContent());
 }
コード例 #20
0
ファイル: Middleware.php プロジェクト: timgws/laravel-pjax
 /**
  * Get only the content we care about
  *
  * @param Response $response
  * @return string html content to send.
  */
 private function getContent(Response $response)
 {
     // Get the full response
     $content = $response->getContent();
     // Get the XML document
     $document = $this->getDocument($content);
     /**
      * Create a new HTML document with only the extracted content
      */
     return $this->getTitle($document) . $this->getNewDocumentContent($document);
 }
コード例 #21
0
ファイル: Lari18n.php プロジェクト: nicolasbeauvais/lari18n
 /**
  * Attach the toolbar dom to the laravel answer.
  *
  * @param Response $response
  */
 public function injectToolbar(Response $response)
 {
     $content = $response->getContent();
     $renderedContent = '<script type="text/javascript" src="' . $this->paths['js'] . 'lari18n.js' . '"></script>';
     $pos = strripos($content, '</body>');
     if ($pos !== false) {
         $content = substr($content, 0, $pos) . $renderedContent . substr($content, $pos);
     } else {
         $content = $content . $renderedContent;
     }
     $response->setContent($content);
 }
コード例 #22
0
 /**
  * Prepare the PJAX-specific response content.
  *
  * @param  Response $response
  * @param  string   $container
  * @return $this
  */
 protected function filterResponse(Response $response, $container)
 {
     $crawler = new Crawler($response->getContent());
     $response->setContent($this->makeTitle($crawler) . $this->fetchContents($crawler, $container));
     return $this;
 }
コード例 #23
0
 /**
  * Cache the response to a file.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Illuminate\Http\Response  $response
  * @return void
  */
 protected function cacheResponse($request, $response)
 {
     list($path, $file) = $this->getDirectoryAndFileNames($request);
     $this->files->makeDirectory($path, 0775, true, true);
     $this->files->put($path . $file, $response->getContent());
 }
コード例 #24
0
ファイル: FilterIfPjax.php プロジェクト: spatie/laravel-pjax
 /**
  * Make the content of the given response lowercase.
  *
  * @param \Illuminate\Http\Response $response
  *
  * @return \Illuminate\Http\Response
  */
 protected function createResponseWithLowerCaseContent(Response $response)
 {
     $lowercaseContent = strtolower($response->getContent());
     return Response::create($lowercaseContent);
 }
コード例 #25
0
ファイル: Handler.php プロジェクト: hilmysyarif/sisfito
 /**
  * Map exception into an illuminate response.
  *
  * @param  \Symfony\Component\HttpFoundation\Response  $response
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 protected function toIlluminateResponse($response, Exception $e)
 {
     $response = new Response($response->getContent(), $response->getStatusCode(), $response->headers->all());
     $response->exception = $e;
     return $response;
 }
コード例 #26
0
ファイル: Flatten.php プロジェクト: onefasteuro/flattnr
 /**
  *
  * Cache the response
  *
  * @response		final response
  *
  **/
 public function write(Response $response = NULL)
 {
     //only cache 200 OK response, do not cache errors and 404, 500...
     if ($response->getStatusCode() == 200) {
         $content = $response->getContent();
         $this->writeCache($content);
     }
 }
コード例 #27
0
ファイル: Agent.php プロジェクト: daylerees/anbu-agent
 /**
  * Attach a report link to the view.
  *
  * @param \Illuminate\Http\Response $response
  */
 protected function attachLink($response)
 {
     /**
      * We only attach the button to HTML responses.
      */
     $contentType = $response->headers->get('Content-Type');
     if (str_contains($contentType, 'text/html')) {
         $response->setContent($response->getContent() . $this->fetchButtonHtml());
     }
 }
コード例 #28
-1
 protected function makeMessageFromResponse(Response $response)
 {
     $message['original_content'] = $response->getOriginalContent();
     $message['content'] = $response->getContent();
     $message['status_code'] = $response->getStatusCode();
     return json_encode($message, JSON_PRETTY_PRINT);
 }
コード例 #29
-3
ファイル: CacheFilter.php プロジェクト: seivad/nnt
 public function put(Route $route, Request $request, Response $response)
 {
     $key = $this->makeCacheKey($request->url());
     var_dump($response->getContent());
     if (!Cache::has($key)) {
         Cache::put($key, $response->getContent(), 1440);
     }
 }