src/Yggdrasil/Core/Controller/HttpManagerTrait.php
protected function json(array $data = [], string $status = Response::HTTP_OK): JsonResponse
    {
        $headers = $this->getResponse()->headers->all();

        $serializedData = [];

        foreach ($data as $key => $item) {
            if (is_array($item) && is_object($item[0])) {
                $serializedData[$key] = EntityNormalizer::normalize($item);

                unset($data[$key]);
            }

            if (is_object($item)) {
                $serializedData[$key] = EntityNormalizer::normalize([$item])[0];

                unset($data[$key]);
            }
        }

        $serializedData = array_merge($serializedData, $data);

        return new JsonResponse($serializedData, $status, $headers);
    }
protected function json(array $data = [], string $status = Response::HTTP_OK): JsonResponse
    {
        $headers = $this->getResponse()->headers->all();

        $serializedData = [];

        foreach ($data as $key => $item) {
            if (is_array($item) && is_object($item[0])) {
                $serializedData[$key] = EntityNormalizer::normalize($item);

                unset($data[$key]);
            }

            if (is_object($item)) {
                $serializedData[$key] = EntityNormalizer::normalize([$item])[0];

                unset($data[$key]);
            }
        }

        $serializedData = array_merge($serializedData, $data);

        return new JsonResponse($serializedData, $status, $headers);
    }
protected function json ( array $ data = [ ] , string $ status = Response :: HTTP_OK ) : JsonResponse { $ headers = $ this -> getResponse ( ) -> headers -> all ( ) ; $ serializedData = [ ] ; foreach ( $ data as $ key => $ item ) { if ( is_array ( $ item ) && is_object ( $ item [ 0 ] ) ) { $ serializedData [ $ key ] = EntityNormalizer :: normalize ( $ item ) ; unset ( $ data [ $ key ] ) ; } if ( is_object ( $ item ) ) { $ serializedData [ $ key ] = EntityNormalizer :: normalize ( [ $ item ] ) [ 0 ] ; unset ( $ data [ $ key ] ) ; } } $ serializedData = array_merge ( $ serializedData , $ data ) ; return new JsonResponse ( $ serializedData , $ status , $ headers ) ; }
Returns JSON encoded response

@param array  $data   Data supposed to be returned
@param string $status Response status code
@return JsonResponse
Returns JSON encoded response