Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
InjectTemplateListener | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPrefixes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
inflectName | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | /** |
4 | * VuFind "Inject Template" Listener |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
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 Theme |
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 Main Site |
28 | */ |
29 | |
30 | namespace VuFindTheme; |
31 | |
32 | use function strlen; |
33 | |
34 | /** |
35 | * VuFind "Inject Template" Listener -- this extends the core MVC class to adjust |
36 | * default template configurations to something more appropriate for VuFind. |
37 | * |
38 | * @category VuFind |
39 | * @package Theme |
40 | * @author Demian Katz <demian.katz@villanova.edu> |
41 | * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> |
42 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
43 | * @link https://vufind.org Main Site |
44 | */ |
45 | class InjectTemplateListener extends \Laminas\Mvc\View\Http\InjectTemplateListener |
46 | { |
47 | /** |
48 | * List of prefixes for theme files |
49 | * |
50 | * @var array $prefixes |
51 | */ |
52 | protected $prefixes; |
53 | |
54 | /** |
55 | * InjectTemplateListener constructor. |
56 | * |
57 | * @param string[] $prefixes List of prefixes for theme files |
58 | */ |
59 | public function __construct(array $prefixes) |
60 | { |
61 | $this->prefixes = $prefixes; |
62 | } |
63 | |
64 | /** |
65 | * Get the prefixes recognized by the listener. |
66 | * |
67 | * @return string[] |
68 | */ |
69 | public function getPrefixes(): array |
70 | { |
71 | return $this->prefixes; |
72 | } |
73 | |
74 | /** |
75 | * Inflect a name to a normalized value |
76 | * |
77 | * @param string $name Name to inflect |
78 | * |
79 | * @return string |
80 | */ |
81 | protected function inflectName($name) |
82 | { |
83 | foreach ($this->prefixes as $prefix) { |
84 | if (str_starts_with($name, $prefix)) { |
85 | return strtolower(substr($name, strlen($prefix))); |
86 | } |
87 | } |
88 | return strtolower($name); |
89 | } |
90 | } |