1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Riclep\Storyblok\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
|
7
|
|
|
class StubViewsCommand extends Command |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* The name and signature of the console command. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $signature = 'ls:stub-views {--O|overwrite}'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The console command description. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $description = 'Command description'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Create a new command instance. |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
public function __construct() |
29
|
|
|
{ |
30
|
|
|
parent::__construct(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Execute the console command. |
35
|
|
|
* |
36
|
|
|
* @return int |
37
|
|
|
*/ |
38
|
|
|
public function handle() |
39
|
|
|
{ |
40
|
|
|
$client = new \Storyblok\ManagementClient(config('storyblok.oauth_token')); |
41
|
|
|
|
42
|
|
|
$components = collect($client->get('spaces/' . config('storyblok.space_id') . '/components/')->getBody()['components']); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$components->each(function ($component) { |
45
|
|
|
$path = resource_path('views/' . str_replace('.', '/', config('storyblok.view_path')) . 'blocks/'); |
46
|
|
|
$filename = $component['name'] . '.blade.php'; |
47
|
|
|
|
48
|
|
|
if ($this->option('overwrite') || !file_exists($path . $filename)) { |
49
|
|
|
$content = file_get_contents(__DIR__ . '/stubs/blade.stub'); |
50
|
|
|
$content = str_replace('#NAME#', $component['name'], $content); |
51
|
|
|
|
52
|
|
|
$body = ''; |
53
|
|
|
|
54
|
|
|
foreach ($component['schema'] as $name => $field) { |
55
|
|
|
switch ($field['type']) { |
56
|
|
|
case 'bloks': |
57
|
|
|
$body .= "\t" . '@foreach ($block->' . $name . ' as $childBlock)' . "\n"; |
58
|
|
|
$body .= "\t\t" . '{{ $childBlock->render() }}' . "\n"; |
59
|
|
|
$body .= "\t" . '@endforeach' . "\n"; |
60
|
|
|
break; |
61
|
|
|
case 'datetime': |
62
|
|
|
case 'number': |
63
|
|
|
case 'text': |
64
|
|
|
$body .= "\t" . '<p>{{ $block->' . $name . ' }}</p>' . "\n"; |
65
|
|
|
break; |
66
|
|
|
case 'multilink': |
67
|
|
|
$body .= "\t" . '<a href="{{ $block->' . $name . '->cached_url }}"></a>' . "\n"; |
68
|
|
|
break; |
69
|
|
|
case 'options': |
70
|
|
|
$body .= "\t" . '@foreach ($block->' . $name . ' as $childBlock)' . "\n"; |
71
|
|
|
$body .= "\t\t\n"; |
72
|
|
|
$body .= "\t" . '@endforeach' . "\n"; |
73
|
|
|
break; |
74
|
|
|
case 'textarea': |
75
|
|
|
case 'richtext': |
76
|
|
|
$body .= "\t" . '<div>{!! $block->' . $name . ' !!}</div>' . "\n"; |
77
|
|
|
break; |
78
|
|
|
default: |
79
|
|
|
$body .= "\t" . '{{ $block->' . $name . ' }}' . "\n"; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$body .= "\n"; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$content = str_replace('#BODY#', $body, $content); |
86
|
|
|
|
87
|
|
|
file_put_contents($path . $filename, $content); |
88
|
|
|
|
89
|
|
|
$this->info('Created: '. $component['name'] . '.blade.php'); |
90
|
|
|
} |
91
|
|
|
}); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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.