Skip to content

Commit

Permalink
Call factory method if available
Browse files Browse the repository at this point in the history
  • Loading branch information
TiiFuchs committed May 10, 2022
1 parent 4f12995 commit a98d1c6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Types/CastsToTelegramTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ protected function objectify(mixed $value, \ReflectionType $types, string $phpDo
continue;
}

return array_map(fn($data) => new $class($data), $value);
return is_subclass_of($class, Factory::class)
? array_map(fn($data) => $class::factory($data), $value)
: array_map(fn($data) => new $class($data), $value);

} elseif (is_array($value)) {

Expand All @@ -43,8 +45,9 @@ protected function objectify(mixed $value, \ReflectionType $types, string $phpDo
continue;
}

return new $class($value);

return is_subclass_of($class, Factory::class)
? $class::factory($value)
: new $class($value);
}

}
Expand Down

0 comments on commit a98d1c6

Please sign in to comment.