10
10
use Exception ;
11
11
use GuzzleHttp \Client ;
12
12
use GuzzleHttp \Exception \ClientException ;
13
+ use GuzzleHttp \Utils ;
13
14
use Illuminate \Console \Command ;
14
15
use Illuminate \Support \Arr ;
15
16
use Illuminate \Support \Str ;
16
17
17
18
class RetrieveExtensions extends Command
18
19
{
19
- protected $ signature = 'extensions:retrieve ' ;
20
+ protected $ signature = 'extensions:retrieve {q?} ' ;
20
21
protected $ description = 'Retrieve extensions via Packagist ' ;
21
22
22
23
protected Client $ client ;
@@ -34,19 +35,23 @@ public function handle()
34
35
{
35
36
$ url = '/search.json?type=flarum-extension ' ;
36
37
38
+ if ($ this ->hasArgument ('q ' )) {
39
+ $ url .= '&q= ' . urlencode ($ this ->argument ('q ' ));
40
+ }
41
+
37
42
while ($ url ) {
38
43
$ this ->info ("Reading $ url " );
39
44
40
45
$ response = $ this ->client ->get ($ url );
41
- $ data = \ GuzzleHttp \json_decode ($ response ->getBody ()->getContents (), true );
46
+ $ data = Utils:: jsonDecode ($ response ->getBody ()->getContents (), true );
42
47
43
48
$ packages = Arr::get ($ data , 'results ' , []);
44
49
45
50
foreach ($ packages as $ package ) {
46
51
$ packageName = Arr::get ($ package , 'name ' );
47
52
$ this ->info ("Saving $ packageName " );
48
53
49
- $ details = Arr::get (\ GuzzleHttp \json_decode ($ this ->client ->get ("/packages/ $ packageName.json " )->getBody ()->getContents (), true ), 'package ' , []);
54
+ $ details = Arr::get (Utils:: jsonDecode ($ this ->client ->get ("/packages/ $ packageName.json " )->getBody ()->getContents (), true ), 'package ' , []);
50
55
51
56
$ versions = Arr::get ($ details , 'versions ' , []);
52
57
0 commit comments