unsupportedMediaType example



    public function testMissingReverseAssociation(): void
    {
        $exception = ApiException::missingReverseAssociation('order', 'customer');

        static::assertInstanceOf(MissingReverseAssociation::class$exception);
    }

    public function testUnsupportedMediaType(): void
    {
        $exception = ApiException::unsupportedMediaType('jpeg');

        static::assertInstanceOf(UnsupportedMediaTypeHttpException::class$exception);
        static::assertSame('The Content-Type "jpeg" is unsupported.', $exception->getMessage());
    }

    public function testNotExistingRelation(): void
    {
        $exception = ApiException::notExistingRelation('demo');

        static::assertEquals(ApiException::API_NOT_EXISTING_RELATION_EXCEPTION, $exception->getErrorCode());
        static::assertEquals('Resource at path "demo" is not an existing relation.', $exception->getMessage());
    }
try {
            switch ($contentType) {
                case 'application/vnd.api+json':
                    return $this->serializer->decode($request->getContent(), 'jsonapi');
                case 'application/json':
                    return $request->request->all();
            }
        } catch (InvalidArgumentException|UnexpectedValueException $exception) {
            throw ApiException::badRequest($exception->getMessage());
        }

        throw ApiException::unsupportedMediaType($contentType);
    }

    /** * @param array<mixed> $array */
    private function isCollection(array $array): bool
    {
        return array_keys($array) === range(0, \count($array) - 1);
    }

    private function getEntityDefinition(string $entityName): EntityDefinition
    {
Home | Imprint | This part of the site doesn't use cookies.