1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Riclep\Storyblok\Traits; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use App\Storyblok\DefaultBlock; |
|
|
|
|
8
|
|
|
use Illuminate\Support\Facades\Config; |
9
|
|
|
use Illuminate\Support\Str; |
10
|
|
|
|
11
|
|
|
trait ProcessesBlocks |
12
|
|
|
{ |
13
|
|
|
private function processBlock($block, $key) { |
14
|
|
|
if (is_array($block) && !array_key_exists('component', $block)) { |
15
|
|
|
$block['component'] = $this->getComponentType($block, $key); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
$blockType = $this->getBlockType($block, $key); |
19
|
|
|
|
20
|
|
|
if ($blockType) { |
21
|
|
|
return $blockType; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
return $block ?: false; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
private function getBlockType($block, $key) { |
29
|
|
|
if (is_int($key) && $this->isUuid($block)) { |
30
|
|
|
$child = $this->childStory($block); |
|
|
|
|
31
|
|
|
$blockClass = $this->getBlockClass($child['content']['component']); |
32
|
|
|
|
33
|
|
|
return new $blockClass($child, $key); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if (!in_array($key, ['id', 'uuid', 'group_id']) && $this->isUuid($block)) { |
37
|
|
|
$child = $this->childStory($block); |
38
|
|
|
$blockClass = $this->getBlockClass($child['content']['component']); |
39
|
|
|
|
40
|
|
|
return new $blockClass($child, $key); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if (is_array($block)) { |
44
|
|
|
return $this->arrayBlock($block, $key); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return false; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Works out the component type - this can come from either the component specified in |
52
|
|
|
* the response from Storyblok or, in the case of plugins, the plugin name is used |
53
|
|
|
*/ |
54
|
|
|
private function getComponentType($block, $key) { |
55
|
|
|
if (array_key_exists('plugin', $block)) { |
56
|
|
|
return $block['plugin']; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (array_key_exists('component', $block) && !is_null($block['component'])) { |
60
|
|
|
return $block['component']; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $key; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function arrayBlock($block, $key) { |
67
|
|
|
$blockClass = $this->getBlockClass($block['component']); |
68
|
|
|
|
69
|
|
|
// or return the default block |
70
|
|
|
return new $blockClass($block, $key); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function getBlockClass($component) { |
74
|
|
|
|
75
|
|
|
//dump($this, $component, '------------------------'); |
76
|
|
|
|
77
|
|
|
if (class_exists(config('storyblok.component_class_namespace') . Str::studly($component) . 'Block')) { |
78
|
|
|
return config('storyblok.component_class_namespace') . Str::studly($component) . 'Block'; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return config('storyblok.component_class_namespace') . 'DefaultBlock'; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Check if a given string is a valid UUID |
86
|
|
|
* |
87
|
|
|
* @param string $uuid The string to check |
88
|
|
|
* @return boolean |
89
|
|
|
*/ |
90
|
|
|
private function isUuid( $uuid ) { |
91
|
|
|
return !(!is_string($uuid) || (preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', $uuid) !== 1)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
private function processStoryblokKeys($block) { |
95
|
|
|
$this->_uid = $block['_uid'] ?? null; |
|
|
|
|
96
|
|
|
$this->component = $block['component'] ?? null; |
|
|
|
|
97
|
|
|
$this->content = collect(array_diff_key($block, array_flip(['_editable', '_uid', 'component', 'plugin']))); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths