Настройка ConstraintViolationList с RestBudnle - PullRequest
0 голосов
/ 31 марта 2020

Я использую FosRestBundle, который использует сериализатор jms (выглядит как по умолчанию), и я не могу переопределить обработчики по умолчанию в комплекте сериализатора jms. Как я могу остановить обработчик по умолчанию от переопределения моего собственного?

Я пытаюсь с приоритетом: -1000 и приоритетом: 1000 все еще не используется. Я установил точку останова в getSubscribingMethods и ничего, отладка не введена: (

Я использовал fre sh пакетов версий


        "name": "jms/serializer-bundle",
        "version": "3.5.0",

"name": "symfony/framework-bundle",
            "version": "v5.0.5",

Я до версии "name": "jms/serializer-bundle", "version": "dev-master", все еще получаю тот же случай

App\Serializer\ConstraintViolationListHandler:
  tags:
    - {name: jms_serializer.subscribing_handler, priority: 1000}


class ConstraintViolationListHandler implements SubscribingHandlerInterface
{

    public static function getSubscribingMethods()
    {
        return [
            [
                'direction' => GraphNavigatorInterface::DIRECTION_SERIALIZATION,
                'format' => 'json',
                'type' => ConstraintViolationList::class,
                'method' => 'serializeConstraintViolationList',
            ]
        ];
    }

    public function serializeConstraintViolationList(
        JsonSerializationVisitor $visitor,
        $constraintViolationList,
        array $type,
        Context $context = null
    )
    {
        $t = 1;

        return 1;
    }
}

Но debbug никогда не входит в мои ConstraintViolationListHandler

мои действия от контроллера покоя

 * @Rest\View(statusCode=Response::HTTP_OK)
 */
public function getCategoriesAction(SentEmail $sentEmail, ConstraintViolationListInterface $validationErrors)
{
    $content = 1;
    if (count($validationErrors) > 0) {
        // Handle validation errors
        return $validationErrors;

и мои настройки покоя

fos_rest:
    body_listener:
        service: my_body_listener
    body_converter:
        enabled: true
        validate: true
        validation_errors_argument: validationErrors
    unauthorized_challenge: "Basic realm=\"Restricted Area\""
    access_denied_listener:
        # all requests using the 'json' format will return a 403 on an access denied violation
        json: true
    param_fetcher_listener: true
    format_listener:
        rules:
            - { path: ^/api, prefer_extension: true, fallback_format: json, priorities: [ json ] }
            - { path: ^/, priorities: [ json, xml, html ], fallback_format: ~, prefer_extension: true }
    view:
      view_response_listener: 'force'
      formats:
        json: true
        jsonp: false
        xml: false
        rss: false
      mime_types:
        json: ['application/json', 'application/x-json']
    routing_loader:
        default_format:  json
    exception:
        enabled: true
        codes:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
            'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
            'Symfony\Component\HttpKernel\Exception\BadRequestHttpException': 400
        messages:
            Symfony\Component\HttpKernel\Exception\BadRequestHttpException: true
            Symfony\Component\HttpKernel\Exception\HttpException: true

пока ответ с ConstraintViolationList выглядит следующим образом

[
    {
        "property_path": "email",
        "message": "This value is not a valid email address."
    }
]

, но мне нужно его настроить. Что нужно для этого сделать?

...