Apple_Push_API\MIME_Builder::build_attachment PHP Method

build_attachment() private method

Build an attachment in the MIME request.
private build_attachment ( string $name, string $filename, string $content, string $mime_type, integer $size ) : string
$name string
$filename string
$content string
$mime_type string
$size integer
return string
    private function build_attachment($name, $filename, $content, $mime_type, $size)
    {
        // Ensure the file isn't empty
        if (empty($content)) {
            throw new Request_Exception(sprintf(__('The attachment %s could not be included in the request because it was empty.', 'apple-news'), esc_html($filename)));
        }
        // Ensure a valid size was provided
        if (0 >= intval($size)) {
            throw new Request_Exception(sprintf(__('The attachment %s could not be included in the request because its size was %s.', 'apple-news'), esc_html($filename), esc_html($size)));
        }
        // Build the attachment
        $attachment = '--' . $this->boundary . $this->eol;
        $attachment .= 'Content-Type: ' . $mime_type . $this->eol;
        $attachment .= 'Content-Disposition: form-data; name=' . $name . '; filename=' . $filename . '; size=' . $size . $this->eol . $this->eol;
        $this->debug_content .= $attachment;
        $attachment .= $content . $this->eol;
        if ('application/json' === $mime_type) {
            $this->debug_content .= $content . $this->eol;
        } else {
            $this->debug_content .= "(binary contents of {$filename})" . $this->eol;
        }
        return $attachment;
    }