1
|
|
|
<?php |
2
|
|
|
namespace Flynt; |
3
|
|
|
|
4
|
|
|
use Flynt\Defaults; |
5
|
|
|
use Flynt\BuildConstructionPlan; |
6
|
|
|
use Flynt\Render; |
7
|
|
|
use Flynt\ComponentManager; |
8
|
|
|
use Flynt\Utils\Feature; |
9
|
|
|
use Dflydev\DotAccessData\Data; |
10
|
|
|
|
11
|
|
|
function initDefaults() |
12
|
|
|
{ |
13
|
|
|
Defaults::init(); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
function registerComponent($componentName, $componentPath = null) |
17
|
|
|
{ |
18
|
|
|
$componentManager = ComponentManager::getInstance(); |
19
|
|
|
$componentManager->registerComponent($componentName, $componentPath); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
function registerComponentsFromPath($componentBasePath) |
23
|
|
|
{ |
24
|
|
|
foreach (glob("{$componentBasePath}/*", GLOB_ONLYDIR) as $componentPath) { |
25
|
|
|
$componentName = basename($componentPath); |
26
|
|
|
registerComponent($componentName, $componentPath); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function registerFeaturesFromPath($featureBasePath) |
31
|
|
|
{ |
32
|
|
|
foreach (glob("{$featureBasePath}/*", GLOB_ONLYDIR) as $featurePath) { |
33
|
|
|
$featureName = basename($featurePath); |
34
|
|
|
Feature::register($featureName, $featureBasePath); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function renderComponent($componentName, $data) |
39
|
|
|
{ |
40
|
|
|
// var_dump($componentName, $data);die(); |
41
|
|
|
$data = apply_filters( |
42
|
|
|
'Flynt/addComponentData', |
43
|
|
|
$data, |
44
|
|
|
$componentName |
45
|
|
|
); |
46
|
|
|
$output = apply_filters( |
47
|
|
|
'Flynt/renderComponent', |
48
|
|
|
null, |
49
|
|
|
$componentName, |
50
|
|
|
$data |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
return is_null($output) ? '' : $output; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
add_filter('Flynt/renderComponent', function ($output, $componentName, $data) { |
57
|
|
|
return apply_filters( |
58
|
|
|
"Flynt/renderComponent?name={$componentName}", |
59
|
|
|
$output, |
60
|
|
|
$componentName, |
61
|
|
|
$data |
62
|
|
|
); |
63
|
|
|
}, 10, 3); |
64
|
|
|
|
65
|
|
|
add_filter('Flynt/addComponentData', function ($data, $componentName) { |
66
|
|
|
return apply_filters( |
67
|
|
|
"Flynt/addComponentData?name={$componentName}", |
68
|
|
|
$data, |
69
|
|
|
$componentName |
70
|
|
|
); |
71
|
|
|
}, 10, 2); |
72
|
|
|
|
73
|
|
|
function registerFields($scope, $fields, $fieldsId = null) |
74
|
|
|
{ |
75
|
|
|
global $flyntFields; |
76
|
|
|
$flyntFields = $flyntFields ?? []; |
77
|
|
|
if (empty($fieldsId)) { |
78
|
|
|
$flyntFields[$scope] = $fields; |
79
|
|
|
} else { |
80
|
|
|
$flyntFields[$scope] = $flyntFields[$scope] ?? []; |
81
|
|
|
$flyntFields[$scope][$fieldsId] = $fields; |
82
|
|
|
} |
83
|
|
|
return $fields; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
function loadFields($scope, $fieldPath = null) |
87
|
|
|
{ |
88
|
|
|
global $flyntFields; |
89
|
|
|
$flyntFields = $flyntFields ?? []; |
90
|
|
|
if (empty($fieldPath)) { |
91
|
|
|
return $flyntFields[$scope]; |
92
|
|
|
} else { |
93
|
|
|
$data = new Data($flyntFields[$scope]); |
94
|
|
|
return $data->get($fieldPath); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|