Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
AbstractSyndetics | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getHttpClient | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getIsbnUrl | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
xmlToDOMDocument | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * Abstract base for Syndetics content loader plug-ins. |
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 Content |
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/wiki/development Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Content; |
31 | |
32 | use DOMDocument; |
33 | |
34 | /** |
35 | * Abstract base for Syndetics content loader plug-ins. |
36 | * |
37 | * @category VuFind |
38 | * @package Content |
39 | * @author Demian Katz <demian.katz@villanova.edu> |
40 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
41 | * @link https://vufind.org/wiki/development Wiki |
42 | */ |
43 | abstract class AbstractSyndetics extends AbstractBase |
44 | { |
45 | /** |
46 | * Use SSL URLs? |
47 | * |
48 | * @var bool |
49 | */ |
50 | protected $useSSL; |
51 | |
52 | /** |
53 | * Use Syndetics plus? |
54 | * |
55 | * @var bool |
56 | */ |
57 | protected $usePlus; |
58 | |
59 | /** |
60 | * HTTP timeout for API calls (in seconds) |
61 | * |
62 | * @var int |
63 | */ |
64 | protected $timeout; |
65 | |
66 | /** |
67 | * Constructor |
68 | * |
69 | * @param bool $useSSL Use SSL URLs? |
70 | * @param bool $usePlus Use Syndetics Plus? |
71 | * @param int $timeout HTTP timeout for API calls (in seconds) |
72 | */ |
73 | public function __construct($useSSL = false, $usePlus = false, $timeout = 10) |
74 | { |
75 | $this->useSSL = $useSSL; |
76 | $this->usePlus = $usePlus; |
77 | $this->timeout = $timeout; |
78 | } |
79 | |
80 | /** |
81 | * Get an HTTP client |
82 | * |
83 | * @param string $url URL for client to use |
84 | * |
85 | * @return \Laminas\Http\Client |
86 | * @throws \Exception |
87 | */ |
88 | protected function getHttpClient($url = null) |
89 | { |
90 | $client = parent::getHttpClient($url); |
91 | $client->setOptions(['timeout' => $this->timeout]); |
92 | return $client; |
93 | } |
94 | |
95 | /** |
96 | * Get the Syndetics URL for making a request. |
97 | * |
98 | * @param string $isbn ISBN to load |
99 | * @param string $id Client ID |
100 | * @param string $file File to request |
101 | * @param string $type Type parameter |
102 | * |
103 | * @return string |
104 | */ |
105 | protected function getIsbnUrl($isbn, $id, $file = 'index.xml', $type = 'rw12,h7') |
106 | { |
107 | $baseUrl = $this->useSSL |
108 | ? 'https://secure.syndetics.com' : 'http://syndetics.com'; |
109 | $url = $baseUrl . '/index.aspx?isbn=' . $isbn |
110 | . '/' . $file . '&client=' . $id . '&type=' . $type; |
111 | $this->debug('Syndetics request: ' . $url); |
112 | return $url; |
113 | } |
114 | |
115 | /** |
116 | * Turn an XML response into a DOMDocument object. |
117 | * |
118 | * @param string $xml XML to load. |
119 | * |
120 | * @return DOMDocument|bool Document on success, false on failure. |
121 | */ |
122 | protected function xmlToDOMDocument($xml) |
123 | { |
124 | $dom = new DOMDocument(); |
125 | return $dom->loadXML($xml) ? $dom : false; |
126 | } |
127 | } |