src/Controller/Framework/DocTreeController.php
/**
     * Create a response with a CFDocument.
     */
Create a response with a CFDocument.
Create a response with a CFDocument .
protected function respondWithDocumentByIdentifier(Request $request, string $identifier, LsDoc $lsDoc): Response
    {
        $newDoc = $this->getDoctrine()->getRepository(LsDoc::class)->findOneBy(['identifier' => $identifier]);
        if (null !== $newDoc) {
            return $this->exportAction($request, $newDoc);
        }
        $externalDocs = $lsDoc->getExternalDocs();
        if (!empty($externalDocs[$identifier])) {
            $response = $this->exportExternalDocument($externalDocs[$identifier]['url'], null);
            if (200 !== $response->getStatusCode()) {
                return $response;
            }
            $content = $response->getContent();
            $json = json_decode($content, true);
            $lastModified = new \DateTime($json['CFDocument']['lastChangeDateTime'], new \DateTimeZone('UTC'));
            $response->setEtag(md5($lastModified->format('U.u').self::ETAG_SEED), true);
            $response->setLastModified($lastModified);
            $response->setMaxAge(0);
            $response->setSharedMaxAge(0);
            $response->setExpires(\DateTime::createFromFormat('U', $lastModified->format('U'))->sub(new \DateInterval('PT1S')));
            $response->setPublic();
            $response->headers->addCacheControlDirective('must-revalidate');
            if ($response->isNotModified($request)) {
                return $response;
            }
            return $response;
        }
        return new Response('Document not found.', Response::HTTP_NOT_FOUND);
    }
protected function respondWithDocumentByIdentifier ( Request $ request , string $ identifier , LsDoc $ lsDoc ) : Response { $ newDoc = $ this -> getDoctrine ( ) -> getRepository ( LsDoc :: class ) -> findOneBy ( [ 'identifier' => $ identifier ] ) ; if ( null !== $ newDoc ) { return $ this -> exportAction ( $ request , $ newDoc ) ; } $ externalDocs = $ lsDoc -> getExternalDocs ( ) ; if ( ! empty ( $ externalDocs [ $ identifier ] ) ) { $ response = $ this -> exportExternalDocument ( $ externalDocs [ $ identifier ] [ 'url' ] , null ) ; if ( 200 !== $ response -> getStatusCode ( ) ) { return $ response ; } $ content = $ response -> getContent ( ) ; $ json = json_decode ( $ content , true ) ; $ lastModified = new \ DateTime ( $ json [ 'CFDocument' ] [ 'lastChangeDateTime' ] , new \ DateTimeZone ( 'UTC' ) ) ; $ response -> setEtag ( md5 ( $ lastModified -> format ( 'U.u' ) . self :: ETAG_SEED ) , true ) ; $ response -> setLastModified ( $ lastModified ) ; $ response -> setMaxAge ( 0 ) ; $ response -> setSharedMaxAge ( 0 ) ; $ response -> setExpires ( \ DateTime :: createFromFormat ( 'U' , $ lastModified -> format ( 'U' ) ) -> sub ( new \ DateInterval ( 'PT1S' ) ) ) ; $ response -> setPublic ( ) ; $ response -> headers -> addCacheControlDirective ( 'must-revalidate' ) ; if ( $ response -> isNotModified ( $ request ) ) { return $ response ; } return $ response ; } return new Response ( 'Document not found.' , Response :: HTTP_NOT_FOUND ) ; }
Create a response with a CFDocument.
Create a response with a CFDocument .
// otherwise look in this doc's externalDocs // We could store, and check here, a global table of external documents that we could index by identifiers, instead of using document-specific associated docs. But it's not completely clear that would be an improvement. // if we found it, load it, noting that we don't have to save a record of it in externalDocs (since it's already there) // if not found in externalDocs, error