Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TextPart.php

function TextPart::__construct

Parameters

resource|string|File $body Use a File instance to defer loading the file until rendering:

Overrides AbstractPart::__construct

2 calls to TextPart::__construct()
DataPart::__construct in vendor/symfony/mime/Part/DataPart.php
DataPart::__construct in vendor/symfony/mime/Part/DataPart.php
1 method overrides TextPart::__construct()
DataPart::__construct in vendor/symfony/mime/Part/DataPart.php

File

vendor/symfony/mime/Part/TextPart.php, line 45

Class

TextPart
@author Fabien Potencier <fabien@symfony.com>

Namespace

Symfony\Component\Mime\Part

Code

public function __construct($body, ?string $charset = 'utf-8', string $subtype = 'plain', ?string $encoding = null) {
    parent::__construct();
    if (!\is_string($body) && !\is_resource($body) && !$body instanceof File) {
        throw new \TypeError(\sprintf('The body of "%s" must be a string, a resource, or an instance of "%s" (got "%s").', self::class, File::class, get_debug_type($body)));
    }
    if ($body instanceof File) {
        $path = $body->getPath();
        if (is_file($path) && !is_readable($path) || is_dir($path)) {
            throw new InvalidArgumentException(\sprintf('Path "%s" is not readable.', $path));
        }
    }
    $this->body = $body;
    $this->charset = $charset;
    $this->subtype = $subtype;
    $this->seekable = \is_resource($body) ? stream_get_meta_data($body)['seekable'] && 0 === fseek($body, 0, \SEEK_CUR) : null;
    if (null === $encoding) {
        $this->encoding = $this->chooseEncoding();
    }
    else {
        if (!\in_array($encoding, self::DEFAULT_ENCODERS, true) && !\array_key_exists($encoding, self::$encoders)) {
            throw new InvalidArgumentException(\sprintf('The encoding must be one of "%s" ("%s" given).', implode('", "', array_unique(array_merge(self::DEFAULT_ENCODERS, array_keys(self::$encoders)))), $encoding));
        }
        $this->encoding = $encoding;
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal