getApplication()->getRequest(); $queryString = $request->getQueryString(); $queryArray = array(); if (isset($queryString)) { parse_str($queryString, $queryArray); } if (in_array('endpoint', array_keys($queryArray)) && isset($queryArray['journal'])) { $endpoint = $queryArray['endpoint']; return explode('/', trim($endpoint, '/')); } return null; } /** * Determines whether this router can route the given request. * @param $request PKPRequest * @return boolean true, if the router supports this request, otherwise false */ function supports($request) { $pathInfoParts = $this->getPathInfoParts(); if (!is_null($pathInfoParts) && count($pathInfoParts)>=2 && $pathInfoParts[1] == 'api') { // Context-specific API requests: [index.php]/{contextPath}/api return true; } return false; } /** * Get the API version * @return string */ function getVersion() { $pathInfoParts = $this->getPathInfoParts(); return Core::cleanFileVar(isset($pathInfoParts[2]) ? $pathInfoParts[2] : ''); } /** * Get the entity being requested * @return string */ function getEntity() { $pathInfoParts = $this->getPathInfoParts(); return Core::cleanFileVar(isset($pathInfoParts[3]) ? $pathInfoParts[3] : ''); } // // Implement template methods from PKPRouter // /** * @copydoc PKPRouter::route() */ function route($request) { // Ensure slim library is available require_once('lib/pkp/lib/vendor/autoload.php'); $sourceFile = sprintf('api/%s/%s/index.php', $this->getVersion(), $this->getEntity()); if (!file_exists($sourceFile)) { $dispatcher = $this->getDispatcher(); $dispatcher->handle404(); } if (!defined('SESSION_DISABLE_INIT')) { // Initialize session SessionManager::getManager(); } $this->_handler = require ('./'.$sourceFile); $this->_handler->getApp()->run(); } /** * Get the API handler. * @return APIHandler */ function getHandler() { return $this->_handler; } /** * Get the requested operation * * @param $request PKPRequest * @return string */ function getRequestedOp($request) { $handler = $this->getHandler(); $container = $handler->getApp()->getContainer(); $router = $container->get('router'); $request = $container->get('request'); $routeInfo = $router->dispatch($request); if (isset($routeInfo[1])) { $route = $router->lookupRoute($routeInfo[1]); $callable = $route->getCallable(); if (is_array($callable) && count($callable) == 2) return $callable[1]; } return ''; } /** * @copydoc PKPRouter::handleAuthorizationFailure() */ function handleAuthorizationFailure($request, $authorizationMessage) { $dispatcher = $this->getDispatcher(); $dispatcher->handle404(); } } ?>