src/acdhOeaw/fedora/Fedora.php
static public function attachData(Request $request, $body): Request {
        $headers = $request->getHeaders();
        if (is_string($body) && file_exists($body)) {
            $filename                       = rawurldecode(basename($body)); // lucky guess - unfortunately it is not clear how to escape header values
            $headers['Content-Disposition'] = 'attachment; filename="' . $filename . '"';

            $mime = @mime_content_type($body);
            if ($mime) {
                $headers['Content-Type'] = $mime;
            }
            $body = fopen($body, 'rb');
        } elseif (is_array($body) && isset($body['contentType']) && isset($body['data']) && isset($body['filename'])) {
            $headers['Content-Type']        = $body['contentType'];
            $headers['Content-Disposition'] = 'attachment; filename="' . rawurldecode($body['filename']) . '"';
            $body                           = file_exists($body['data']) ? fopen($body['data'], 'rb') : $body['data'];
        } elseif (is_string($body) && preg_match('|^[a-z0-9]+://|i', $body)) {
            $headers['Content-Type'] = 'message/external-body; access-type=URL; URL="' . $body . '"';
            $body                    = null;
        }
        return new Request($request->getMethod(), $request->getUri(), $headers, $body);
    }
static public function attachData(Request $request, $body): Request {
        $headers = $request->getHeaders();
        if (is_string($body) && file_exists($body)) {
            $filename                       = rawurldecode(basename($body)); // lucky guess - unfortunately it is not clear how to escape header values
            $headers['Content-Disposition'] = 'attachment; filename="' . $filename . '"';

            $mime = @mime_content_type($body);
            if ($mime) {
                $headers['Content-Type'] = $mime;
            }
            $body = fopen($body, 'rb');
        } elseif (is_array($body) && isset($body['contentType']) && isset($body['data']) && isset($body['filename'])) {
            $headers['Content-Type']        = $body['contentType'];
            $headers['Content-Disposition'] = 'attachment; filename="' . rawurldecode($body['filename']) . '"';
            $body                           = file_exists($body['data']) ? fopen($body['data'], 'rb') : $body['data'];
        } elseif (is_string($body) && preg_match('|^[a-z0-9]+://|i', $body)) {
            $headers['Content-Type'] = 'message/external-body; access-type=URL; URL="' . $body . '"';
            $body                    = null;
        }
        return new Request($request->getMethod(), $request->getUri(), $headers, $body);
    }
static public function attachData ( Request $ request , $ body ) : Request { $ headers = $ request -> getHeaders ( ) ; if ( is_string ( $ body ) && file_exists ( $ body ) ) { $ filename = rawurldecode ( basename ( $ body ) ) ; // lucky guess - unfortunately it is not clear how to escape header values $ headers [ 'Content-Disposition' ] = 'attachment; filename="' . $ filename . '"' ; $ mime = @ mime_content_type ( $ body ) ; if ( $ mime ) { $ headers [ 'Content-Type' ] = $ mime ; } $ body = fopen ( $ body , 'rb' ) ; } elseif ( is_array ( $ body ) && isset ( $ body [ 'contentType' ] ) && isset ( $ body [ 'data' ] ) && isset ( $ body [ 'filename' ] ) ) { $ headers [ 'Content-Type' ] = $ body [ 'contentType' ] ; $ headers [ 'Content-Disposition' ] = 'attachment; filename="' . rawurldecode ( $ body [ 'filename' ] ) . '"' ; $ body = file_exists ( $ body [ 'data' ] ) ? fopen ( $ body [ 'data' ] , 'rb' ) : $ body [ 'data' ] ; } elseif ( is_string ( $ body ) && preg_match ( '|^[a-z0-9]+://|i' , $ body ) ) { $ headers [ 'Content-Type' ] = 'message/external-body; access-type=URL; URL="' . $ body . '"' ; $ body = null ; } return new Request ( $ request -> getMethod ( ) , $ request -> getUri ( ) , $ headers , $ body ) ; }
Attaches binary content to a given Guzzle HTTP request

@param \GuzzleHttp\Psr7\Request $request HTTP request
@param $body binary content to be attached
It can be a file name, an URL, an array or a normal string.
If it is an URL, a "redirecting Fedora resource" will be created.
If it is an array, it should contain fields: contentType, filename, data
@return \GuzzleHttp\Psr7\Request
Attaches binary content to a given Guzzle HTTP request