|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU General Public License version 3 or later. |
|
9
|
|
|
* For the full copyright and license information, please read the |
|
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Api\Orcid; |
|
14
|
|
|
|
|
15
|
|
|
use Psr\Log\LoggerAwareInterface; |
|
16
|
|
|
use Psr\Log\LoggerAwareTrait; |
|
17
|
|
|
use TYPO3\CMS\Core\Http\RequestFactory; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* ORCID API Client class |
|
21
|
|
|
**/ |
|
22
|
|
|
class Client implements LoggerAwareInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use LoggerAwareTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* constants for API endpoint |
|
28
|
|
|
**/ |
|
29
|
|
|
const HOSTNAME = 'orcid.org'; |
|
30
|
|
|
const VERSION = '3.0'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The ORCID API endpoint |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
**/ |
|
37
|
|
|
private $endpoint = 'record'; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The ORCID API access level |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
**/ |
|
44
|
|
|
private $level = 'pub'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The ORCID to search for |
|
48
|
|
|
* |
|
49
|
|
|
* @var string |
|
50
|
|
|
**/ |
|
51
|
|
|
private $orcid = null; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* The request object |
|
55
|
|
|
* |
|
56
|
|
|
* @var RequestFactoryInterface |
|
|
|
|
|
|
57
|
|
|
**/ |
|
58
|
|
|
private $requestFactory = null; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Constructs a new instance |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $orcid: the ORCID to search for |
|
64
|
|
|
* @param RequestFactory $requestFactory a request object to inject |
|
65
|
|
|
* @return void |
|
66
|
|
|
**/ |
|
67
|
|
|
public function __construct($orcid, RequestFactory $requestFactory) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->orcid = $orcid; |
|
70
|
|
|
$this->requestFactory = $requestFactory; |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $endpoint the shortname of the endpoint |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setEndpoint($endpoint) { |
|
77
|
|
|
$this->endpoint = $endpoint; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get the profile data |
|
82
|
|
|
* |
|
83
|
|
|
* @return object |
|
84
|
|
|
* @throws Exception |
|
85
|
|
|
**/ |
|
86
|
|
|
public function getData() |
|
87
|
|
|
{ |
|
88
|
|
|
$url = $this->getApiEndpoint(); |
|
89
|
|
|
try { |
|
90
|
|
|
$response = $this->requestFactory->request($url); |
|
91
|
|
|
} catch (\Exception $e) { |
|
92
|
|
|
$this->logger->warning('Could not fetch data from URL "' . $url . '". Error: ' . $e->getMessage() . '.'); |
|
93
|
|
|
return false; |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
return $response->getBody()->getContents(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Creates the qualified API endpoint for retrieving the desired data |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $endpoint the shortname of the endpoint |
|
102
|
|
|
* @return string |
|
103
|
|
|
**/ |
|
104
|
|
|
private function getApiEndpoint() |
|
105
|
|
|
{ |
|
106
|
|
|
$url = 'https://' . $this->level . '.' . self::HOSTNAME; |
|
107
|
|
|
$url .= '/v' . self::VERSION . '/'; |
|
108
|
|
|
$url .= '0000-0001-9483-5161'; |
|
109
|
|
|
//$url .= $this->orcid; |
|
110
|
|
|
$url .= '/' . $this->endpoint; |
|
111
|
|
|
return $url; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths