Controllers\xAPI\DocumentController::documentResponse PHP Method

documentResponse() public method

Generates content response.
public documentResponse ( mixed $data ) : Response
$data mixed used to select the Document.
return Response
    public function documentResponse($data)
    {
        $document = $this->document->find($this->getOptions(), $this->document_type, $data);
        if (!$document) {
            throw new Exceptions\NotFound($data[$this->identifier], $this->document_type);
        } else {
            $headers = ['Updated' => $document->updated_at->toISO8601String(), 'Content-Type' => $document->contentType, 'ETag' => '"' . $document->sha . '"'];
            if ($this->method === 'HEAD') {
                //Only return headers
                return \Response::make(null, 200, $headers);
            } else {
                switch ($document->contentType) {
                    case "application/json":
                        return \Response::json($document->content, 200, $headers);
                    case "text/plain":
                        return \Response::make($document->content, 200, $headers);
                    default:
                        $stream = FileFactory::create()->stream($document->getFilePath(), []);
                        return \Response::stream(function () use($stream) {
                            if (ob_get_level() == 0) {
                                ob_start();
                            }
                            while (!feof($stream)) {
                                echo fread($stream, 8192);
                                flush();
                                ob_flush();
                            }
                            fclose($stream);
                        }, 200, $headers);
                }
            }
        }
    }