Skip to content

Commit

Permalink
fix -- the order of searching for relation handlers, at first search …
Browse files Browse the repository at this point in the history
…in registered handlers, then try to check instance of base relations
  • Loading branch information
phoenix committed Jan 15, 2021
1 parent 7b723be commit 42c638b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Domain/Relation/RelationHandlerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

Expand Down

0 comments on commit 42c638b

Please sign in to comment.