Skip to content

Commit 8011f1b

Browse files
committed
Add setting for the error detail element
1 parent 1aee967 commit 8011f1b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Transformer/ErrorDetailsTransformer.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010
*/
1111
final class ErrorDetailsTransformer implements TransformerInterface
1212
{
13+
/**
14+
* @var string
15+
*/
16+
private $detailsName;
17+
18+
/**
19+
* The constructor.
20+
*
21+
* @param string $detailsName The name of the details index.
22+
*/
23+
public function __construct(string $detailsName = 'details')
24+
{
25+
$this->detailsName = $detailsName;
26+
}
27+
1328
/**
1429
* Transform the given ValidationResult into an array.
1530
*
@@ -33,7 +48,7 @@ public function transform(ValidationResult $validationResult): array
3348

3449
$errors = $validationResult->getErrors();
3550
if ($errors) {
36-
$error['details'] = $this->getErrorDetails($errors);
51+
$error[$this->detailsName] = $this->getErrorDetails($errors);
3752
}
3853

3954
return ['error' => $error];

0 commit comments

Comments
 (0)