From 52489821731ad290097cf129dda6754c710ad4a0 Mon Sep 17 00:00:00 2001 From: Erik Gaal Date: Wed, 15 Feb 2023 15:07:47 +0100 Subject: [PATCH] feat: allow customising instance creation --- src/ClassFactory.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ClassFactory.php b/src/ClassFactory.php index 84f560b..3a2538b 100644 --- a/src/ClassFactory.php +++ b/src/ClassFactory.php @@ -58,7 +58,7 @@ public function make(array | Closure $state = null): object $this->state($state); } - $object = new $this->class(...$this->collapseStates()); + $object = $this->newInstance($this->collapseStates()); foreach ($this->lateTransformers as $transformer) { $transformer($object); @@ -67,6 +67,15 @@ public function make(array | Closure $state = null): object return $object; } + /** + * @param array $properties + * @return T + */ + protected function newInstance(array $properties): object + { + return new $this->class(...$properties); + } + /** @return array */ private function collapseStates(): array {