Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
RawDocument
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getContentType
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getContent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * SOLR "raw document" class for submitting any type of data.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 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  Search
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
28 */
29
30namespace VuFindSearch\Backend\Solr\Document;
31
32/**
33 * SOLR "raw document" class for submitting any type of data.
34 *
35 * @category VuFind
36 * @package  Search
37 * @author   Demian Katz <demian.katz@villanova.edu>
38 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
39 * @link     https://vufind.org
40 */
41class RawDocument implements DocumentInterface
42{
43    /**
44     * Raw document text
45     *
46     * @var string
47     */
48    protected $content;
49
50    /**
51     * MIME type
52     *
53     * @var string
54     */
55    protected $mime;
56
57    /**
58     * Text encoding
59     *
60     * @var string
61     */
62    protected $encoding;
63
64    /**
65     * Constructor.
66     *
67     * @param string  $content  Raw document text
68     * @param string  $mime     MIME type
69     * @param ?string $encoding Text encoding (null for unspecified)
70     */
71    public function __construct(
72        string $content,
73        string $mime,
74        ?string $encoding = 'UTF-8'
75    ) {
76        $this->content = $content;
77        $this->mime = $mime;
78        $this->encoding = $encoding;
79    }
80
81    /**
82     * Return content MIME type.
83     *
84     * @return string
85     */
86    public function getContentType(): string
87    {
88        return $this->mime
89            . (empty($this->encoding) ? '' : '; charset=' . $this->encoding);
90    }
91
92    /**
93     * Return serialized representation.
94     *
95     * @return string
96     */
97    public function getContent(): string
98    {
99        return $this->content;
100    }
101}