Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
JsonRecord
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 __get
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Simple, schema-less JSON record.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2010-2024.
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
31namespace VuFindSearch\Response;
32
33/**
34 * Simple, schema-less JSON record.
35 *
36 * This record primarily serves as an example or blueprint for a schema-less
37 * record. All fields are exposed via object properties.
38 *
39 * @category VuFind
40 * @package  Search
41 * @author   David Maus <maus@hab.de>
42 * @author   Demian Katz <demian.katz@villanova.edu>
43 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
44 * @link     https://vufind.org
45 */
46class JsonRecord implements RecordInterface
47{
48    use RecordTrait;
49
50    /**
51     * Constructor.
52     *
53     * @param array   $fields   Document fields
54     * @param ?string $sourceId Record source identifier (optional)
55     *
56     * @return void
57     */
58    public function __construct(protected array $fields, ?string $sourceId = null)
59    {
60        if ($sourceId) {
61            $this->setSourceIdentifiers($sourceId);
62        }
63    }
64
65    /**
66     * __get()
67     *
68     * @param string $name Field name
69     *
70     * @return mixed
71     */
72    public function __get($name)
73    {
74        return $this->fields[$name] ?? null;
75    }
76}