Skip to content

Commit f7a45a8

Browse files
committed
FlexibleMultiplier accepts entity or component
1 parent a8a247b commit f7a45a8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/UI/FlexibleMultiplier.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@ public function __construct(callable $getter, callable $factory)
2727
}
2828

2929
/**
30-
* @param mixed $entity
30+
* @param object $entityOrComponent
3131
* @param string|int $name
3232
*/
33-
public function add($entity, $name): IComponent
33+
public function add($entityOrComponent, $name): IComponent
3434
{
3535
if (empty($name) && $name !== 0) {
3636
throw new InvalidArgumentException('Argument $name must not be an empty');
3737
}
3838

39-
$this->addComponent($component = ($this->factory)($entity), (string) $name);
39+
$component = $entityOrComponent;
40+
if (!$component instanceof Component) {
41+
$component = ($this->factory)($entityOrComponent);
42+
}
43+
44+
$this->addComponent($component, (string) $name);
4045

4146
return $this->static[] = $component;
4247
}

0 commit comments

Comments
 (0)