File tree Expand file tree Collapse file tree 5 files changed +42
-23
lines changed Expand file tree Collapse file tree 5 files changed +42
-23
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,6 @@ class DataFetcher
21
21
private string $ type ;
22
22
private int $ group_id ;
23
23
private string $ event_id ;
24
- protected \Closure $ callable_sort ;
25
24
26
25
27
26
/**
@@ -58,25 +57,6 @@ public function getEventId(): string
58
57
59
58
public function __construct (private ?object $ data = null )
60
59
{
61
- $ this ->callable_sort = fn ($ data ) => array_walk ($ data , function ($ value , $ property ) {
62
- if (property_exists ($ this , $ property )) {
63
-
64
- if ($ property === "peer_id " && $ value - 2000000000 > 0 ) {
65
- $ this ->chat_id = $ value - 2000000000 ;
66
- }
67
-
68
- if ($ property === "payload " ) {
69
- $ this ->payload = match (gettype ($ value )) {
70
- "object " => (array ) $ value ,
71
- "string " => @json_decode ($ value , true ),
72
- "array " => $ value ,
73
- };
74
- } else {
75
- $ this ->$ property = $ value ;
76
- }
77
- }
78
- });
79
-
80
60
if ($ data ?->type === "message_new " ) {
81
61
$ this ->client_info = $ data ?->object->client_info ;
82
62
}
Original file line number Diff line number Diff line change 10
10
namespace Astaroth \DataFetcher \Events ;
11
11
12
12
use Astaroth \DataFetcher \DataFetcher ;
13
+ use Astaroth \DataFetcher \Sort ;
13
14
14
15
/**
15
16
* Class MessageEvent
18
19
*/
19
20
final class MessageEvent extends DataFetcher
20
21
{
22
+ use Sort;
23
+
21
24
private int $ peer_id ;
22
25
private int $ user_id ;
23
26
private int $ conversation_message_id ;
@@ -29,7 +32,7 @@ final class MessageEvent extends DataFetcher
29
32
public function __construct (?object $ data = null )
30
33
{
31
34
parent ::__construct ($ data );
32
- ( $ this ->callable_sort ) ($ data ?->object);
35
+ $ this ->sort ($ data ?->object);
33
36
}
34
37
35
38
/**
Original file line number Diff line number Diff line change 10
10
11
11
12
12
use Astaroth \DataFetcher \DataFetcher ;
13
+ use Astaroth \DataFetcher \Sort ;
13
14
14
15
/**
15
16
* Class MessageNew
19
20
*/
20
21
final class MessageNew extends DataFetcher
21
22
{
23
+ use Sort;
24
+
22
25
private int $ id ;
23
26
private int $ out ;
24
27
private int $ date ;
@@ -51,7 +54,7 @@ final class MessageNew extends DataFetcher
51
54
public function __construct (?object $ data = null )
52
55
{
53
56
parent ::__construct ($ data );
54
- ( $ this ->callable_sort ) ($ data ?->object->message );
57
+ $ this ->sort ($ data ?->object->message );
55
58
}
56
59
57
60
/**
Original file line number Diff line number Diff line change 8
8
namespace Astaroth \DataFetcher \Events ;
9
9
10
10
use Astaroth \DataFetcher \DataFetcher ;
11
+ use Astaroth \DataFetcher \Sort ;
11
12
12
13
/**
13
14
* Class WallPostNew
14
15
* @package Astaroth\DataFetcher\Events
15
16
*/
16
17
final class WallPostNew extends DataFetcher
17
18
{
19
+ use Sort;
20
+
18
21
private int $ id ;
19
22
private int $ from_id ;
20
23
private int $ owner_id ;
@@ -33,7 +36,7 @@ final class WallPostNew extends DataFetcher
33
36
public function __construct (?object $ data = null )
34
37
{
35
38
parent ::__construct ($ data );
36
- ( $ this ->callable_sort ) ($ data ?->object-> message );
39
+ $ this ->sort ($ data ?->object);
37
40
}
38
41
39
42
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Astaroth \DataFetcher ;
6
+
7
+ trait Sort
8
+ {
9
+ private function sort ($ data ): void
10
+ {
11
+ array_walk ($ data , function ($ value , $ property ) {
12
+ if (property_exists ($ this , $ property )) {
13
+
14
+ if ($ property === "peer_id " && $ value - 2000000000 > 0 ) {
15
+ $ this ->chat_id = $ value - 2000000000 ;
16
+ }
17
+
18
+ if ($ property === "payload " ) {
19
+ $ this ->payload = match (gettype ($ value )) {
20
+ "object " => (array )$ value ,
21
+ "string " => @json_decode ($ value , true ),
22
+ "array " => $ value ,
23
+ };
24
+ } else {
25
+ $ this ->$ property = $ value ;
26
+ }
27
+ }
28
+ });
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments