From 42c638b5d02cbb131d20eff3c92bd87d77b98415 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 15 Jan 2021 11:57:26 +0300 Subject: [PATCH] fix -- the order of searching for relation handlers, at first search in registered handlers, then try to check instance of base relations --- src/Domain/Relation/RelationHandlerResolver.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Domain/Relation/RelationHandlerResolver.php b/src/Domain/Relation/RelationHandlerResolver.php index 25ffcb6..7bc26d5 100644 --- a/src/Domain/Relation/RelationHandlerResolver.php +++ b/src/Domain/Relation/RelationHandlerResolver.php @@ -17,6 +17,15 @@ public function __construct(){ public function make( $relation ): RelationHandler { + // at first search in registered handlers, user can register his own handlers + $relationClass = get_class($relation); + + if($this->handlers->has($relationClass)) + { + return $this->handlers->get($relationClass); + } + + // then try to check is relation has instance of base relations $handler = $this->handlers->first(function (RelationHandler $handler) use ($relation){ $handlerRelation = $handler->relation(); return $relation instanceof $handlerRelation; @@ -27,6 +36,7 @@ public function make( $relation ): RelationHandler return $handler; } + // oops, not registered relation throw new DomainException(sprintf('RelationHandler for relation: %s is not registered', $relation)); }