dmBridge PHP API
DMBridgeVersion.php
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 
00013 abstract class DMBridgeVersion {
00014 
00015    const DMBRIDGE_VERSION_URL = "http://digital.library.unlv.edu/versions/dmbridge.php";
00016 
00020    private static function getVersionFilePathname() {
00021       return dirname(__FILE__) . "/../VERSION.txt";
00022    }
00023 
00030    private static function parseVersionFile($file, &$version, &$seq) {
00031       if (file_exists($file)) {
00032          $data = file_get_contents($file);
00033          $tmp = explode("\n", $data);
00034          $version = (string) substr($tmp[0], 0, 20);
00035          $seq = (int) substr($tmp[1], 0, 3);
00036       }
00037    }
00038 
00043    public static function getHTTPAPIVersions() {
00044       return array(1);
00045    }
00046 
00050    public static function getLatestHTTPAPIVersion() {
00051       return max(self::getHTTPAPIVersions());;
00052    }
00053 
00060    public static function getDmBridgeVersion() {
00061       $version = $seq = 0;
00062       self::parseVersionFile(self::getVersionFilePathname(), $version, $seq);
00063       return $version;
00064    }
00065 
00072    public static function getDmBridgeVersionSequence() {
00073       $version = $seq = 0;
00074       self::parseVersionFile(self::getVersionFilePathname(), $version, $seq);
00075       return $seq;
00076    }
00077 
00087    public static function getCurrentDmBridgeVersionSequence(DMHTTPRequest $req) {
00088       $req->setURI(new DMURI(self::DMBRIDGE_VERSION_URL));
00089       $client = new DMHTTPClient($req);
00090       $response = $client->send();
00091       return (int) substr($response->getRepresentation()->getBody(), 0, 4);
00092    }
00093 
00099    public static function isNewerDmBridgeVersionAvailable(DMHTTPRequest $req) {
00100       if (file_exists(self::getVersionFilePathname())) {
00101          return (self::getDmBridgeVersionSequence()
00102             < self::getCurrentDmBridgeVersionSequence($req));
00103       }
00104       return false;
00105    }
00106 
00107 }
 All Data Structures Functions Variables