public function getEntryById(string $sectionHandle, string $id): JsonResponse
    {
        $request = $this->requestStack->getCurrentRequest();

        $optionsResponse = $this->preFlightOptions($request, self::ALLOWED_HTTP_METHODS);
        if ($optionsResponse) {
            return $optionsResponse;
        }

        $this->dispatcher->dispatch(
            ApiFetchEntry::NAME,
            new ApiFetchEntry($request, $sectionHandle)
        );

        if ($abort = $this->shouldAbort($request)) {
            return $abort;
        }

        try {
            $section = $this->sectionManager->readByHandle(Handle::fromString($sectionHandle));

            try {
                $this->cache->start(
                    $section->getConfig()->getFullyQualifiedClassName(),
                    $this->getFields(),
                    self::CACHE_CONTEXT_GET_ENTRY_BY_ID,
                    $id
                );
            } catch (\Psr\Cache\InvalidArgumentException $exception) {
                //
            }

            if ($this->cache->isHit()) {
                return new JsonResponse(
                    $this->cache->get(),
                    JsonResponse::HTTP_OK,
                    $this->getDefaultResponseHeaders($request)
                );
            }

            $entry = $this->readSection->read(ReadOptions::fromArray([
                ReadOptions::SECTION => $sectionHandle,
                ReadOptions::ID => (int)$id
            ]))->current();

            $responseData = $this->serialize->toArray($request, $entry);
            $jsonResponse = new JsonResponse(
                $responseData,
                JsonResponse::HTTP_OK,
                $this->getDefaultResponseHeaders($request)
            );

            $this->dispatcher->dispatch(
                ApiEntryFetched::NAME,
                new ApiEntryFetched($request, $responseData, $jsonResponse, $entry)
            );

            if ($abort = $this->shouldAbort($request)) {
                return $abort;
            }

            $this->cache->set($responseData);

            return $jsonResponse;
        } catch (\Exception $exception) {
            return $this->errorResponse($request, $exception);
        }
    }
public function getEntryById(string $sectionHandle, string $id): JsonResponse
    {
        $request = $this->requestStack->getCurrentRequest();

        $optionsResponse = $this->preFlightOptions($request, self::ALLOWED_HTTP_METHODS);
        if ($optionsResponse) {
            return $optionsResponse;
        }

        $this->dispatcher->dispatch(
            ApiFetchEntry::NAME,
            new ApiFetchEntry($request, $sectionHandle)
        );

        if ($abort = $this->shouldAbort($request)) {
            return $abort;
        }

        try {
            $section = $this->sectionManager->readByHandle(Handle::fromString($sectionHandle));

            try {
                $this->cache->start(
                    $section->getConfig()->getFullyQualifiedClassName(),
                    $this->getFields(),
                    self::CACHE_CONTEXT_GET_ENTRY_BY_ID,
                    $id
                );
            } catch (\Psr\Cache\InvalidArgumentException $exception) {
                //
            }

            if ($this->cache->isHit()) {
                return new JsonResponse(
                    $this->cache->get(),
                    JsonResponse::HTTP_OK,
                    $this->getDefaultResponseHeaders($request)
                );
            }

            $entry = $this->readSection->read(ReadOptions::fromArray([
                ReadOptions::SECTION => $sectionHandle,
                ReadOptions::ID => (int)$id
            ]))->current();

            $responseData = $this->serialize->toArray($request, $entry);
            $jsonResponse = new JsonResponse(
                $responseData,
                JsonResponse::HTTP_OK,
                $this->getDefaultResponseHeaders($request)
            );

            $this->dispatcher->dispatch(
                ApiEntryFetched::NAME,
                new ApiEntryFetched($request, $responseData, $jsonResponse, $entry)
            );

            if ($abort = $this->shouldAbort($request)) {
                return $abort;
            }

            $this->cache->set($responseData);

            return $jsonResponse;
        } catch (\Exception $exception) {
            return $this->errorResponse($request, $exception);
        }
    }
public function getEntryById ( string $ sectionHandle , string $ id ) : JsonResponse { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; $ optionsResponse = $ this -> preFlightOptions ( $ request , self :: ALLOWED_HTTP_METHODS ) ; if ( $ optionsResponse ) { return $ optionsResponse ; } $ this -> dispatcher -> dispatch ( ApiFetchEntry :: NAME , new ApiFetchEntry ( $ request , $ sectionHandle ) ) ; if ( $ abort = $ this -> shouldAbort ( $ request ) ) { return $ abort ; } try { $ section = $ this -> sectionManager -> readByHandle ( Handle :: fromString ( $ sectionHandle ) ) ; try { $ this -> cache -> start ( $ section -> getConfig ( ) -> getFullyQualifiedClassName ( ) , $ this -> getFields ( ) , self :: CACHE_CONTEXT_GET_ENTRY_BY_ID , $ id ) ; } catch ( \ Psr \ Cache \ InvalidArgumentException $ exception ) { // } if ( $ this -> cache -> isHit ( ) ) { return new JsonResponse ( $ this -> cache -> get ( ) , JsonResponse :: HTTP_OK , $ this -> getDefaultResponseHeaders ( $ request ) ) ; } $ entry = $ this -> readSection -> read ( ReadOptions :: fromArray ( [ ReadOptions :: SECTION => $ sectionHandle , ReadOptions :: ID => ( int ) $ id ] ) ) -> current ( ) ; $ responseData = $ this -> serialize -> toArray ( $ request , $ entry ) ; $ jsonResponse = new JsonResponse ( $ responseData , JsonResponse :: HTTP_OK , $ this -> getDefaultResponseHeaders ( $ request ) ) ; $ this -> dispatcher -> dispatch ( ApiEntryFetched :: NAME , new ApiEntryFetched ( $ request , $ responseData , $ jsonResponse , $ entry ) ) ; if ( $ abort = $ this -> shouldAbort ( $ request ) ) { return $ abort ; } $ this -> cache -> set ( $ responseData ) ; return $ jsonResponse ; } catch ( \ Exception $ exception ) { return $ this -> errorResponse ( $ request , $ exception ) ; } }
GET an entry by id
@param string $sectionHandle
@param string $id
@return JsonResponse
GET an entry by id