1 | <?php |
||
22 | final class CustomErrorMiddleware implements Middleware |
||
23 | { |
||
24 | /** @var \Closure(Error, RequestFailed) : \Exception */ |
||
25 | private $factory; |
||
26 | |||
27 | /** |
||
28 | * @param \Closure(Error, RequestFailed) : \Exception $factory |
||
29 | */ |
||
30 | private function __construct($factory) |
||
34 | |||
35 | /** |
||
36 | * Creates the middleware from a provided closure which receives |
||
37 | * `Tarantool\Client\Error` and `Tarantool\Client\Exception\RequestFailed` |
||
38 | * objects as arguments and should return a custom exception. |
||
39 | * |
||
40 | * Example: |
||
41 | * |
||
42 | * ```php |
||
43 | * $middleware = CustomErrorMiddleware::fromFactory( |
||
44 | * static function (Error $err, RequestFailed $ex) : \Exception { |
||
45 | * return 'UserNotFound' === $err->tryGetField('custom_type') |
||
46 | * ? new UserNotFound($err->getMessage(), $err->getCode(), $ex) |
||
47 | * : $ex; |
||
48 | * } |
||
49 | * ); |
||
50 | * ``` |
||
51 | */ |
||
52 | public static function fromFactory(\Closure $factory) : self |
||
60 | |||
61 | /** |
||
62 | * Creates the middleware from an array in which the keys are custom types |
||
63 | * of box.error objects and the corresponding values are fully qualified names |
||
64 | * of custom exception classes. |
||
65 | * |
||
66 | * Example: |
||
67 | * |
||
68 | * ```php |
||
69 | * $middleware = CustomErrorMiddleware::fromMapping([ |
||
70 | * 'UserNotFound' => UserNotFound::class, |
||
71 | * 'MyCustomType' => MyCustomException::class, |
||
72 | * ... |
||
73 | * ]); |
||
74 | * ``` |
||
75 | * |
||
76 | * @param array<string, class-string<\Exception>> $mapping |
||
77 | */ |
||
78 | public static function fromMapping(array $mapping) : self |
||
93 | |||
94 | /** |
||
95 | * Creates the middleware from the base namespace for the custom exception classes. |
||
96 | * The exception class name then will be in the format of "<namespace>/<lua_error.custom_type>". |
||
97 | * |
||
98 | * Example: |
||
99 | * |
||
100 | * ```php |
||
101 | * $middleware = CustomErrorMiddleware::fromNamespace('Foo\Bar'); |
||
102 | * ``` |
||
103 | */ |
||
104 | public static function fromNamespace(string $namespace) : self |
||
124 | |||
125 | public function process(Request $request, Handler $handler) : Response |
||
137 | } |
||
138 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.