Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ThemeConfig
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __invoke
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * Theme config view helper
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2020.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  View_Helpers
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development Wiki
28 */
29
30namespace VuFind\View\Helper\Root;
31
32use Laminas\View\Helper\AbstractHelper;
33use VuFindTheme\ThemeInfo;
34
35/**
36 * Theme config view helper
37 *
38 * @category VuFind
39 * @package  View_Helpers
40 * @author   Demian Katz <demian.katz@villanova.edu>
41 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
42 * @link     https://vufind.org/wiki/development Wiki
43 */
44class ThemeConfig extends AbstractHelper
45{
46    /**
47     * ThemeInfo object to access themeConfig
48     *
49     * @var ThemeInfo
50     */
51    protected $themeInfo;
52
53    /**
54     * Constructor
55     *
56     * @param ThemeInfo $themeInfo ThemeInfo
57     */
58    public function __construct(ThemeInfo $themeInfo)
59    {
60        $this->themeInfo = $themeInfo;
61    }
62
63    /**
64     * Returns config by path
65     *
66     * Examples:
67     * - 'less' => all of less section
68     * - ['less'] => same as above
69     * - ['less', 'active'] => would return LESS active status
70     *
71     * @param string|string[] $path Path to return from theme.config.php
72     *
73     * @return mixed|null
74     */
75    public function __invoke($path = [])
76    {
77        // Ensure path is an array
78        $path = (array)$path;
79        $key = array_shift($path) ?? '';
80
81        $mergedConfig = $this->themeInfo->getMergedConfig($key);
82
83        // Follow the path
84        $nextNode = $mergedConfig;
85        foreach ($path as $p) {
86            $nextNode = $nextNode[$p] ?? null;
87        }
88
89        return $nextNode;
90    }
91}