Skip to content

Commit

Permalink
feat: allow customising instance creation
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgaal committed Feb 15, 2023
1 parent 2b4ab11 commit 5248982
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ClassFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -67,6 +67,15 @@ public function make(array | Closure $state = null): object
return $object;
}

/**
* @param array<string, mixed> $properties
* @return T
*/
protected function newInstance(array $properties): object
{
return new $this->class(...$properties);
}

/** @return array<string, mixed> */
private function collapseStates(): array
{
Expand Down

0 comments on commit 5248982

Please sign in to comment.