File tree Expand file tree Collapse file tree 4 files changed +109
-0
lines changed Expand file tree Collapse file tree 4 files changed +109
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use ApiClients \Client \Twitter \AsyncClient ;
4
+ use ApiClients \Client \Twitter \Resource \ProfileInterface ;
5
+ use React \EventLoop \Factory ;
6
+ use function ApiClients \Foundation \resource_pretty_print ;
7
+
8
+ require dirname (__DIR__ ) . DIRECTORY_SEPARATOR . 'vendor/autoload.php ' ;
9
+ $ config = require 'resolve_config.php ' ;
10
+
11
+ if (!isset ($ argv [1 ])) {
12
+ echo 'This example requires you to pass a username for example \'php profile-update-name-async.php "Cees-Jan %s Kiewiet" \'. ' , PHP_EOL ;
13
+ echo 'The %s in there will be replaced with a random emoji. ' , PHP_EOL ;
14
+ exit (255 );
15
+ }
16
+
17
+ $ loop = Factory::create ();
18
+ $ client = (new AsyncClient (
19
+ $ config ['consumer ' ]['key ' ],
20
+ $ config ['consumer ' ]['secret ' ],
21
+ $ loop
22
+ ))->withAccessToken (
23
+ $ config ['access_token ' ]['token ' ],
24
+ $ config ['access_token ' ]['secret ' ]
25
+ )->profile ()->done (function (ProfileInterface $ profile ) use ($ argv ) {
26
+ resource_pretty_print ($ profile );
27
+ $ emojis = [
28
+ '😈 ' ,
29
+ '👾 ' ,
30
+ '🤖 ' ,
31
+ '🦄 ' ,
32
+ '🐯 ' ,
33
+ '🦁 ' ,
34
+ '🐆 ' ,
35
+ '🐅 ' ,
36
+ '🐃 ' ,
37
+ '🐦 ' ,
38
+ '🦎 ' ,
39
+ '🐲 ' ,
40
+ '🐉 ' ,
41
+ '🦋 ' ,
42
+ '🐞 ' ,
43
+ '🕷 ' ,
44
+ '🕸 ' ,
45
+ '🍀 ' ,
46
+ '🍔 ' ,
47
+ '🥞 ' ,
48
+ '🌭 ' ,
49
+ '🍕 ' ,
50
+ '🍺 ' ,
51
+ '🍻 ' ,
52
+ '🥃 ' ,
53
+ '🌍 ' ,
54
+ '🌎 ' ,
55
+ '🌏 ' ,
56
+ '🌐 ' ,
57
+ '🗺 ' ,
58
+ '🏔 ' ,
59
+ '⛰ ' ,
60
+ '🌋 ' ,
61
+ '⛈ ' ,
62
+ '🌪 ' ,
63
+ '🌀 ' ,
64
+ '🌈 ' ,
65
+ '⚡ ' ,
66
+ '☃ ' ,
67
+ '☄ ' ,
68
+ '🔥 ' ,
69
+ '🎃 ' ,
70
+ '🎮 ' ,
71
+ '🔊 ' ,
72
+ '🎵 ' ,
73
+ '🎶 ' ,
74
+ ];
75
+ $ profile = $ profile ->withName (sprintf (
76
+ $ argv [1 ],
77
+ $ emojis [random_int (0 , count ($ emojis ) - 1 )]
78
+ ));
79
+ resource_pretty_print ($ profile );
80
+ });
81
+
82
+ $ loop ->run ();
Original file line number Diff line number Diff line change @@ -61,4 +61,14 @@ public function description() : string
61
61
{
62
62
return null ;
63
63
}
64
+
65
+
66
+ /**
67
+ * @param string $name
68
+ * @return ProfileInterface
69
+ */
70
+ public function withName (string $ name ): ProfileInterface
71
+ {
72
+ return clone $ this ;
73
+ }
64
74
}
Original file line number Diff line number Diff line change @@ -100,4 +100,15 @@ public function description() : string
100
100
{
101
101
return $ this ->description ;
102
102
}
103
+
104
+ /**
105
+ * @param string $name
106
+ * @return ProfileInterface
107
+ */
108
+ public function withName (string $ name ): ProfileInterface
109
+ {
110
+ $ clone = clone $ this ;
111
+ $ clone ->name = $ name ;
112
+ return $ clone ;
113
+ }
103
114
}
Original file line number Diff line number Diff line change @@ -42,4 +42,10 @@ public function profileLocation() : string;
42
42
* @return string
43
43
*/
44
44
public function description () : string ;
45
+
46
+ /**
47
+ * @param string $name
48
+ * @return static
49
+ */
50
+ public function withName (string $ name );
45
51
}
You can’t perform that action at this time.
0 commit comments