1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Cubiche package. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Cubiche |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Cubiche\Core\Bus\Exception; |
12
|
|
|
|
13
|
|
|
use RuntimeException; |
14
|
|
|
use Exception; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* NotFoundException class. |
18
|
|
|
* |
19
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class NotFoundException extends RuntimeException |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Creates an exception for a not found message name, method name or handler for a given message. |
25
|
|
|
* |
26
|
|
|
* @param string $type |
27
|
|
|
* @param mixed $message |
28
|
|
|
* @param Exception|null $cause |
29
|
|
|
* |
30
|
|
|
* @return NotFoundException |
31
|
|
|
*/ |
32
|
|
|
protected static function notFound($type, $message, Exception $cause = null) |
33
|
|
|
{ |
34
|
|
|
return new static(sprintf( |
35
|
|
|
'Not found a %s for a given object of type %s', |
36
|
|
|
$type, |
37
|
|
|
is_object($message) ? get_class($message) : gettype($message) |
38
|
|
|
), 0, $cause); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param mixed $object |
43
|
|
|
* @param Exception|null $cause |
44
|
|
|
* |
45
|
|
|
* @return NotFoundException |
46
|
|
|
*/ |
47
|
|
|
public static function nameOfMessage($object, Exception $cause = null) |
48
|
|
|
{ |
49
|
|
|
return self::notFound('name of message', $object, $cause); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param mixed $object |
54
|
|
|
* @param Exception|null $cause |
55
|
|
|
* |
56
|
|
|
* @return NotFoundException |
57
|
|
|
*/ |
58
|
|
|
public static function nameOfCommand($object, Exception $cause = null) |
59
|
|
|
{ |
60
|
|
|
return self::notFound('name of command', $object, $cause); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param mixed $object |
65
|
|
|
* @param Exception|null $cause |
66
|
|
|
* |
67
|
|
|
* @return NotFoundException |
68
|
|
|
*/ |
69
|
|
|
public static function handlerMethodNameForObject($object, Exception $cause = null) |
70
|
|
|
{ |
71
|
|
|
return self::notFound('handler method name', $object, $cause); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param mixed $object |
76
|
|
|
* @param Exception|null $cause |
77
|
|
|
* |
78
|
|
|
* @return NotFoundException |
79
|
|
|
*/ |
80
|
|
|
public static function nameOfQuery($object, Exception $cause = null) |
81
|
|
|
{ |
82
|
|
|
return self::notFound('name of query', $object, $cause); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $messageName |
87
|
|
|
* @param Exception|null $cause |
88
|
|
|
* |
89
|
|
|
* @return NotFoundException |
90
|
|
|
*/ |
91
|
|
|
public static function handlerFor($messageName, Exception $cause = null) |
92
|
|
|
{ |
93
|
|
|
return new static(sprintf( |
94
|
|
|
'Not found a handler for a given message named %s', |
95
|
|
|
$messageName |
96
|
|
|
), 0, $cause); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Creates an exception for a not found middleware. |
101
|
|
|
* |
102
|
|
|
* @param string $type |
103
|
|
|
* @param Exception|null $cause |
104
|
|
|
* |
105
|
|
|
* @return NotFoundException |
106
|
|
|
*/ |
107
|
|
|
public static function middlewareOfType($type, Exception $cause = null) |
108
|
|
|
{ |
109
|
|
|
return new static(sprintf( |
110
|
|
|
'Not found a middleware of type %s', |
111
|
|
|
$type |
112
|
|
|
), 0, $cause); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param mixed $object |
117
|
|
|
* @param string $method |
118
|
|
|
* @param Exception|null $cause |
119
|
|
|
* |
120
|
|
|
* @return NotFoundException |
121
|
|
|
*/ |
122
|
|
|
public static function methodForObject($object, $method, Exception $cause = null) |
123
|
|
|
{ |
124
|
|
|
return self::notFound('method with name `'.$method.'`', $object, $cause); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|