PHP 8.1.33
Preview: CallbackStream.php Size: 3.35 KB
/home/jambtst2015/public_html/ida.com.ng/libraries/vendor/laminas/laminas-diactoros/src/CallbackStream.php

<?php

/**
 * @see       https://github.com/laminas/laminas-diactoros for the canonical source repository
 * @copyright https://github.com/laminas/laminas-diactoros/blob/master/COPYRIGHT.md
 * @license   https://github.com/laminas/laminas-diactoros/blob/master/LICENSE.md New BSD License
 */

declare(strict_types=1);

namespace Laminas\Diactoros;

use Psr\Http\Message\StreamInterface;

use function array_key_exists;

use const SEEK_SET;

/**
 * Implementation of PSR HTTP streams
 */
class CallbackStream implements StreamInterface
{
    /**
     * @var callable|null
     */
    protected $callback;

    /**
     * @param callable $callback
     * @throws Exception\InvalidArgumentException
     */
    public function __construct(callable $callback)
    {
        $this->attach($callback);
    }

    /**
     * {@inheritdoc}
     */
    public function __toString() : string
    {
        return $this->getContents();
    }

    /**
     * {@inheritdoc}
     */
    public function close() : void
    {
        $this->callback = null;
    }

    /**
     * {@inheritdoc}
     */
    public function detach() : ?callable
    {
        $callback = $this->callback;
        $this->callback = null;
        return $callback;
    }

    /**
     * Attach a new callback to the instance.
     */
    public function attach(callable $callback) : void
    {
        $this->callback = $callback;
    }

    /**
     * {@inheritdoc}
     */
    public function getSize() : ?int
    {
        return null;
    }

    /**
     * {@inheritdoc}
     */
    public function tell() : int
    {
        throw Exception\UntellableStreamException::forCallbackStream();
    }

    /**
     * {@inheritdoc}
     */
    public function eof() : bool
    {
        return empty($this->callback);
    }

    /**
     * {@inheritdoc}
     */
    public function isSeekable() : bool
    {
        return false;
    }

    /**
     * {@inheritdoc}
     */
    public function seek($offset, $whence = SEEK_SET)
    {
        throw Exception\UnseekableStreamException::forCallbackStream();
    }

    /**
     * {@inheritdoc}
     */
    public function rewind() : void
    {
        throw Exception\UnrewindableStreamException::forCallbackStream();
    }

    /**
     * {@inheritdoc}
     */
    public function isWritable() : bool
    {
        return false;
    }

    /**
     * {@inheritdoc}
     */
    public function write($string) : void
    {
        throw Exception\UnwritableStreamException::forCallbackStream();
    }

    /**
     * {@inheritdoc}
     */
    public function isReadable() : bool
    {
        return false;
    }

    /**
     * {@inheritdoc}
     */
    public function read($length) : string
    {
        throw Exception\UnreadableStreamException::forCallbackStream();
    }

    /**
     * {@inheritdoc}
     */
    public function getContents() : string
    {
        $callback = $this->detach();
        $contents = $callback ? $callback() : '';
        return (string) $contents;
    }

    /**
     * {@inheritdoc}
     */
    public function getMetadata($key = null)
    {
        $metadata = [
            'eof' => $this->eof(),
            'stream_type' => 'callback',
            'seekable' => false
        ];

        if (null === $key) {
            return $metadata;
        }

        if (! array_key_exists($key, $metadata)) {
            return null;
        }

        return $metadata[$key];
    }
}

Directory Contents

Dirs: 4 × Files: 21

Name Size Perms Modified Actions
Exception DIR
- drwxr-xr-x 2024-11-22 17:53:12
Edit Download
functions DIR
- drwxr-xr-x 2024-11-22 17:53:12
Edit Download
Request DIR
- drwxr-xr-x 2024-11-22 17:53:12
Edit Download
Response DIR
- drwxr-xr-x 2024-11-22 17:53:12
Edit Download
4.48 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
3.35 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
1.54 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
5.31 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
12.63 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
521 B lrw-r--r-- 2024-11-22 17:53:12
Edit Download
1.80 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
3.76 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
2.07 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
662 B lrw-r--r-- 2024-11-22 17:53:12
Edit Download
9.96 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
5.88 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
727 B lrw-r--r-- 2024-11-22 17:53:12
Edit Download
6.44 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
3.02 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
8.60 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
1.22 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
7.49 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
1.02 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
17.34 KB lrw-r--r-- 2024-11-22 17:53:12
Edit Download
621 B lrw-r--r-- 2024-11-22 17:53:12
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).