0 follower

Final Class Yiisoft\Mailer\File

InheritanceYiisoft\Mailer\File

File is a data object that stores data for attaching a file to a mail message.

Public Methods

Hide inherited methods

Method Description Defined By
cid() Returns the file CID source. Yiisoft\Mailer\File
content() Returns the content that should be used to attach the file. Yiisoft\Mailer\File
contentType() Returns the MIME type that should be used to attach the file. Yiisoft\Mailer\File
fromContent() Creates a new file instance from the specified content. Yiisoft\Mailer\File
fromPath() Creates a new file instance from the specified full path to the file. Yiisoft\Mailer\File
id() Returns the file ID. Yiisoft\Mailer\File
name() Returns the name that should be used to attach the file. Yiisoft\Mailer\File
path() Returns the full path to the file. Yiisoft\Mailer\File

Method Details

Hide inherited methods

cid() public method

Returns the file CID source.

public string cid ( )
return string

The file CID source.

throws Exception

{@see https://www.php.net/manual/en/function.random-bytes.php}

                public function cid(): string
{
    return "cid:{$this->id()}";
}

            
content() public method

Returns the content that should be used to attach the file.

public string|null content ( )
return string|null

The content that should be used to attach the file.

                public function content(): ?string
{
    return $this->content;
}

            
contentType() public method

Returns the MIME type that should be used to attach the file.

public string|null contentType ( )
return string|null

MIME type that should be used to attach the file.

                public function contentType(): ?string
{
    return $this->contentType;
}

            
fromContent() public static method

Creates a new file instance from the specified content.

public static self fromContent ( string $content, string|null $name null, string|null $contentType null )
$content string

The content that should be used to attach the file.

$name string|null

The name that should be used to attach the file.

$contentType string|null

MIME type that should be used to attach the file.

                public static function fromContent(string $content, ?string $name = null, ?string $contentType = null): self
{
    return new self($name, null, $content, $contentType);
}

            
fromPath() public static method

Creates a new file instance from the specified full path to the file.

public static self fromPath ( string $path, string|null $name null, string|null $contentType null )
$path string

The full path to the file.

$name string|null

The name that should be used to attach the file.

$contentType string|null

MIME type that should be used to attach the file.

throws RuntimeException

If the specified file does not exist.

                public static function fromPath(string $path, ?string $name = null, ?string $contentType = null): self
{
    if (!is_file($path)) {
        throw new RuntimeException("The file {$path} does not exist.");
    }
    return new self($name, $path, null, $contentType);
}

            
id() public method

Returns the file ID.

public string id ( )
return string

The file ID.

throws Exception

{@see https://www.php.net/manual/en/function.random-bytes.php}

                public function id(): string
{
    if ($this->id === null) {
        $this->id = bin2hex(random_bytes(16)) . '@app';
    }
    return $this->id;
}

            
name() public method

Returns the name that should be used to attach the file.

public string|null name ( )
return string|null

The name that should be used to attach the file.

                public function name(): ?string
{
    return $this->name;
}

            
path() public method

Returns the full path to the file.

public string|null path ( )
return string|null

The full path to the file.

                public function path(): ?string
{
    return $this->path;
}