Php 带有RESTBundle的自定义约束ViolationList
我使用FosRestBundle,它使用jms序列化程序(看起来像是默认的),我无法覆盖jms序列化程序捆绑包中的默认处理程序。如何阻止默认处理程序重写自定义处理程序 我尝试使用优先级:-1000和优先级:1000仍然没有使用。我在Php 带有RESTBundle的自定义约束ViolationList,php,fosrestbundle,jmsserializerbundle,symfony5,Php,Fosrestbundle,Jmsserializerbundle,Symfony5,我使用FosRestBundle,它使用jms序列化程序(看起来像是默认的),我无法覆盖jms序列化程序捆绑包中的默认处理程序。如何阻止默认处理程序重写自定义处理程序 我尝试使用优先级:-1000和优先级:1000仍然没有使用。我在getSubscribingMethods中设置了断点,但未输入任何内容,调试:( 我用的是新版本 "name": "jms/serializer-bundle", "version": "3.5.0", "name": "symf
getSubscribingMethods
中设置了断点,但未输入任何内容,调试:(
我用的是新版本
"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控制器的我的操作
* @Rest\View(statusCode=Response::HTTP_OK)
*/
public function getCategoriesAction(SentEmail $sentEmail, ConstraintViolationListInterface $validationErrors)
{
$content = 1;
if (count($validationErrors) > 0) {
// Handle validation errors
return $validationErrors;
和我的rest配置
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."
}
]
但我需要定制它,需要做什么