예제 #1
0
 /**
  * @static
  * @param AbstractProtoClass $proto
  * @param int $depth max depth
  * @param string $prefix
  * @param array $exclude
  * @return array
  */
 public static function getFullPropertyList(AbstractProtoClass $proto, $depth = 99, $prefix = '', $exclude = array())
 {
     $properties = $proto->getPropertyList();
     $values = array();
     foreach ($properties as $name => $prop) {
         $values[] = $prefix . $name;
         if ($prop->isIdentifier()) {
             $exclude[] = $prop->getClassName();
         }
         $class = $prop->getClassName();
         if (strlen($class) && is_subclass_of($class, Prototyped::class)) {
             if (!in_array($class, $exclude) && $depth > 0) {
                 $values = array_merge($values, self::getFullPropertyList($class::proto(), $depth - 1, $prefix . $prop->getName() . '.', $exclude));
             }
         }
     }
     return $values;
 }
예제 #2
0
 private function processPath(AbstractProtoClass $proto, $probablyPath, JoinCapableQuery $query, $table, $parentRequired = true, $prefix = null)
 {
     $path = explode('.', $probablyPath);
     try {
         $property = $proto->getPropertyByName($path[0]);
     } catch (MissingElementException $e) {
         // oh, it's a value, not a property
         return new DBValue($probablyPath);
     }
     unset($path[0]);
     Assert::isTrue($property->getRelationId() != null && !$property->isGenericType());
     Assert::classExists($property->getClassName());
     // checking whether we're playing with value object
     if (!method_exists($property->getClassName(), 'dao')) {
         if (method_exists($property->getClassName(), 'proto') && count($path) > 1) {
             return $this->processPath($property->getProto(), implode('.', $path), $query, $table);
         } else {
             return $this->guessAtom(implode('.', $path), $query, $table, $prefix);
         }
     } else {
         $propertyDao = call_user_func([$property->getClassName(), 'dao']);
         Assert::isNotNull($propertyDao, 'can not find target dao for "' . $property->getName() . '" property at "' . get_class($proto) . '"');
     }
     $alias = $propertyDao->getJoinName($property->getColumnName(), $prefix);
     if ($property->getRelationId() == MetaRelation::ONE_TO_MANY || $property->getRelationId() == MetaRelation::MANY_TO_MANY) {
         $remoteName = $property->getClassName();
         $selfName = $this->getObjectName();
         $self = new $selfName();
         $getter = $property->getGetter();
         $dao = call_user_func([$remoteName, 'dao']);
         if ($property->getRelationId() == MetaRelation::MANY_TO_MANY) {
             $helperTable = $self->{$getter}()->getHelperTable();
             $helperAlias = $helperTable;
             if (!$query->hasJoinedTable($helperAlias)) {
                 $logic = Expression::eq(DBField::create($this->getIdName(), $table), DBField::create($self->{$getter}()->getParentIdField(), $helperAlias));
                 if ($property->isRequired()) {
                     $query->join($helperTable, $logic, $helperAlias);
                 } else {
                     $query->leftJoin($helperTable, $logic, $helperAlias);
                 }
             }
             $logic = Expression::eq(DBField::create($propertyDao->getIdName(), $alias), DBField::create($self->{$getter}()->getChildIdField(), $helperAlias));
         } else {
             $logic = Expression::eq(DBField::create($self->{$getter}()->getParentIdField(), $alias), DBField::create($this->getIdName(), $table));
         }
         if (!$query->hasJoinedTable($alias)) {
             if ($property->isRequired() && $parentRequired) {
                 $query->join($dao->getTable(), $logic, $alias);
             } else {
                 $query->leftJoin($dao->getTable(), $logic, $alias);
             }
         }
     } else {
         // OneToOne, lazy OneToOne
         // prevents useless joins
         if (isset($path[1]) && count($path) == 1 && $path[1] == $propertyDao->getIdName()) {
             return new DBField($property->getColumnName(), $table);
         }
         if (!$query->hasJoinedTable($alias)) {
             $logic = Expression::eq(DBField::create($property->getColumnName(), $table), DBField::create($propertyDao->getIdName(), $alias));
             if ($property->isRequired() && $parentRequired) {
                 $query->join($propertyDao->getTable(), $logic, $alias);
             } else {
                 $query->leftJoin($propertyDao->getTable(), $logic, $alias);
             }
         }
     }
     if ($path) {
         return $propertyDao->guessAtom(implode('.', $path), $query, $alias, $property->isRequired() && $parentRequired, $propertyDao->getJoinPrefix($property->getColumnName(), $prefix));
     }
     // ok, we're done
 }