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


PHP ResponseInterface::withBody方法代码示例

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


在下文中一共展示了ResponseInterface::withBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 /**
  * Create response.
  * @param  FilesystemInterface $cache Cache file system.
  * @param  string              $path  Cached file path.
  * @return Response            Response object.
  */
 public function create(FilesystemInterface $cache, $path)
 {
     $stream = $this->streamCallback->__invoke($cache->readStream($path));
     $contentType = $cache->getMimetype($path);
     $contentLength = (string) $cache->getSize($path);
     $cacheControl = 'max-age=31536000, public';
     $expires = date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT';
     return $this->response->withBody($stream)->withHeader('Content-Type', $contentType)->withHeader('Content-Length', $contentLength)->withHeader('Cache-Control', $cacheControl)->withHeader('Expires', $expires);
 }
开发者ID:whismat,项目名称:glide,代码行数:15,代码来源:PsrResponseFactory.php

示例2: create

 /**
  * Create response.
  * @param  FilesystemInterface $cache Cache file system.
  * @param  string              $path  Cached file path.
  * @return ResponseInterface   Response object.
  */
 public function create(FilesystemInterface $cache, $path)
 {
     $stream = $this->streamCallback->__invoke($cache->readStream($path));
     $contentType = $cache->getMimetype($path);
     $contentLength = (string) $cache->getSize($path);
     $cacheControl = 'max-age=31536000, public';
     $expires = date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT';
     if ($contentType === false) {
         throw new FilesystemException('Unable to determine the image content type.');
     }
     if ($contentLength === false) {
         throw new FilesystemException('Unable to determine the image content length.');
     }
     return $this->response->withBody($stream)->withHeader('Content-Type', $contentType)->withHeader('Content-Length', $contentLength)->withHeader('Cache-Control', $cacheControl)->withHeader('Expires', $expires);
 }
开发者ID:mambax7,项目名称:glide,代码行数:21,代码来源:PsrResponseFactory.php

示例3: render

 public function render(ResponseInterface $response, $templateName, array $data = [])
 {
     $source = $this->fetch($templateName, $data);
     $body = $response->getBody();
     $body->write($source);
     return $response->withBody($body);
 }
开发者ID:marihachi,项目名称:slim3-jade,代码行数:7,代码来源:JadeRenderer.php

示例4: __wakeup

 public function __wakeup()
 {
     // We re-create the stream of the response
     if ($this->response !== null) {
         $this->response = $this->response->withBody(\GuzzleHttp\Psr7\stream_for($this->responseBody));
     }
 }
开发者ID:kevinrob,项目名称:guzzle-cache-middleware,代码行数:7,代码来源:CacheEntry.php

示例5: withBody

 /**
  * Proxy to PsrResponseInterface::withBody()
  *
  * {@inheritdoc}
  */
 public function withBody(StreamInterface $body)
 {
     if ($this->complete) {
         return $this;
     }
     $new = $this->psrResponse->withBody($body);
     return new self($new);
 }
开发者ID:fabiocarneiro,项目名称:zend-stratigility,代码行数:13,代码来源:Response.php

示例6: withBody

 /**
  * Proxy to PsrResponseInterface::withBody()
  *
  * {@inheritdoc}
  * @throws RuntimeException if response is already completed
  */
 public function withBody(StreamInterface $body)
 {
     if ($this->complete) {
         throw $this->responseIsAlreadyCompleted(__METHOD__);
     }
     $new = $this->psrResponse->withBody($body);
     return new self($new);
 }
开发者ID:michaelmoussa,项目名称:zend-stratigility,代码行数:14,代码来源:Response.php

示例7: transform

 /**
  * Transform the image.
  * 
  * @param ResponseInterface $response
  * @param string            $transform
  * 
  * @return ResponseInterface
  */
 private function transform(ResponseInterface $response, $transform)
 {
     $image = Image::createFromString((string) $response->getBody());
     $image->transform($transform);
     $body = Middleware::createStream();
     $body->write($image->getString());
     return $response->withBody($body)->withHeader('Content-Type', $image->getMimeType());
 }
开发者ID:basz,项目名称:psr7-middlewares,代码行数:16,代码来源:ImageTransformer.php

示例8: marshalResponse

 public function marshalResponse(ViewModelInterface $model, ResponseInterface $response)
 {
     $template = $model->getTemplate();
     $vars = $model->getVariables();
     $stream = $response->getBody()->detach();
     $this->assign($vars);
     $this->render($template, $stream);
     return $response->withBody(new Stream($stream));
 }
开发者ID:ReKungPaw,项目名称:Backbeard,代码行数:9,代码来源:View.php

示例9: __invoke

 /**
  * Execute the middleware.
  *
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  * @param callable          $next
  *
  * @return ResponseInterface
  */
 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
 {
     if ($request->getUri()->getPath() === '/robots.txt') {
         $body = Middleware::createStream();
         $body->write("User-Agent: *\nDisallow: /");
         return $response->withBody($body);
     }
     $response = $next($request, $response);
     return $response->withHeader(self::HEADER, 'noindex, nofollow, noarchive');
 }
开发者ID:jordiwes,项目名称:psr7-middlewares,代码行数:19,代码来源:Robots.php

示例10: fetchFromCache

 private function fetchFromCache(string $id, Response $res)
 {
     $cachePath = sprintf('%s/%s', $this->cachePath, $id);
     if (!file_exists($cachePath)) {
         // Nothing in cache, but should be cached
         return false;
     }
     // Cache hit!
     return $res->withBody(new Stream(fopen($cachePath, 'r')));
 }
开发者ID:vrkansagara,项目名称:mwop.net,代码行数:10,代码来源:CachingMiddleware.php

示例11: insertIntoPostForms

 /**
  * Insert content into all POST forms.
  *
  * @param ResponseInterface $response
  * @param callable          $replace
  *
  * @return ResponseInterface
  */
 private function insertIntoPostForms(ResponseInterface $response, callable $replace)
 {
     $html = (string) $response->getBody();
     $html = preg_replace_callback('/(<form\\s[^>]*method=["\']?POST["\']?[^>]*>)/i', $replace, $html, -1, $count);
     if (!empty($count)) {
         $body = self::createStream();
         $body->write($html);
         return $response->withBody($body);
     }
     return $response;
 }
开发者ID:oscarotero,项目名称:psr7-middlewares,代码行数:19,代码来源:FormTrait.php

示例12: __invoke

 /**
  * Execute the middleware.
  *
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  * @param callable          $next
  *
  * @return ResponseInterface
  */
 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
 {
     if ($request->getMethod() !== 'GET') {
         return $response->withStatus(405);
     }
     $file = $this->getFilename($request);
     if (!is_file($file)) {
         return $response->withStatus(404);
     }
     return $next($request, $response->withBody(Middleware::createStream($file)));
 }
开发者ID:jordiwes,项目名称:psr7-middlewares,代码行数:20,代码来源:ReadResponse.php

示例13: __invoke

 /**
  * Process an incoming error, along with associated request and response.
  *
  * Accepts an error, a server-side request, and a response instance, and
  * does something with them; if further processing can be done, it can
  * delegate to `$out`.
  *
  * @see MiddlewareInterface
  * @param mixed $error
  * @param Request $request
  * @param Response $response
  * @param null|callable $out
  * @return null|Response
  */
 public function __invoke($error, Request $request, Response $response, callable $out = null)
 {
     //Show error in browser if display_errors is on in php.ini
     if ($this->displayErrors) {
         $body = $response->getBody();
         $body->write($error);
         return $response->withBody($body);
     }
     $body = $response->getBody();
     $body->write('500 Internal Server Error');
     return $response->withStatus(500)->withBody($body);
 }
开发者ID:reliv,项目名称:pipe-rat,代码行数:26,代码来源:NonThrowingErrorHandler.php

示例14: inject

 /**
  * Inject some code just before any tag.
  *
  * @param ResponseInterface $response
  * @param string            $code
  * @param string            $tag
  *
  * @return ResponseInterface
  */
 private function inject(ResponseInterface $response, $code, $tag = 'body')
 {
     $html = (string) $response->getBody();
     $pos = strripos($html, "</{$tag}>");
     if ($pos === false) {
         $response->getBody()->write($code);
         return $response;
     }
     $body = self::createStream();
     $body->write(substr($html, 0, $pos) . $code . substr($html, $pos));
     return $response->withBody($body);
 }
开发者ID:oscarotero,项目名称:psr7-middlewares,代码行数:21,代码来源:HtmlInjectorTrait.php

示例15: after

 public function after(ResponseInterface $response)
 {
     if (config('micro_debug.handlers.fire_php')) {
         $db = \app('db');
         if ($db) {
             $profiler = $db->getProfiler();
             if ($profiler->getEnabled()) {
                 $totalTime = $profiler->getTotalElapsedSecs();
                 $queryCount = $profiler->getTotalNumQueries();
                 $longestTime = 0;
                 $longestQuery = \null;
                 $total = sprintf('%.6f', microtime(\true) - $_SERVER['REQUEST_TIME_FLOAT']);
                 $label = 'Executed ' . $queryCount . ' queries in ' . sprintf('%.6f', $totalTime) . ' seconds. (' . ($total ? \round($totalTime / $total * 100, 2) : 0) . '%)';
                 $table = [];
                 $table[] = ['Time', 'Event', 'Parameters'];
                 if ($profiler->getQueryProfiles()) {
                     foreach ($profiler->getQueryProfiles() as $k => $query) {
                         if ($query->getElapsedSecs() > $longestTime) {
                             $longestTime = $query->getElapsedSecs();
                             $longestQuery = $k;
                         }
                     }
                     foreach ($profiler->getQueryProfiles() as $k => $query) {
                         $table[] = [\sprintf('%.6f', $query->getElapsedSecs()) . ($k == $longestQuery ? ' !!!' : ''), $query->getQuery(), ($params = $query->getQueryParams()) ? $params : \null];
                     }
                 }
                 FirePHP\FirePHP::getInstance()->table('DB - ' . $label, $table);
             }
         }
     }
     if (\config('micro_debug.handlers.dev_tools')) {
         if ($response instanceof HtmlResponse) {
             $body = $response->getBody();
             if ($body->isSeekable()) {
                 $body->rewind();
             }
             $b = $body->getContents();
             $b = explode('</body>', $b);
             $b[0] .= str_replace(array("\n", "\t", "\r"), "", $this->view->render()) . '</body>';
             $response->withBody(new TempStream(implode('', $b)));
         }
     }
     if (($fileForCache = \config('micro_debug.handlers.performance')) !== \null) {
         $forStore = [];
         foreach (\MicroLoader::getFiles() as $class => $file) {
             if (\substr($class, 0, 6) === 'Micro\\') {
                 $forStore[$class] = $file;
             }
         }
         \file_put_contents($fileForCache, "<?php\nreturn " . \var_export($forStore, \true) . ";", \LOCK_EX);
     }
     return $response;
 }
开发者ID:control-corp,项目名称:micro,代码行数:53,代码来源:DevTools.php


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