public function webhook(Request $request): Response
    {
        $content = (string) $request->getContent();
        $spaceId = $request->headers->get('X-Space-Id');
        $spaceId = is_array($spaceId) ? $spaceId[0] : $spaceId;

        try {
            $client = $this->contentful->getClientBySpaceId((string) $spaceId);
        } catch (Throwable $t) {
            throw new BadRequestHttpException('Invalid request');
        }

        if ($client === null) {
            throw new BadRequestHttpException('Invalid request');
        }

        try {
            $remoteEntry = $client->parseJson($content);
        } catch (Throwable $t) {
            throw new BadRequestHttpException('Invalid request');
        }

        switch ($request->headers->get('X-Contentful-Topic')) {
            case self::ENTRY_PUBLISH:
                if (!$remoteEntry instanceof Entry) {
                    throw new BadRequestHttpException('Invalid request');
                }

                $this->contentful->refreshContentfulEntry($remoteEntry);

                break;
            case self::ENTRY_UNPUBLISH:
                if (!$remoteEntry instanceof DeletedEntry) {
                    throw new BadRequestHttpException('Invalid request');
                }

                $this->contentful->unpublishContentfulEntry($remoteEntry);

                break;
            case self::ENTRY_DELETE:
                if (!$remoteEntry instanceof DeletedEntry) {
                    throw new BadRequestHttpException('Invalid request');
                }

                $this->contentful->deleteContentfulEntry($remoteEntry);

                break;
            case self::CONTENT_TYPE_PUBLISH:
            case self::CONTENT_TYPE_UNPUBLISH:
            case self::CONTENT_TYPE_DELETE:
                $this->contentful->refreshContentTypeCache($client);

                break;
            default:
                throw new BadRequestHttpException('Invalid request');
        }

        return new Response();
    }
public function webhook(Request $request): Response
    {
        $content = (string) $request->getContent();
        $spaceId = $request->headers->get('X-Space-Id');
        $spaceId = is_array($spaceId) ? $spaceId[0] : $spaceId;

        try {
            $client = $this->contentful->getClientBySpaceId((string) $spaceId);
        } catch (Throwable $t) {
            throw new BadRequestHttpException('Invalid request');
        }

        if ($client === null) {
            throw new BadRequestHttpException('Invalid request');
        }

        try {
            $remoteEntry = $client->parseJson($content);
        } catch (Throwable $t) {
            throw new BadRequestHttpException('Invalid request');
        }

        switch ($request->headers->get('X-Contentful-Topic')) {
            case self::ENTRY_PUBLISH:
                if (!$remoteEntry instanceof Entry) {
                    throw new BadRequestHttpException('Invalid request');
                }

                $this->contentful->refreshContentfulEntry($remoteEntry);

                break;
            case self::ENTRY_UNPUBLISH:
                if (!$remoteEntry instanceof DeletedEntry) {
                    throw new BadRequestHttpException('Invalid request');
                }

                $this->contentful->unpublishContentfulEntry($remoteEntry);

                break;
            case self::ENTRY_DELETE:
                if (!$remoteEntry instanceof DeletedEntry) {
                    throw new BadRequestHttpException('Invalid request');
                }

                $this->contentful->deleteContentfulEntry($remoteEntry);

                break;
            case self::CONTENT_TYPE_PUBLISH:
            case self::CONTENT_TYPE_UNPUBLISH:
            case self::CONTENT_TYPE_DELETE:
                $this->contentful->refreshContentTypeCache($client);

                break;
            default:
                throw new BadRequestHttpException('Invalid request');
        }

        return new Response();
    }
public function webhook ( Request $ request ) : Response { $ content = ( string ) $ request -> getContent ( ) ; $ spaceId = $ request -> headers -> get ( 'X-Space-Id' ) ; $ spaceId = is_array ( $ spaceId ) ? $ spaceId [ 0 ] : $ spaceId ; try { $ client = $ this -> contentful -> getClientBySpaceId ( ( string ) $ spaceId ) ; } catch ( Throwable $ t ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } if ( $ client === null ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } try { $ remoteEntry = $ client -> parseJson ( $ content ) ; } catch ( Throwable $ t ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } switch ( $ request -> headers -> get ( 'X-Contentful-Topic' ) ) { case self :: ENTRY_PUBLISH : if ( ! $ remoteEntry instanceof Entry ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } $ this -> contentful -> refreshContentfulEntry ( $ remoteEntry ) ; break ; case self :: ENTRY_UNPUBLISH : if ( ! $ remoteEntry instanceof DeletedEntry ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } $ this -> contentful -> unpublishContentfulEntry ( $ remoteEntry ) ; break ; case self :: ENTRY_DELETE : if ( ! $ remoteEntry instanceof DeletedEntry ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } $ this -> contentful -> deleteContentfulEntry ( $ remoteEntry ) ; break ; case self :: CONTENT_TYPE_PUBLISH : case self :: CONTENT_TYPE_UNPUBLISH : case self :: CONTENT_TYPE_DELETE : $ this -> contentful -> refreshContentTypeCache ( $ client ) ; break ; default : throw new BadRequestHttpException ( 'Invalid request' ) ; } return new Response ( ) ; }
Contentful webhook for clearing local caches.

@throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException If the webhook request is not valid
Contentful webhook for clearing local caches .