1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Marwan Al-Soltany <[email protected]> |
5
|
|
|
* @copyright Marwan Al-Soltany 2020 |
6
|
|
|
* For the full copyright and license information, please view |
7
|
|
|
* the LICENSE file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace MAKS\AmqpAgent\Exception; |
13
|
|
|
|
14
|
|
|
use MAKS\AmqpAgent\Helper\ArrayProxy; |
15
|
|
|
use MAKS\AmqpAgent\Exception\PropertyDoesNotExistException; |
16
|
|
|
use MAKS\AmqpAgent\Exception\MethodDoesNotExistException; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* A trait to throw exceptions on calls to magic methods. |
20
|
|
|
* @since 1.2.0 |
21
|
|
|
*/ |
22
|
|
|
trait MagicMethodsExceptionsTrait |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Throws an exception when trying to get a class member via public property assignment notation. |
26
|
|
|
* @param string $property Property name. |
27
|
|
|
* @return void |
28
|
|
|
* @throws PropertyDoesNotExistException |
29
|
|
|
*/ |
30
|
1 |
|
public function __get(string $property) |
31
|
|
|
{ |
32
|
1 |
|
throw new PropertyDoesNotExistException( |
33
|
1 |
|
sprintf( |
34
|
1 |
|
'The requested property with the name "%s" does not exist!', |
35
|
1 |
|
$property |
36
|
|
|
) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Throws an exception when trying to set a class member via public property assignment notation. |
42
|
|
|
* @param string $property Property name. |
43
|
|
|
* @param array $value Property value. |
44
|
|
|
* @return void |
45
|
|
|
* @throws PropertyDoesNotExistException |
46
|
|
|
*/ |
47
|
1 |
|
public function __set(string $property, $value) |
48
|
|
|
{ |
49
|
1 |
|
throw new PropertyDoesNotExistException( |
50
|
1 |
|
sprintf( |
51
|
1 |
|
'A property with the name "%s" is immutable or does not exist!', |
52
|
1 |
|
$property |
53
|
|
|
) |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Throws an exception for calls to undefined methods. |
59
|
|
|
* @param string $method Function name. |
60
|
|
|
* @param array $parameters Function arguments. |
61
|
|
|
* @return mixed |
62
|
|
|
* @throws MethodDoesNotExistException |
63
|
|
|
*/ |
64
|
1 |
|
public function __call(string $method, $parameters) |
65
|
|
|
{ |
66
|
1 |
|
throw new MethodDoesNotExistException( |
67
|
1 |
|
sprintf( |
68
|
1 |
|
'The called method "%s" with the parameter(s) "%s" does not exist!', |
69
|
1 |
|
$method, |
70
|
1 |
|
ArrayProxy::castArrayToString($parameters) |
71
|
|
|
) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Throws an exception for calls to undefined static methods. |
77
|
|
|
* @param string $method Function name. |
78
|
|
|
* @param array $parameters Function arguments. |
79
|
|
|
* @return mixed |
80
|
|
|
* @throws MethodDoesNotExistException |
81
|
|
|
*/ |
82
|
1 |
|
public static function __callStatic(string $method, $parameters) |
83
|
|
|
{ |
84
|
1 |
|
throw new MethodDoesNotExistException( |
85
|
1 |
|
sprintf( |
86
|
1 |
|
'The called static method "%s" with the parameter(s) "%s" does not exist', |
87
|
1 |
|
$method, |
88
|
1 |
|
ArrayProxy::castArrayToString($parameters) |
89
|
|
|
) |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|