Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
CommitDocument | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getContentType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getContent | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * SOLR commit document class. |
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 Search |
25 | * @author David Maus <maus@hab.de> |
26 | * @author Demian Katz <demian.katz@villanova.edu> |
27 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
28 | * @link https://vufind.org |
29 | */ |
30 | |
31 | namespace VuFindSearch\Backend\Solr\Document; |
32 | |
33 | use XMLWriter; |
34 | |
35 | /** |
36 | * SOLR commit document class. |
37 | * |
38 | * @category VuFind |
39 | * @package Search |
40 | * @author David Maus <maus@hab.de> |
41 | * @author Demian Katz <demian.katz@villanova.edu> |
42 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
43 | * @link https://vufind.org |
44 | */ |
45 | class CommitDocument implements DocumentInterface |
46 | { |
47 | /** |
48 | * Value for commitWithin attribute |
49 | * |
50 | * @var int |
51 | */ |
52 | protected $commitWithin; |
53 | |
54 | /** |
55 | * Constructor. |
56 | * |
57 | * @param int $commitWithin commitWithin attribute value (-1 to omit) |
58 | */ |
59 | public function __construct(int $commitWithin = -1) |
60 | { |
61 | $this->commitWithin = $commitWithin; |
62 | } |
63 | |
64 | /** |
65 | * Return content MIME type. |
66 | * |
67 | * @return string |
68 | */ |
69 | public function getContentType(): string |
70 | { |
71 | return 'text/xml; charset=UTF-8'; |
72 | } |
73 | |
74 | /** |
75 | * Return serialized representation. |
76 | * |
77 | * @return string |
78 | */ |
79 | public function getContent(): string |
80 | { |
81 | $writer = new XMLWriter(); |
82 | $writer->openMemory(); |
83 | $writer->startDocument(); |
84 | $writer->startElement('commit'); |
85 | if ($this->commitWithin > 0) { |
86 | $writer->writeAttribute('commitWithin', $this->commitWithin); |
87 | } |
88 | $writer->endElement(); |
89 | $writer->endDocument(); |
90 | return $writer->flush(); |
91 | } |
92 | } |