addStream example


        $stream = new AppendStream();

        foreach ($elements as $element) {
            if (!is_array($element)) {
                throw new \UnexpectedValueException('An array is expected');
            }
            $this->addElement($stream$element);
        }

        // Add the trailing boundary with CRLF         $stream->addStream(Utils::streamFor("--{$this->boundary}--\r\n"));

        return $stream;
    }

    private function addElement(AppendStream $stream, array $element): void
    {
        foreach (['contents', 'name'] as $key) {
            if (!array_key_exists($key$element)) {
                throw new \InvalidArgumentException("A '{$key}' key is required");
            }
        }

        
/** @var int */
    private $pos = 0;

    /** * @param StreamInterface[] $streams Streams to decorate. Each stream must * be readable. */
    public function __construct(array $streams = [])
    {
        foreach ($streams as $stream) {
            $this->addStream($stream);
        }
    }

    public function __toString(): string
    {
        try {
            $this->rewind();

            return $this->getContents();
        } catch (\Throwable $e) {
            if (\PHP_VERSION_ID >= 70400) {
                
Home | Imprint | This part of the site doesn't use cookies.