Tools\Mailer\Email::attachments PHP Method

attachments() public method

Overwrite to allow mimetype detection
public attachments ( mixed | null $attachments = null ) : array | $this
$attachments mixed | null
return array | $this
    public function attachments($attachments = null)
    {
        if ($attachments === null) {
            return $this->_attachments;
        }
        $attach = [];
        foreach ((array) $attachments as $name => $fileInfo) {
            if (!is_array($fileInfo)) {
                $fileInfo = ['file' => $fileInfo];
            }
            if (!isset($fileInfo['file'])) {
                if (!isset($fileInfo['data'])) {
                    throw new InvalidArgumentException('No file or data specified.');
                }
                if (is_int($name)) {
                    throw new InvalidArgumentException('No filename specified.');
                }
                $fileInfo['data'] = chunk_split(base64_encode($fileInfo['data']), 76, "\r\n");
            } else {
                $fileName = $fileInfo['file'];
                $fileInfo['file'] = realpath($fileInfo['file']);
                if ($fileInfo['file'] === false || !file_exists($fileInfo['file'])) {
                    throw new InvalidArgumentException(sprintf('File not found: "%s"', $fileName));
                }
                if (is_int($name)) {
                    $name = basename($fileInfo['file']);
                }
            }
            if (!isset($fileInfo['mimetype'])) {
                $ext = pathinfo($name, PATHINFO_EXTENSION);
                $fileInfo['mimetype'] = $this->_getMimeByExtension($ext);
            }
            $attach[$name] = $fileInfo;
        }
        $this->_attachments = $attach;
        return $this;
    }