-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mat Jordan
committed
May 3, 2021
1 parent
307f5b9
commit c4d11e6
Showing
5 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<IfModule mod_rewrite.c> | ||
RewriteEngine On | ||
RewriteRule ^(.*)$ index.php?url=/$1 [QSA,L] | ||
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
require "../run.php"; | ||
|
||
use Src\Collection; | ||
|
||
header("Access-Control-Allow-Origin: *"); | ||
header("Content-Type: application/json; charset=UTF-8"); | ||
header("Access-Control-Allow-Methods: GET"); | ||
header("Access-Control-Max-Age: 3600"); | ||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"); | ||
|
||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); | ||
$uri = explode( '/', $uri ); | ||
|
||
// the namespace must be an string | ||
if (isset($uri[3])) { | ||
$namespace = $uri[3]; | ||
} | ||
|
||
// the persistentIdentifier PID must be an int | ||
if (isset($uri[4])) { | ||
$id = $uri[4]; | ||
} | ||
|
||
if (isset($namespace) && isset($id)) { | ||
|
||
$requestMethod = $_SERVER["REQUEST_METHOD"]; | ||
|
||
$controller = new Collection($requestMethod, array($namespace, $id)); | ||
$controller->processRequest(); | ||
|
||
} else { | ||
|
||
header("HTTP/1.1 404 Not Found"); | ||
exit(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Src; | ||
|
||
error_reporting(E_ALL); | ||
|
||
class Collection | ||
{ | ||
|
||
private $requestMethod; | ||
private $persistentIdentifier; | ||
|
||
public function __construct($requestMethod, $persistentIdentifier) | ||
{ | ||
|
||
$this->requestMethod = $requestMethod; | ||
$this->persistentIdentifier = $persistentIdentifier; | ||
|
||
} | ||
|
||
public function processRequest() | ||
{ | ||
|
||
switch ($this->requestMethod) { | ||
case 'GET': | ||
$response = self::theCollection(); | ||
break; | ||
default: | ||
$response = self::noFoundResponse(); | ||
break; | ||
} | ||
|
||
print $response; | ||
|
||
} | ||
|
||
private function theCollection() | ||
{ | ||
|
||
$persistentIdentifier = implode('%3A', $this->persistentIdentifier); | ||
$object = Request::getObjects($persistentIdentifier); | ||
|
||
if ($object['status'] === 200) : | ||
$model = simplexml_load_string($object['body'])->objModels->model; | ||
if (self::isCollection($model)) : | ||
$object = Request::getObjects($persistentIdentifier, 'XML', true); | ||
return json_encode($object); | ||
else : | ||
$object['body'] = 'Object ' . str_replace('%3A', ':', $persistentIdentifier) . ' is not of object model islandora:collectionCModel.'; | ||
return json_encode($object); | ||
endif; | ||
else : | ||
return json_encode($object); | ||
endif; | ||
|
||
} | ||
|
||
private static function isCollection ($islandoraModel) { | ||
|
||
$model = Utility::xmlToArray($islandoraModel); | ||
|
||
if (in_array('info:fedora/islandora:collectionCModel', $model)) : | ||
return true; | ||
else: | ||
return false; | ||
endif; | ||
|
||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters