13
13
14
14
use Longman \TelegramBot \Entities \InlineQuery \InlineEntity ;
15
15
use Longman \TelegramBot \Entities \InputMedia \InputMedia ;
16
- use Longman \TelegramBot \Exception \UndefinedPropertyException ;
17
16
18
17
/**
19
18
* Class Entity
@@ -29,6 +28,9 @@ abstract class Entity implements \JsonSerializable
29
28
{
30
29
public static $ fixThumbnailRename = true ;
31
30
31
+ public $ bot_username = '' ;
32
+ public $ raw_data = [];
33
+
32
34
private $ fields = [];
33
35
34
36
/**
@@ -41,46 +43,34 @@ abstract class Entity implements \JsonSerializable
41
43
*/
42
44
public function __construct (array $ data , string $ bot_username = '' )
43
45
{
44
- //Make sure we're not raw_data inception-ing
45
- if (array_key_exists ('raw_data ' , $ data )) {
46
- if ($ data ['raw_data ' ] === null ) {
47
- unset($ data ['raw_data ' ]);
48
- }
49
- } else {
50
- $ data ['raw_data ' ] = $ data ;
51
- }
46
+ $ this ->bot_username = $ bot_username ;
47
+ $ this ->raw_data = $ data ;
52
48
53
- $ data ['bot_username ' ] = $ bot_username ;
54
49
$ this ->assignMemberVariables ($ data );
55
50
$ this ->validate ();
56
51
}
57
52
58
53
/**
59
- * Dynamically sets a parameter .
54
+ * Dynamically set a field .
60
55
*
61
56
* @param string $name
62
- * @param $value
57
+ * @param mixed $value
63
58
* @return void
64
59
*/
65
- public function __set (string $ name , $ value ) : void
60
+ public function __set (string $ name , mixed $ value ): void
66
61
{
67
62
$ this ->fields [$ name ] = $ value ;
68
63
}
69
64
70
65
/**
71
- * Gets a dynamic parameter .
66
+ * Gets a dynamic field .
72
67
*
73
68
* @param string $name
74
69
* @return mixed|null
75
70
*/
76
71
public function __get (string $ name )
77
72
{
78
- if (! isset ($ this ->fields [$ name ])) {
79
- $ class = static ::class;
80
- throw new UndefinedPropertyException ("Undefined property: {$ class }:: \${$ name }" );
81
- }
82
-
83
- return $ this ->fields [$ name ];
73
+ return $ this ->fields [$ name ] ?? null ;
84
74
}
85
75
86
76
/**
0 commit comments