dmBridge PHP API
DMObjectViewerDelegateManager.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 
00015 abstract class DMObjectViewerDelegateManager {
00016 
00020    private static $classes = array();
00021 
00026    public static function getNameForClass($class) {
00027       // constructor parameters are not important here
00028       $col = DMCollectionFactory::getCollection("/dmdefault");
00029       $obj = new DMObject($col, 1, DMDataStoreFactory::getDataStore(),
00030             DMConfigIni::getInstance());
00031       $type = new DMMediaType("animal", "cat");
00032       $instance = new $class($obj, $type, 500, 500);
00033       return $instance->getName();
00034    }
00035 
00039    private static function initializeClassArray() {
00040       // built-in viewers
00041       self::populateClassArrayWithPath(dirname(__FILE__));
00042       // custom viewers
00043       self::populateClassArrayWithPath(
00044             dirname(__FILE__) . "/../../extensions/viewers");
00045       natcasesort(self::$classes);
00046    }
00047 
00048    private static function populateClassArrayWithPath($path) {
00049       $it = new DirectoryIterator($path);
00050       foreach (new IteratorIterator($it) as $filename) {
00051          // skip hidden folders, such as .svn
00052          if (substr($filename, 0, 1) == ".") {
00053             continue;
00054          }
00055          if (strlen($filename) < 3) {
00056             continue;
00057          }
00058          if (!is_dir($path . "/" . $filename)) {
00059             continue;
00060          }
00061          if (!file_exists($path . "/" . $filename . "/" . $filename . ".php")) {
00062             continue;
00063          }
00064          $abs_path = $path . "/" . $filename . "/" . $filename . ".php";
00065          include_once($abs_path);
00066          $info = pathinfo($abs_path);
00067          if (array_key_exists("extension", $info)) {
00068             $class = basename($filename, "." . $info['extension']);
00069             if (interface_exists($class)) {
00070                continue;
00071             }
00072             $rclass = new ReflectionClass($class);
00073             if ($rclass->implementsInterface("DMObjectViewerDelegate")) {
00074                self::$classes[$class] = self::getNameForClass($class);
00075             }
00076          }
00077       }
00078    }
00079 
00085    public static function getAllViewerDelegateClassNames() {
00086       if (count(self::$classes) < 1) {
00087          self::initializeClassArray();
00088       }
00089       return array_keys(self::$classes);
00090    }
00091 
00097    public static function getAllViewerDelegateNames() {
00098       if (count(self::$classes) < 1) {
00099          self::initializeClassArray();
00100       }
00101       return self::$classes;
00102    }
00103 
00104 }
 All Data Structures Functions Variables