dmBridge PHP API
DMModel.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 DMModel {
00014 
00015    private $objects = array();
00016 
00025    public final function addAssociatedModel($obj) {
00026       if (!is_object($obj)) {
00027          throw new DMIllegalArgumentException();
00028       }
00029       if (!in_array($obj, $this->objects)) {
00030          $this->objects[] = $obj;
00031       }
00032    }
00033 
00038    public final function getAssociatedModels() {
00039       return $this->objects;
00040    }
00041 
00048    public final function disassociateModel($obj) {
00049       if (!is_object($obj)) {
00050          throw new DMIllegalArgumentException();
00051       }
00052       for ($i = 0; $i < count($this->objects); $i++) {
00053          if ($this->objects[$i] === $obj) {
00054             unset($this->objects[$i]);
00055          }
00056       }
00057    }
00058 
00066    public function __call($method, $args) {
00067       foreach ($this->objects as $obj) {
00068          if (method_exists($obj, $method)) {
00069             return call_user_func_array(array($obj, $method), $args);
00070          }
00071       }
00072       throw new DMNoSuchMethodException($method);
00073    }
00074 
00082    public function __get($var) {
00083       if (property_exists($this, $var)) {
00084          return $this->$var;
00085       } else {
00086          foreach ($this->objects as $obj) {
00087             if (property_exists($obj, $var)) {
00088                return $obj->$var;
00089             }
00090          }
00091       }
00092       throw new DMNoSuchFieldException($var);
00093    }
00094 
00103    public function __set($var, $val) {
00104       $found = false;
00105       if (property_exists($this, $var)) {
00106          $found = true;
00107          $this->$var = $val;
00108       } else {
00109          foreach ($this->objects as $obj) {
00110             if (property_exists($obj, $var)) {
00111                $found = true;
00112                $obj->$var = $val;
00113             }
00114          }
00115       }
00116       if (!$found) {
00117          throw new DMNoSuchFieldException($var);
00118       }
00119    }
00120 
00121 }
 All Data Structures Functions Variables