Final Class Yiisoft\Mailer\File
| Inheritance | Yiisoft\Mailer\File |
|---|
File is a data object that stores data for attaching a file to a mail message.
Public 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
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()}";
}
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;
}
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;
}
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);
}
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);
}
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;
}
Signup or Login in order to comment.