本文整理汇总了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]]));
}
示例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));
}
示例3: send
public function send(StreamInterface $stream)
{
if (!$stream->isWritable()) {
throw new \InvalidArgumentException('Output stream must be writable');
}
$stream->write($this->contents);
}
示例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;
}
示例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));
}
}
示例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();
}
}
示例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");
}
}
}
}
示例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;
}
示例9: isWritable
/**
* {@inheritdoc}
*/
public function isWritable()
{
return $this->stream->isWritable();
}
示例10: isWritable
/**
* {@inheritdoc}
*/
public function isWritable()
{
return $this->decoratedStream->isWritable();
}
示例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);
}
示例12: runMatches
protected function runMatches(StreamInterface $stream)
{
return $stream->isWritable();
}
示例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());
}