Skip to content

Commit 42c638b

Browse files
author
phoenix
committed
fix -- the order of searching for relation handlers, at first search in registered handlers, then try to check instance of base relations
1 parent 7b723be commit 42c638b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Domain/Relation/RelationHandlerResolver.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ public function __construct(){
1717

1818
public function make( $relation ): RelationHandler
1919
{
20+
// at first search in registered handlers, user can register his own handlers
21+
$relationClass = get_class($relation);
22+
23+
if($this->handlers->has($relationClass))
24+
{
25+
return $this->handlers->get($relationClass);
26+
}
27+
28+
// then try to check is relation has instance of base relations
2029
$handler = $this->handlers->first(function (RelationHandler $handler) use ($relation){
2130
$handlerRelation = $handler->relation();
2231
return $relation instanceof $handlerRelation;
@@ -27,6 +36,7 @@ public function make( $relation ): RelationHandler
2736
return $handler;
2837
}
2938

39+
// oops, not registered relation
3040
throw new DomainException(sprintf('RelationHandler for relation: %s is not registered', $relation));
3141
}
3242

0 commit comments

Comments
 (0)