1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Riclep\Storyblok\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
|
8
|
|
|
class ComponentViewCommand extends Command |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* The name and signature of the console command. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $signature = 'ls:component-list |
17
|
|
|
{--additional-fields= : Additional fields to pull form Storyblok Management API}'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'List all storyblok components.'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Create a new command instance. |
28
|
|
|
*/ |
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
parent::__construct(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Execute the console command. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function handle() |
40
|
|
|
{ |
41
|
|
|
$managementClient = new \Storyblok\ManagementClient(config('storyblok.oauth_token')); |
42
|
|
|
|
43
|
|
|
$resp = $managementClient->get('spaces/'.config('storyblok.space_id').'/components'); |
44
|
|
|
$components = collect($resp->getBody()['components']); |
|
|
|
|
45
|
|
|
|
46
|
|
|
$additionalFields = $this->option('additional-fields') ? |
47
|
|
|
Str::of($this->option('additional-fields'))->explode(',') |
48
|
|
|
: collect(); |
49
|
|
|
|
50
|
|
|
$rows = $components->map(function ($c) use ($additionalFields) { |
51
|
|
|
$mapped = [ |
52
|
|
|
'name' => $c['name'], |
53
|
|
|
'display_name' => $c['display_name'], |
54
|
|
|
'has_image' => $c['image'] ? "<fg=green>true</>" : '<fg=red>false</>', |
55
|
|
|
'has_template' => $c['preview_tmpl'] ? "<fg=green>true</>" : '<fg=red>false</>', |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
$mappedAdditional = collect($c)->only($additionalFields); |
59
|
|
|
|
60
|
|
|
return array_merge($mapped, $mappedAdditional->toArray()); |
61
|
|
|
}); |
62
|
|
|
|
63
|
|
|
$this->table( |
64
|
|
|
array_keys($rows->first()), |
65
|
|
|
$rows |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.