Schema
1 year ago
class-builder.php
1 year ago
class-schema.php
1 year ago
class-validation-exception.php
1 year ago
class-validator.php
1 year ago
class-validation-exception.php
44 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This file is part of the WooCommerce Email Editor package. |
| 4 | * |
| 5 | * @package Automattic\WooCommerce\EmailEditor |
| 6 | */ |
| 7 | |
| 8 | declare( strict_types = 1 ); |
| 9 | namespace Automattic\WooCommerce\EmailEditor\Validator; |
| 10 | |
| 11 | use Automattic\WooCommerce\EmailEditor\UnexpectedValueException; |
| 12 | use WP_Error; |
| 13 | |
| 14 | /** |
| 15 | * Exception thrown when validation fails. |
| 16 | */ |
| 17 | class Validation_Exception extends UnexpectedValueException { |
| 18 | /** |
| 19 | * WP_Error instance. |
| 20 | * |
| 21 | * @var WP_Error |
| 22 | */ |
| 23 | protected $wp_error; |
| 24 | |
| 25 | /** |
| 26 | * Creates a new instance of the exception. |
| 27 | * |
| 28 | * @param WP_Error $wp_error WP_Error instance. |
| 29 | */ |
| 30 | public static function create_from_wp_error( WP_Error $wp_error ): self { |
| 31 | $exception = self::create() |
| 32 | ->withMessage( $wp_error->get_error_message() ); |
| 33 | $exception->wp_error = $wp_error; |
| 34 | return $exception; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Returns the WP_Error instance. |
| 39 | */ |
| 40 | public function get_wp_error(): WP_Error { |
| 41 | return $this->wp_error; |
| 42 | } |
| 43 | } |
| 44 |