update patch 1

This commit is contained in:
fiqhpratama
2024-12-02 01:18:34 +07:00
parent 453d9bb470
commit 25026b0a85
3380 changed files with 103529 additions and 363623 deletions
@@ -53,7 +53,7 @@ final class BackedEnumValueResolver implements ValueResolverInterface
}
if (!\is_int($value) && !\is_string($value)) {
throw new \LogicException(sprintf('Could not resolve the "%s $%s" controller argument: expecting an int or string, got "%s".', $argument->getType(), $argument->getName(), get_debug_type($value)));
throw new \LogicException(\sprintf('Could not resolve the "%s $%s" controller argument: expecting an int or string, got "%s".', $argument->getType(), $argument->getName(), get_debug_type($value)));
}
/** @var class-string<\BackedEnum> $enumType */
@@ -62,7 +62,7 @@ final class BackedEnumValueResolver implements ValueResolverInterface
try {
return [$enumType::from($value)];
} catch (\ValueError|\TypeError $e) {
throw new NotFoundHttpException(sprintf('Could not resolve the "%s $%s" controller argument: ', $argument->getType(), $argument->getName()).$e->getMessage(), $e);
throw new NotFoundHttpException(\sprintf('Could not resolve the "%s $%s" controller argument: ', $argument->getType(), $argument->getName()).$e->getMessage(), $e);
}
}
}
@@ -79,7 +79,7 @@ final class DateTimeValueResolver implements ValueResolverInterface
}
if (!$date) {
throw new NotFoundHttpException(sprintf('Invalid date given for parameter "%s".', $argument->getName()));
throw new NotFoundHttpException(\sprintf('Invalid date given for parameter "%s".', $argument->getName()));
}
return [$date];
@@ -53,8 +53,8 @@ final class NotTaggedControllerValueResolver implements ValueResolverInterface
return [];
}
$what = sprintf('argument $%s of "%s()"', $argument->getName(), $controller);
$message = sprintf('Could not resolve %s, maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?', $what);
$what = \sprintf('argument $%s of "%s()"', $argument->getName(), $controller);
$message = \sprintf('Could not resolve %s, maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?', $what);
throw new RuntimeException($message);
}
@@ -41,7 +41,7 @@ final class QueryParameterValueResolver implements ValueResolverInterface
return [];
}
throw HttpException::fromStatusCode($validationFailedCode, sprintf('Missing query parameter "%s".', $name));
throw HttpException::fromStatusCode($validationFailedCode, \sprintf('Missing query parameter "%s".', $name));
}
$value = $request->query->all()[$name];
@@ -55,7 +55,7 @@ final class QueryParameterValueResolver implements ValueResolverInterface
$filtered = array_values(array_filter((array) $value, \is_array(...)));
if ($filtered !== $value && !($attribute->flags & \FILTER_NULL_ON_FAILURE)) {
throw HttpException::fromStatusCode($validationFailedCode, sprintf('Invalid query parameter "%s".', $name));
throw HttpException::fromStatusCode($validationFailedCode, \sprintf('Invalid query parameter "%s".', $name));
}
return $filtered;
@@ -83,7 +83,7 @@ final class QueryParameterValueResolver implements ValueResolverInterface
default => match ($enumType = is_subclass_of($type, \BackedEnum::class) ? (new \ReflectionEnum($type))->getBackingType()->getName() : null) {
'int' => \FILTER_VALIDATE_INT,
'string' => \FILTER_DEFAULT,
default => throw new \LogicException(sprintf('#[MapQueryParameter] cannot be used on controller argument "%s$%s" of type "%s"; one of array, string, int, float, bool or \BackedEnum should be used.', $argument->isVariadic() ? '...' : '', $argument->getName(), $type ?? 'mixed')),
default => throw new \LogicException(\sprintf('#[MapQueryParameter] cannot be used on controller argument "%s$%s" of type "%s"; one of array, string, int, float, bool or \BackedEnum should be used.', $argument->isVariadic() ? '...' : '', $argument->getName(), $type ?? 'mixed')),
},
};
@@ -106,7 +106,7 @@ final class QueryParameterValueResolver implements ValueResolverInterface
}
if (null === $value && !($attribute->flags & \FILTER_NULL_ON_FAILURE)) {
throw HttpException::fromStatusCode($validationFailedCode, sprintf('Invalid query parameter "%s".', $name));
throw HttpException::fromStatusCode($validationFailedCode, \sprintf('Invalid query parameter "%s".', $name));
}
if (!\is_array($value)) {
@@ -120,7 +120,7 @@ final class QueryParameterValueResolver implements ValueResolverInterface
}
if ($filtered !== $value && !($attribute->flags & \FILTER_NULL_ON_FAILURE)) {
throw HttpException::fromStatusCode($validationFailedCode, sprintf('Invalid query parameter "%s".', $name));
throw HttpException::fromStatusCode($validationFailedCode, \sprintf('Invalid query parameter "%s".', $name));
}
return $argument->isVariadic() ? $filtered : [$filtered];
@@ -65,6 +65,7 @@ class RequestPayloadValueResolver implements ValueResolverInterface, EventSubscr
private readonly SerializerInterface&DenormalizerInterface $serializer,
private readonly ?ValidatorInterface $validator = null,
private readonly ?TranslatorInterface $translator = null,
private string $translationDomain = 'validators',
) {
}
@@ -80,16 +81,16 @@ class RequestPayloadValueResolver implements ValueResolverInterface, EventSubscr
}
if (!$attribute instanceof MapUploadedFile && $argument->isVariadic()) {
throw new \LogicException(sprintf('Mapping variadic argument "$%s" is not supported.', $argument->getName()));
throw new \LogicException(\sprintf('Mapping variadic argument "$%s" is not supported.', $argument->getName()));
}
if ($attribute instanceof MapRequestPayload) {
if ('array' === $argument->getType()) {
if (!$attribute->type) {
throw new NearMissValueResolverException(sprintf('Please set the $type argument of the #[%s] attribute to the type of the objects in the expected array.', MapRequestPayload::class));
throw new NearMissValueResolverException(\sprintf('Please set the $type argument of the #[%s] attribute to the type of the objects in the expected array.', MapRequestPayload::class));
}
} elseif ($attribute->type) {
throw new NearMissValueResolverException(sprintf('Please set its type to "array" when using argument $type of #[%s].', MapRequestPayload::class));
throw new NearMissValueResolverException(\sprintf('Please set its type to "array" when using argument $type of #[%s].', MapRequestPayload::class));
}
}
@@ -118,7 +119,7 @@ class RequestPayloadValueResolver implements ValueResolverInterface, EventSubscr
$request = $event->getRequest();
if (!$argument->metadata->getType()) {
throw new \LogicException(sprintf('Could not resolve the "$%s" controller argument: argument should be typed.', $argument->metadata->getName()));
throw new \LogicException(\sprintf('Could not resolve the "$%s" controller argument: argument should be typed.', $argument->metadata->getName()));
}
if ($this->validator) {
@@ -137,7 +138,7 @@ class RequestPayloadValueResolver implements ValueResolverInterface, EventSubscr
if ($error->canUseMessageForUser()) {
$parameters['hint'] = $error->getMessage();
}
$message = $trans($template, $parameters, 'validators');
$message = $trans($template, $parameters, $this->translationDomain);
$violations->add(new ConstraintViolation($message, $template, $parameters, null, $error->getPath(), null));
}
$payload = $e->getData();
@@ -185,7 +186,7 @@ class RequestPayloadValueResolver implements ValueResolverInterface, EventSubscr
private function mapQueryString(Request $request, ArgumentMetadata $argument, MapQueryString $attribute): ?object
{
if (!$data = $request->query->all()) {
if (!($data = $request->query->all()) && ($argument->isNullable() || $argument->hasDefaultValue())) {
return null;
}
@@ -199,7 +200,7 @@ class RequestPayloadValueResolver implements ValueResolverInterface, EventSubscr
}
if ($attribute->acceptFormat && !\in_array($format, (array) $attribute->acceptFormat, true)) {
throw new UnsupportedMediaTypeHttpException(sprintf('Unsupported format, expects "%s", but "%s" given.', implode('", "', (array) $attribute->acceptFormat), $format));
throw new UnsupportedMediaTypeHttpException(\sprintf('Unsupported format, expects "%s", but "%s" given.', implode('", "', (array) $attribute->acceptFormat), $format));
}
if ('array' === $argument->getType() && null !== $attribute->type) {
@@ -212,7 +213,7 @@ class RequestPayloadValueResolver implements ValueResolverInterface, EventSubscr
return $this->serializer->denormalize($data, $type, null, $attribute->serializationContext + self::CONTEXT_DENORMALIZE + ('form' === $format ? ['filter_bool' => true] : []));
}
if ('' === $data = $request->getContent()) {
if ('' === ($data = $request->getContent()) && ($argument->isNullable() || $argument->hasDefaultValue())) {
return null;
}
@@ -223,11 +224,11 @@ class RequestPayloadValueResolver implements ValueResolverInterface, EventSubscr
try {
return $this->serializer->deserialize($data, $type, $format, self::CONTEXT_DESERIALIZE + $attribute->serializationContext);
} catch (UnsupportedFormatException $e) {
throw new UnsupportedMediaTypeHttpException(sprintf('Unsupported format: "%s".', $format), $e);
throw new UnsupportedMediaTypeHttpException(\sprintf('Unsupported format: "%s".', $format), $e);
} catch (NotEncodableValueException $e) {
throw new BadRequestHttpException(sprintf('Request payload contains invalid "%s" data.', $format), $e);
throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" data.', $format), $e);
} catch (UnexpectedPropertyException $e) {
throw new BadRequestHttpException(sprintf('Request payload contains invalid "%s" property.', $e->property), $e);
throw new BadRequestHttpException(\sprintf('Request payload contains invalid "%s" property.', $e->property), $e);
}
}
@@ -30,7 +30,7 @@ final class RequestValueResolver implements ValueResolverInterface
}
if (str_ends_with($argument->getType() ?? '', '\\Request')) {
throw new NearMissValueResolverException(sprintf('Looks like you required a Request object with the wrong class name "%s". Did you mean to use "%s" instead?', $argument->getType(), Request::class));
throw new NearMissValueResolverException(\sprintf('Looks like you required a Request object with the wrong class name "%s". Did you mean to use "%s" instead?', $argument->getType(), Request::class));
}
return [];
@@ -56,12 +56,12 @@ final class ServiceValueResolver implements ValueResolverInterface
return [$this->container->get($controller)->get($argument->getName())];
} catch (RuntimeException $e) {
$what = 'argument $'.$argument->getName();
$message = str_replace(sprintf('service "%s"', $argument->getName()), $what, $e->getMessage());
$what .= sprintf(' of "%s()"', $controller);
$message = str_replace(\sprintf('service "%s"', $argument->getName()), $what, $e->getMessage());
$what .= \sprintf(' of "%s()"', $controller);
$message = preg_replace('/service "\.service_locator\.[^"]++"/', $what, $message);
if ($e->getMessage() === $message) {
$message = sprintf('Cannot resolve %s: %s', $what, $message);
$message = \sprintf('Cannot resolve %s: %s', $what, $message);
}
throw new NearMissValueResolverException($message, $e->getCode(), $e);
@@ -32,7 +32,7 @@ final class UidValueResolver implements ValueResolverInterface
try {
return [$uidClass::fromString($value)];
} catch (\InvalidArgumentException $e) {
throw new NotFoundHttpException(sprintf('The uid for the "%s" parameter is invalid.', $argument->getName()), $e);
throw new NotFoundHttpException(\sprintf('The uid for the "%s" parameter is invalid.', $argument->getName()), $e);
}
}
}
@@ -31,7 +31,7 @@ final class VariadicValueResolver implements ValueResolverInterface
$values = $request->attributes->get($argument->getName());
if (!\is_array($values)) {
throw new \InvalidArgumentException(sprintf('The action argument "...$%1$s" is required to be an array, the request attribute "%1$s" contains a type of "%2$s" instead.', $argument->getName(), get_debug_type($values)));
throw new \InvalidArgumentException(\sprintf('The action argument "...$%1$s" is required to be an array, the request attribute "%1$s" contains a type of "%2$s" instead.', $argument->getName(), get_debug_type($values)));
}
return $values;