Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
OaiController | |
0.00% |
0 / 32 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
homeAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
authserverAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
serverAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
handleOAI | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | /** |
4 | * OAI Module Controller |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2011. |
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 Controller |
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:plugins:controllers Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Controller; |
31 | |
32 | use VuFindApi\Formatter\RecordFormatter; |
33 | |
34 | /** |
35 | * OAIController Class |
36 | * |
37 | * Controls the OAI server |
38 | * |
39 | * @category VuFind |
40 | * @package Controller |
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/wiki/development:plugins:controllers Wiki |
44 | */ |
45 | class OaiController extends AbstractBase |
46 | { |
47 | /** |
48 | * Display OAI server form. |
49 | * |
50 | * @return \Laminas\View\Model\ViewModel |
51 | */ |
52 | public function homeAction() |
53 | { |
54 | // no action needed |
55 | return $this->createViewModel(); |
56 | } |
57 | |
58 | /** |
59 | * Standard OAI server. |
60 | * |
61 | * @return \Laminas\Http\Response |
62 | */ |
63 | public function authserverAction() |
64 | { |
65 | return $this->handleOAI(\VuFind\OAI\Server\Auth::class); |
66 | } |
67 | |
68 | /** |
69 | * Standard OAI server. |
70 | * |
71 | * @return \Laminas\Http\Response |
72 | */ |
73 | public function serverAction() |
74 | { |
75 | return $this->handleOAI(\VuFind\OAI\Server::class); |
76 | } |
77 | |
78 | /** |
79 | * Shared OAI logic. |
80 | * |
81 | * @param string $serverClass Class to load for handling OAI requests. |
82 | * |
83 | * @return \Laminas\Http\Response |
84 | */ |
85 | protected function handleOAI($serverClass) |
86 | { |
87 | // Check if the OAI Server is enabled before continuing |
88 | $config = $this->getConfig(); |
89 | $response = $this->getResponse(); |
90 | if (!isset($config->OAI)) { |
91 | $response->setStatusCode(404); |
92 | $response->setContent('OAI Server Not Configured.'); |
93 | return $response; |
94 | } |
95 | |
96 | // Collect relevant parameters for OAI server: |
97 | $url = explode('?', $this->getServerUrl()); |
98 | $baseURL = $url[0]; |
99 | |
100 | // Build OAI response or die trying: |
101 | try { |
102 | $params = array_merge( |
103 | $this->getRequest()->getQuery()->toArray(), |
104 | $this->getRequest()->getPost()->toArray() |
105 | ); |
106 | $server = $this->serviceLocator->get($serverClass); |
107 | $server->init($config, $baseURL, $params); |
108 | $server->setRecordLinkerHelper( |
109 | $this->getViewRenderer()->plugin('recordLinker') |
110 | ); |
111 | $server->setRecordFormatter( |
112 | $this->serviceLocator->get(RecordFormatter::class) |
113 | ); |
114 | $xml = $server->getResponse(); |
115 | } catch (\Exception $e) { |
116 | $response->setStatusCode(500); |
117 | $response->setContent($e->getMessage()); |
118 | return $response; |
119 | } |
120 | |
121 | // Return response: |
122 | $headers = $response->getHeaders(); |
123 | $headers->addHeaderLine('Content-type', 'text/xml; charset=UTF-8'); |
124 | $response->setContent($xml); |
125 | return $response; |
126 | } |
127 | } |