20 import(
'lib.pkp.classes.core.PKPRouter');
21 import(
'classes.core.Request');
22 import(
'classes.handler.Handler');
31 $pathInfoEnabled =
Config::getVar(
'general',
'disable_path_info') ? false :
true;
32 if ($pathInfoEnabled && isset($_SERVER[
'PATH_INFO'])) {
33 return explode(
'/', trim($_SERVER[
'PATH_INFO'],
'/'));
37 $queryString = $request->getQueryString();
38 $queryArray = array();
39 if (isset($queryString)) {
40 parse_str($queryString, $queryArray);
43 if (in_array(
'endpoint', array_keys($queryArray)) && isset($queryArray[
'journal'])) {
44 $endpoint = $queryArray[
'endpoint'];
45 return explode(
'/', trim($endpoint,
'/'));
59 if (!is_null($pathInfoParts) && count($pathInfoParts)>=2 && $pathInfoParts[1] ==
'api') {
93 require_once(
'lib/pkp/lib/vendor/autoload.php');
97 if (!file_exists($sourceFile)) {
99 http_response_code(
'404');
100 header(
'Content-Type: application/json');
102 'error' =>
'api.404.endpointNotFound',
103 'errorMessage' => __(
'api.404.endpointNotFound'),
108 if (!defined(
'SESSION_DISABLE_INIT')) {
113 $handler = require (
'./'.$sourceFile);
115 $handler->getApp()->run();
126 $container = $handler->getApp()->getContainer();
127 $router = $container->get(
'router');
128 $slimRequest = $handler->getSlimRequest();
129 $routeInfo = $router->dispatch($slimRequest);
130 if (isset($routeInfo[1])) {
131 $route = $router->lookupRoute($routeInfo[1]);
132 $callable = $route->getCallable();
133 if (is_array($callable) && count($callable) == 2)
144 http_response_code(
'403');
145 header(
'Content-Type: application/json');
147 'error' => $authorizationMessage,
148 'errorMessage' => __($authorizationMessage),
156 function url($request, $newContext =
null, $endpoint =
null,
$op =
null, $path =
null,
157 $params =
null, $anchor =
null, $escape =
false) {
162 if (!is_null(
$op) || !is_null($path) || !is_null($anchor) || !is_scalar($newContext)) {
163 throw new Exception(
'APIRouter::url() should not be called with an op, path or anchor. If a new context is passed, the context path must be passed instead of the context object.');
170 $baseUrl = array_shift($baseUrlAndContext);
171 $context = $baseUrlAndContext;
181 if ($request->isPathInfoEnabled()) {
183 $pathInfoArray = array_merge(
185 [
'api', API_VERSION, $endpoint]
187 $queryParametersArray = $additionalParameters;
191 $pathInfoArray = array();
192 $queryParametersArray = array_merge(
194 [sprintf(
'endpoint=/%s/api/%s/%s', $newContext, API_VERSION, $endpoint)],
195 $additionalParameters
199 return $this->
_urlFromParts($baseUrl, $pathInfoArray, $queryParametersArray, $anchor, $escape);