|
dmBridge PHP API
|
00001 <?php 00002 # 00003 # dmBridge: a data access framework for CONTENTdm(R) 00004 # 00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher 00006 # Education, on behalf of the University of Nevada, Las Vegas 00007 # 00008 00017 class DMAPISchemaController extends DMAbstractController { 00018 00019 private static function tryToOutputSchemaAtPath($schema_name, $path) { 00020 $it = new RecursiveDirectoryIterator($path); 00021 foreach (new RecursiveIteratorIterator($it) as $filename) { 00022 if (strpos(realpath($filename), "/.") === false) { 00023 if ($schema_name == basename($filename)) { 00024 header("Content-Type: " . DMMediaType::getTypeForExtension( 00025 DMHTTPRequest::getCurrent()->getURI()->getExtension())); 00026 die(file_get_contents($filename)); 00027 } 00028 } 00029 } 00030 } 00031 00032 public function index($schema_name) { 00033 if (!$schema_name) { 00034 header("HTTP/1.1 404 Not Found"); 00035 die; 00036 } 00037 // first, scan for built-in schemas 00038 self::tryToOutputSchemaAtPath($schema_name, 00039 dirname(__FILE__) . "/../../includes/schema"); 00040 00041 // not found, check modules 00042 $mm = DMModuleManager::getInstance(); 00043 foreach ($mm->getEnabledModules() as $module) { 00044 if ($module instanceof DMBridgeRepresentationSchemaModule) { 00045 self::tryToOutputSchemaAtPath($schema_name, 00046 $module->getPathToSchemas()); 00047 } 00048 } 00049 00050 $response = new DMHTTPResponse(); 00051 $rep = DMHTTPResponseFactory::getRepresentation(); 00052 $rep->setMediaType(new DMMediaType("text", "plain")); 00053 $rep->setBody("Schema not found"); 00054 $response->setStatusCode(404); 00055 $response->setRepresentation($rep); 00056 $response->send(); 00057 die; 00058 } 00059 00060 }