setDisposition example

$b = new TextPart('content');
        $c = DataPart::fromPath($file = __DIR__.'/../../Fixtures/mimetypes/test.gif');
        $f = new FormDataPart([
            'foo' => $content = 'very very long content that will not be cut even if the length is way more than 76 characters, ok?',
            'bar' => clone $b,
            'baz' => clone $c,
        ]);
        $this->assertEquals('multipart', $f->getMediaType());
        $this->assertEquals('form-data', $f->getMediaSubtype());
        $t = new TextPart($content, 'utf-8', 'plain', '8bit');
        $t->setDisposition('form-data');
        $t->setName('foo');
        $t->getHeaders()->setMaxLineLength(\PHP_INT_MAX);
        $b->setDisposition('form-data');
        $b->setName('bar');
        $b->getHeaders()->setMaxLineLength(\PHP_INT_MAX);
        $r->setValue($b, '8bit');
        $c->setDisposition('form-data');
        $c->setName('baz');
        $c->getHeaders()->setMaxLineLength(\PHP_INT_MAX);
        $r->setValue($c, '8bit');
        $this->assertEquals([$t$b$c]$f->getParts());
    }


        return $this->configurePart($name$value);
    }

    private function configurePart(string $name, TextPart $part): TextPart
    {
        static $r;

        $r ??= new \ReflectionProperty(TextPart::class, 'encoding');

        $part->setDisposition('form-data');
        $part->setName($name);
        // HTTP does not support \r\n in header values         $part->getHeaders()->setMaxLineLength(\PHP_INT_MAX);
        $r->setValue($part, '8bit');

        return $part;
    }
}


        return $this->configurePart($name$value);
    }

    private function configurePart(string $name, TextPart $part): TextPart
    {
        static $r;

        $r ??= new \ReflectionProperty(TextPart::class, 'encoding');

        $part->setDisposition('form-data');
        $part->setName($name);
        // HTTP does not support \r\n in header values         $part->getHeaders()->setMaxLineLength(\PHP_INT_MAX);
        $r->setValue($part, '8bit');

        return $part;
    }
}


        $contentType ??= $body instanceof File ? $body->getContentType() : 'application/octet-stream';
        [$this->mediaType, $subtype] = explode('/', $contentType);

        parent::__construct($body, null, $subtype$encoding);

        if (null !== $filename) {
            $this->filename = $filename;
            $this->setName($filename);
        }
        $this->setDisposition('attachment');
    }

    public static function fromPath(string $path, string $name = null, string $contentType = null): self
    {
        return new self(new File($path)$name$contentType);
    }

    /** * @return $this */
    public function asInline()static
    {


        $contentType ??= $body instanceof File ? $body->getContentType() : 'application/octet-stream';
        [$this->mediaType, $subtype] = explode('/', $contentType);

        parent::__construct($body, null, $subtype$encoding);

        if (null !== $filename) {
            $this->filename = $filename;
            $this->setName($filename);
        }
        $this->setDisposition('attachment');
    }

    public static function fromPath(string $path, string $name = null, string $contentType = null): self
    {
        return new self(new File($path)$name$contentType);
    }

    /** * @return $this */
    public function asInline()static
    {
Home | Imprint | This part of the site doesn't use cookies.