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


PHP StreamInterface::isWritable方法代码示例

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


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

示例1: getResource

 /**
  * Returns a resource representing the stream.
  *
  * @param StreamInterface $stream The stream to get a resource for
  *
  * @return resource
  * @throws \InvalidArgumentException if stream is not readable or writable
  */
 public static function getResource(StreamInterface $stream)
 {
     self::register();
     if ($stream->isReadable()) {
         $mode = $stream->isWritable() ? 'r+' : 'r';
     } elseif ($stream->isWritable()) {
         $mode = 'w';
     } else {
         throw new \InvalidArgumentException('The stream must be readable, ' . 'writable, or both.');
     }
     return fopen('guzzle://stream', $mode, null, stream_context_create(['guzzle' => ['stream' => $stream]]));
 }
开发者ID:Rayac,项目名称:search,代码行数:20,代码来源:StreamWrapper.php

示例2: send

 public function send(StreamInterface $stream)
 {
     if (!$stream->isWritable()) {
         throw new \InvalidArgumentException('Output stream must be writable');
     }
     if (is_array($this->callback)) {
         $ref = (new \ReflectionClass(is_object($this->callback[0]) ? get_class($this->callback[0]) : $this->callback[0]))->getMethod($this->callback[1]);
     } elseif (is_object($this->callback) && !$this->callback instanceof \Closure) {
         $ref = new \ReflectionMethod(get_class($this->callback), '__invoke');
     } else {
         $ref = new \ReflectionFunction($this->callback);
     }
     if ($ref->isGenerator()) {
         foreach (call_user_func($this->callback) as $chunk) {
             $stream->write($chunk);
         }
         return;
     }
     foreach ($ref->getParameters() as $param) {
         if (NULL !== ($type = $param->getClass())) {
             if ($type->name === StreamInterface::class || $type->implementsInterface(StreamInterface::class)) {
                 call_user_func($this->callback, $stream);
                 return;
             }
         }
         break;
     }
     $stream->write((string) call_user_func($this->callback));
 }
开发者ID:koolkode,项目名称:http,代码行数:29,代码来源:CallbackEntity.php

示例3: send

 public function send(StreamInterface $stream)
 {
     if (!$stream->isWritable()) {
         throw new \InvalidArgumentException('Output stream must be writable');
     }
     $stream->write($this->contents);
 }
开发者ID:koolkode,项目名称:http,代码行数:7,代码来源:StringEntity.php

示例4: __construct

 /**
  * Decorate the given output stream.
  * 
  * @param StreamInterface $stream
  * 
  * @throws \InvalidArgumentException When the given stream is not writable.
  */
 public function __construct(StreamInterface $stream)
 {
     if (!$stream->isWritable()) {
         throw new \InvalidArgumentException(sprintf('Decorated stream must be writable, given %s', get_class($stream)));
     }
     $this->stream = $stream;
 }
开发者ID:koolkode,项目名称:stream,代码行数:14,代码来源:AbstractOutputStream.php

示例5: send

 public function send(StreamInterface $stream)
 {
     if (!$stream->isWritable()) {
         throw new \InvalidArgumentException('Output stream must be writable');
     }
     while (!$this->stream->eof()) {
         $stream->write($this->stream->read(4096));
     }
 }
开发者ID:koolkode,项目名称:http,代码行数:9,代码来源:StreamEntity.php

示例6: send

 public function send(StreamInterface $stream)
 {
     if ($this->skipBinary) {
         return;
     }
     if (!$stream->isWritable()) {
         throw new \InvalidArgumentException('Output stream must be writable');
     }
     $in = ResourceInputStream::fromUrl($this->file->getPathname());
     try {
         while (!$in->eof()) {
             $stream->write($in->read(4096));
         }
     } finally {
         $in->close();
     }
 }
开发者ID:koolkode,项目名称:http,代码行数:17,代码来源:FileEntity.php

示例7: sendData

 protected function sendData(StreamInterface $stream, $prefix, array $data)
 {
     if (!$stream->isWritable()) {
         throw new \InvalidArgumentException('Output stream must be writable');
     }
     foreach ($data as $k => $v) {
         if (is_numeric($k)) {
             $field = $prefix == '' ? $k : sprintf('%s[]', $prefix);
         } else {
             $field = $prefix == '' ? new UnicodeString($k) : sprintf('%s[%s]', $prefix, new UnicodeString($k));
         }
         if (is_array($v)) {
             $this->sendData($stream, $field, $v);
         } else {
             $stream->write(sprintf("--%s\r\n", $this->boundary));
             if ($v instanceof UploadedFileInterface) {
                 $filename = new UnicodeString($v->getFileName());
                 $type = $v->getMediaType();
                 $in = $v->getInputStream();
                 $stream->write(sprintf('Content-Disposition: form-data; name="%s"; filename="%s"; charset="utf-8"', $field, $filename));
                 $stream->write(sprintf("\r\nContent-Type: %s\r\n", $type));
                 $stream->write("Content-Transfer-Encoding: binary\r\n");
                 $stream->write("\r\n");
                 while (false !== ($chunk = $in->read())) {
                     $stream->write($chunk);
                 }
                 $stream->write("\r\n");
             } else {
                 $stream->write(sprintf('Content-Disposition: form-data; name="%s"; charset="utf-8"', $field));
                 $stream->write("\r\n\r\n");
                 $stream->write(new UnicodeString($v));
                 $stream->write("\r\n");
             }
         }
     }
 }
开发者ID:koolkode,项目名称:http,代码行数:36,代码来源:MultipartFormEntity.php

示例8: pipe

 /**
  * Pipe data from an input stream into an output stream.
  * 
  * @param StreamInterface $in
  * @param StreamInterface $out
  * @param int $chunkSize Maximum chunk size being used during copy.
  * @return int Number of bytes being copied.
  * 
  * @throws \InvalidArgumentException When input stream is not readable or output stream is not writable.
  */
 public static function pipe(StreamInterface $in, StreamInterface $out, $chunkSize = 8192)
 {
     if (!$in->isReadable()) {
         throw new \InvalidArgumentException(sprintf('Input stream is not readable: %s', get_class($in)));
     }
     if (!$out->isWritable()) {
         throw new \InvalidArgumentException(sprintf('Output stream is not writable: %s', get_class($out)));
     }
     $size = 0;
     while (!$in->eof()) {
         $size += $out->write($in->read($chunkSize));
     }
     return $size;
 }
开发者ID:koolkode,项目名称:stream,代码行数:24,代码来源:Stream.php

示例9: isWritable

 /**
  * {@inheritdoc}
  */
 public function isWritable()
 {
     return $this->stream->isWritable();
 }
开发者ID:narrowspark,项目名称:framework,代码行数:7,代码来源:AbstractStreamDecorator.php

示例10: isWritable

 /**
  * {@inheritdoc}
  */
 public function isWritable()
 {
     return $this->decoratedStream->isWritable();
 }
开发者ID:zendframework,项目名称:zend-diactoros,代码行数:7,代码来源:RelativeStream.php

示例11: getResource

 /**
  * Create StreamInterface associated resource.
  *
  * @param StreamInterface $stream
  * @return resource
  * @throws WrapperException
  */
 public static function getResource(StreamInterface $stream)
 {
     $mode = null;
     if ($stream->isReadable()) {
         $mode = 'r';
     }
     if ($stream->isWritable()) {
         $mode = !empty($mode) ? 'r+' : 'w';
     }
     if (empty($mode)) {
         throw new WrapperException("Stream is not available in read or write modes.");
     }
     return fopen(self::getUri($stream), $mode);
 }
开发者ID:tuneyourserver,项目名称:components,代码行数:21,代码来源:StreamWrapper.php

示例12: runMatches

 protected function runMatches(StreamInterface $stream)
 {
     return $stream->isWritable();
 }
开发者ID:oscarotero,项目名称:psr7-unitesting,代码行数:4,代码来源:IsWritable.php

示例13: testCheckMethods

 public function testCheckMethods()
 {
     $this->assertEquals($this->a->isReadable(), $this->b->isReadable());
     $this->assertEquals($this->a->isWritable(), $this->b->isWritable());
     $this->assertEquals($this->a->isSeekable(), $this->b->isSeekable());
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:6,代码来源:StreamDecoratorTraitTest.php


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