You are here

public function CmisBrowser::getDocument in CMIS API 8

Same name and namespace in other branches
  1. 8.2 src/CmisBrowser.php \Drupal\cmis\CmisBrowser::getDocument()
  2. 3.0.x src/CmisBrowser.php \Drupal\cmis\CmisBrowser::getDocument()

Get document by id.

Parameters

type $config:

type $document_id:

1 string reference to 'CmisBrowser::getDocument'
cmis.routing.yml in ./cmis.routing.yml
cmis.routing.yml

File

src/CmisBrowser.php, line 117

Class

CmisBrowser
Description of CmisBrowser

Namespace

Drupal\cmis

Code

public function getDocument($config = '', $document_id = '') {
  $this
    ->init($config, $document_id, 'cmis:document');
  if ($this->connection && !empty($this->current) && $this->current
    ->getBaseTypeId()
    ->__toString() == 'cmis:document') {
    $id = $this->current
      ->getId();
    try {
      $content = $this->current
        ->getContentStream($id);
    } catch (CMISException $e) {

      // TODO: testing this.
      $headers = [
        '' => 'HTTP/1.1 503 Service unavailable',
      ];
      $response = new Response($content, 503, $headers);
      $response
        ->send();
      exit;
    }
    $mime = $this->current
      ->getContentStreamMimeType();
    $headers = [
      'Cache-Control' => 'no-cache, must-revalidate',
      'Content-type' => $mime,
      'Content-Disposition' => 'attachment; filename="' . $this->current
        ->getName() . '"',
    ];
    $response = new Response($content, 200, $headers);
    $response
      ->send();
    print $content;
    exit;
  }
}