Api   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 29
c 1
b 0
f 0
dl 0
loc 51
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A registerComponentsFromPath() 0 5 2
A registerComponent() 0 4 1
A renderComponent() 0 15 2
A registerHooks() 0 18 1
1
<?php
2
3
namespace Flynt;
4
5
use Flynt\ComponentManager;
6
7
class Api
8
{
9
    public static function registerComponent($componentName, $componentPath = null)
10
    {
11
        $componentManager = ComponentManager::getInstance();
12
        $componentManager->registerComponent($componentName, $componentPath);
13
    }
14
15
    public static function registerComponentsFromPath($componentBasePath)
16
    {
17
        foreach (glob("{$componentBasePath}/*", GLOB_ONLYDIR) as $componentPath) {
18
            $componentName = basename($componentPath);
19
            self::registerComponent($componentName, $componentPath);
20
        }
21
    }
22
23
    public static function renderComponent($componentName, $data)
24
    {
25
        $data = apply_filters(
26
            'Flynt/addComponentData',
27
            $data,
28
            $componentName
29
        );
30
        $output = apply_filters(
31
            'Flynt/renderComponent',
32
            null,
33
            $componentName,
34
            $data
35
        );
36
37
        return is_null($output) ? '' : $output;
38
    }
39
40
    public static function registerHooks()
41
    {
42
        add_filter('Flynt/renderComponent', function ($output, $componentName, $data) {
43
            return apply_filters(
44
                "Flynt/renderComponent?name={$componentName}",
45
                $output,
46
                $componentName,
47
                $data
48
            );
49
        }, 10, 3);
50
51
        add_filter('Flynt/addComponentData', function ($data, $componentName) {
52
            return apply_filters(
53
                "Flynt/addComponentData?name={$componentName}",
54
                $data,
55
                $componentName
56
            );
57
        }, 10, 2);
58
    }
59
}
60