Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
AbstractGeneratorPlugin | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
setOptions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
supportsVuFindLanguages | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFrequency | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSitemapName | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getUrls | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
verboseMsg | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Base class for sitemap generator plugins |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) The National Library of Finland 2021. |
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 Sitemap |
25 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development:plugins:ils_drivers Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Sitemap\Plugin; |
31 | |
32 | /** |
33 | * Base class for sitemap generator plugins |
34 | * |
35 | * @category VuFind |
36 | * @package Sitemap |
37 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
38 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
39 | * @link https://vufind.org/wiki/development:plugins:ils_drivers Wiki |
40 | */ |
41 | abstract class AbstractGeneratorPlugin implements GeneratorPluginInterface |
42 | { |
43 | /** |
44 | * Verbose message callback |
45 | * |
46 | * @var callable |
47 | */ |
48 | protected $verboseMessageCallback = null; |
49 | |
50 | /** |
51 | * Set plugin options. |
52 | * |
53 | * @param array $options Options |
54 | * |
55 | * @return void |
56 | */ |
57 | public function setOptions(array $options): void |
58 | { |
59 | $this->verboseMessageCallback = $options['verboseMessageCallback'] ?? null; |
60 | } |
61 | |
62 | /** |
63 | * Whether the URLs generated by the plugin support VuFind's lng parameter |
64 | * |
65 | * @return bool |
66 | */ |
67 | public function supportsVuFindLanguages(): bool |
68 | { |
69 | return true; |
70 | } |
71 | |
72 | /** |
73 | * Get update frequency. Empty string implies that the default from sitemap |
74 | * configuration should be used. |
75 | * |
76 | * @return string |
77 | */ |
78 | public function getFrequency(): string |
79 | { |
80 | return ''; |
81 | } |
82 | |
83 | /** |
84 | * Get the name of the sitemap used to create the sitemap file. This will be |
85 | * appended to the configured base name, and may be blank to use the base |
86 | * name without a suffix. |
87 | * |
88 | * @return string |
89 | */ |
90 | abstract public function getSitemapName(): string; |
91 | |
92 | /** |
93 | * Generate urls for the sitemap. |
94 | * |
95 | * May yield a string per URL or an array that defines language versions and/or |
96 | * frequency in addition to url. |
97 | * |
98 | * @return \Generator |
99 | */ |
100 | abstract public function getUrls(): \Generator; |
101 | |
102 | /** |
103 | * Write a verbose message (if callback is available and configured to do so) |
104 | * |
105 | * @param string $msg Message to display |
106 | * |
107 | * @return void |
108 | */ |
109 | protected function verboseMsg(string $msg): void |
110 | { |
111 | if ($this->verboseMessageCallback) { |
112 | ($this->verboseMessageCallback)($msg); |
113 | } |
114 | } |
115 | } |