[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/laminas/laminas-diactoros/src/ -> StreamFactory.php (source)

   1  <?php
   2  
   3  /**
   4   * @see       https://github.com/laminas/laminas-diactoros for the canonical source repository
   5   * @copyright https://github.com/laminas/laminas-diactoros/blob/master/COPYRIGHT.md
   6   * @license   https://github.com/laminas/laminas-diactoros/blob/master/LICENSE.md New BSD License
   7   */
   8  
   9  declare(strict_types=1);
  10  
  11  namespace Laminas\Diactoros;
  12  
  13  use Psr\Http\Message\StreamFactoryInterface;
  14  use Psr\Http\Message\StreamInterface;
  15  
  16  use function fopen;
  17  use function fwrite;
  18  use function get_resource_type;
  19  use function is_resource;
  20  use function rewind;
  21  
  22  class StreamFactory implements StreamFactoryInterface
  23  {
  24      /**
  25       * {@inheritDoc}
  26       */
  27      public function createStream(string $content = '') : StreamInterface
  28      {
  29          $resource = fopen('php://temp', 'r+');
  30          fwrite($resource, $content);
  31          rewind($resource);
  32  
  33          return $this->createStreamFromResource($resource);
  34      }
  35  
  36      /**
  37       * {@inheritDoc}
  38       */
  39      public function createStreamFromFile(string $file, string $mode = 'r') : StreamInterface
  40      {
  41          return new Stream($file, $mode);
  42      }
  43  
  44      /**
  45       * {@inheritDoc}
  46       */
  47      public function createStreamFromResource($resource) : StreamInterface
  48      {
  49          return new Stream($resource);
  50      }
  51  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer