Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Propel/Generator/Builder/Om/AbstractOMBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ public function declareClassNamespace($class, $namespace = '', $alias = false)
//so use the fqcn
return ($namespace ? '\\' . $namespace : '') . '\\' . $class;
} else {
$autoAliasName = 'Child' . $class;
// $autoAliasName = 'Child' . $class;
// FIXME: USE A DIFFERENT SYSTEM TO GENERATE AN UNIQUE NAME FOR THIS CLASS?
$autoAliasName = $class . md5($namespace);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, well, no md5 in names please :P

Copy link
Copy Markdown
Author

@Almamu Almamu Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That just change the aliases generated for class names (for the use in autogenerated classes, doesnt change any class name) I do agree that MD5 is not the best way, but there are not many ways of doing it. At first I though to generate a name based on the namespace and that could probably be better... for example, get the last namespace and concat it to the class name so a case like the one on the PR generates valid use statements that do not collide. That would generate aliases like MinecraftLaboratoriesAccount and ArcLaboratoriesAccount in case of a collision in the class name, but that could lead to more complex databases to have collisions too (for multiple namespaces or long namespaces, hence md5 does better job in those weird cases, but they are still weird cases anyway...). Would that be a better approach then?

}

return $this->declareClassNamespace($class, $namespace, $autoAliasName);
Expand Down Expand Up @@ -379,6 +381,11 @@ protected function needAliasForClassName($class, $namespace)
return true;
}
}

if (isset($this->declaredClasses[$this->getNamespace()][$class]) || isset($this->declaredClasses[$this->getNamespace()][str_replace("Query", "", $class)])) {
// classes that are already declared must be aliased to prevent collisions between namespaces
return true;
}

return false;
}
Expand Down