Example #1
0
 public static function getDbObjects($name = null)
 {
     $objs = array();
     $o = (object) array('is_class' => false, 'is_irelationship' => false, 'keys' => array(), 'properties' => array(), 'parent' => NULL, 'relationships' => array());
     foreach (Orm::getRules($name) as $rule) {
         foreach ($rule as $name => $class) {
             if (!is_string($class)) {
                 continue;
             }
             if (!class_exists($class)) {
                 if (!isset($objs[$class])) {
                     $objs[$class] = clone $o;
                 }
                 continue;
             }
             $class_reflection = new ReflectionClass($class);
             do {
                 if (!$class_reflection->isInstantiable()) {
                     continue;
                 }
                 if (!isset($objs[$class_reflection->getName()])) {
                     $objs[$class_reflection->getName()] = clone $o;
                 }
             } while (($class_reflection = $class_reflection->getParentClass()) && $class_reflection->getName() != Orm::ORM_CLASS_CLASS && $class_reflection->getName() != Orm::ORM_CLASS_RELATIONSHIP);
             # check that we're not hitting the top
         }
         $objs[$rule->input]->relationships[$rule->relationship] = $rule->output;
     }
     foreach ($objs as $class => $o) {
         if ($o->is_class = class_exists($class) && is_subclass_of($class, Orm::ORM_CLASS_CLASS)) {
             $o->keys = Orm::getKeys($class);
             $o->properties = Orm::getProperties($class);
             $class_reflection = new ReflectionClass($class);
             while (($class_reflection = $class_reflection->getParentClass()) && $class_reflection->getName() != Orm::ORM_CLASS_CLASS && $class_reflection->getName() != Orm::ORM_CLASS_RELATIONSHIP) {
                 if (!$class_reflection->isInstantiable()) {
                     continue;
                 }
                 $o->parent = $class_reflection->getName();
                 break;
             }
         }
         if ($o->is_irelationship = class_exists($class) && is_subclass_of($class, Orm::ORM_CLASS_RELATIONSHIP)) {
             $o->properties = Orm::getProperties($class, true);
         }
         if ($o->keys == array(Orm::AUTO_PROPERTY_ID)) {
             array_unshift($o->properties, Orm::AUTO_PROPERTY_ID);
         }
     }
     return $objs;
 }