Completed
Push — master ( 481507...e81850 )
by Denis
01:52
created

GridViewHelper::loadConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Woo\GridView;
4
5
use Woo\GridView\Columns\ActionsColumn;
6
use Woo\GridView\Columns\AttributeColumn;
7
use Woo\GridView\Columns\RawColumn;
8
use Woo\GridView\Renderers\DefaultRenderer;
9
10
class GridViewHelper
11
{
12
    /**
13
     * A list of grid aliases
14
     * @var array
15
     */
16
    private static $aliases = [
17
        'column' => [
18
            'attribute' => AttributeColumn::class,
19
            'raw' => RawColumn::class,
20
            'actions' => ActionsColumn::class,
21
        ],
22
        'renderer' => [
23
            'default' => DefaultRenderer::class,
24
        ]
25
    ];
26
27
    private function __construct() {}
28
29
    /**
30
     * Allows to resolve class name by its alias
31
     * @param string $context
32
     * @param string $alias
33
     * @return mixed
34
     */
35
    public static function resolveAlias(string $context, string $alias)
36
    {
37
        return self::$aliases[$context][$alias] ?? $alias;
38
    }
39
40
    /**
41
     * Allows to convert options array to html string
42
     * @param array $htmlOptions
43
     * @param array $context - context is variables, which are allowed to use when property value calculated dynamically
44
     * @return string
45
     */
46
    public static function htmlOptionsToString(array $htmlOptions, array $context = []) : string
47
    {
48
        if (empty($htmlOptions)) {
49
            return '';
50
        }
51
52
        $out = [];
53
54
        foreach ($htmlOptions as $k => $v) {
55
56
            if ($v instanceof \Closure) {
57
                $v = call_user_func_array($v, $context);
58
            }
59
60
            $out[] = htmlentities($k) . '="' . htmlentities($v, ENT_COMPAT) . '"';
61
        }
62
63
        return implode(' ', $out);
64
    }
65
}