Completed
Push — master ( 1c115b...b55b98 )
by Nicola
06:56
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A silverstrap_settings() 0 13 3
A get_template_global_variables() 0 6 1
1
<?php
2
3
namespace eNTiDi\Silverstrap;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\View\ArrayData;
8
use SilverStripe\View\TemplateGlobalProvider;
9
10
/**
11
 * Provide access to the layout used by the Silverstrap theme.
12
 *
13
 * @package silverstrap
14
 * @subpackage code
15
 */
16
class Configuration implements TemplateGlobalProvider
17
{
18
    /**
19
     * Array of Silverstrap layouts available.
20
     */
21
    private static $layouts;
0 ignored issues
show
Unused Code introduced by
The property $layouts is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
22
23
24
    /**
25
     * Return the proper layout, depending on the controller.
26
     *
27
     * Check `docs/en/usage.md` to know the exact algorithm used to
28
     * look up the proper layout.
29
     */
30
    public static function silverstrap_settings()
31
    {
32
        $controller = Director::get_current_page();
33
        $layouts    = Config::inst()->get(self::class, 'layouts');
34
        if (array_key_exists($controller->SilverstrapLayout, $layouts)) {
35
            $layout = $controller->SilverstrapLayout;
36
        } elseif (array_key_exists($controller->class, $layouts)) {
37
            $layout = $controller->class;
38
        } else {
39
            $layout = 'default';
40
        }
41
        return ArrayData::create($layouts[$layout]);
42
    }
43
44
    public static function get_template_global_variables()
45
    {
46
        return [
47
            'Silverstrap' => 'silverstrap_settings',
48
        ];
49
    }
50
}
51