private function getContext(Request $request): SerializationContext
    {
        $fields = $request->get('fields', ['id']);
        $depth = $request->get('depth', 20);
        $depth = is_numeric($depth) ? (int)$depth : 20;

        if (is_string($fields)) {
            $fields = explode(',', $fields);
        }

        $context = new SerializationContext();
        $context->addExclusionStrategy(new FieldsExclusionStrategy($fields));
        $context->addExclusionStrategy(new DepthExclusionStrategy($depth));

        return $context;
    }
private function getContext(Request $request): SerializationContext
    {
        $fields = $request->get('fields', ['id']);
        $depth = $request->get('depth', 20);
        $depth = is_numeric($depth) ? (int)$depth : 20;

        if (is_string($fields)) {
            $fields = explode(',', $fields);
        }

        $context = new SerializationContext();
        $context->addExclusionStrategy(new FieldsExclusionStrategy($fields));
        $context->addExclusionStrategy(new DepthExclusionStrategy($depth));

        return $context;
    }
private function getContext ( Request $ request ) : SerializationContext { $ fields = $ request -> get ( 'fields' , [ 'id' ] ) ; $ depth = $ request -> get ( 'depth' , 20 ) ; $ depth = is_numeric ( $ depth ) ? ( int ) $ depth : 20 ; if ( is_string ( $ fields ) ) { $ fields = explode ( ',' , $ fields ) ; } $ context = new SerializationContext ( ) ; $ context -> addExclusionStrategy ( new FieldsExclusionStrategy ( $ fields ) ) ; $ context -> addExclusionStrategy ( new DepthExclusionStrategy ( $ depth ) ) ; return $ context ; }
This method will get the desired fields and depth from the request

@param Request $request
@return SerializationContext
This method will get the desired fields and depth from the request