PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / app / Exceptions / ValidationException.php

ValidationException.php in Yatra – Travel Booking & Tour Operator Software trunk, at app/Exceptions/ValidationException.php

61 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Exceptions;
6
7 /**
8 * Validation Exception
9 *
10 * Thrown when input validation fails
11 */
12 class ValidationException extends YatraException
13 {
14 protected string $errorCode = 'validation_error';
15
16 /**
17 * @var array Validation errors by field
18 */
19 protected array $errors = [];
20
21 public function __construct(string $message = 'Validation failed', array $errors = [], int $code = 400, ?\Exception $previous = null)
22 {
23 $this->errors = $errors;
24 parent::__construct($message, $code, $previous, ['validation_errors' => $errors]);
25 }
26
27 /**
28 * Get validation errors
29 */
30 public function getErrors(): array
31 {
32 return $this->errors;
33 }
34
35 /**
36 * Add validation error for a field
37 */
38 public function addError(string $field, string $message): self
39 {
40 $this->errors[$field][] = $message;
41 $this->context['validation_errors'] = $this->errors;
42 return $this;
43 }
44
45 /**
46 * Check if field has errors
47 */
48 public function hasError(string $field): bool
49 {
50 return isset($this->errors[$field]) && !empty($this->errors[$field]);
51 }
52
53 /**
54 * Get errors for specific field
55 */
56 public function getFieldErrors(string $field): array
57 {
58 return $this->errors[$field] ?? [];
59 }
60 }
61