JeroenDesloovere\VCard\VCard::getHeaders PHP Method

getHeaders() public method

Get headers
public getHeaders ( boolean $asAssociative ) : array
$asAssociative boolean
return array
    public function getHeaders($asAssociative)
    {
        $contentType = $this->getContentType() . '; charset=' . $this->getCharset();
        $contentDisposition = 'attachment; filename=' . $this->getFilename() . '.' . $this->getFileExtension();
        $contentLength = strlen($this->getOutput());
        $connection = 'close';
        if ((bool) $asAssociative) {
            return array('Content-type' => $contentType, 'Content-Disposition' => $contentDisposition, 'Content-Length' => $contentLength, 'Connection' => $connection);
        }
        return array('Content-type: ' . $contentType, 'Content-Disposition: ' . $contentDisposition, 'Content-Length: ' . $contentLength, 'Connection: ' . $connection);
    }

Usage Example

 private function buildVcardResponse(VCard $vcard)
 {
     // Build response
     $response = new Response($vcard->getOutput());
     foreach ($vcard->getHeaders(true) as $key => $val) {
         $response->headers->set($key, $val);
     }
     return $response;
 }