Allow passing strings (names of invokable classes) to Formatter extender

In preparation for fixing #1703.
This commit is contained in:
Franz Liedke 2018-12-15 12:05:17 +01:00
parent 2c6398b8e3
commit e27cd69974

View File

@ -21,7 +21,7 @@ class Formatter implements ExtenderInterface, LifecycleInterface
{ {
protected $callback; protected $callback;
public function configure(callable $callback) public function configure($callback)
{ {
$this->callback = $callback; $this->callback = $callback;
@ -34,8 +34,14 @@ class Formatter implements ExtenderInterface, LifecycleInterface
$events->listen( $events->listen(
Configuring::class, Configuring::class,
function (Configuring $event) { function (Configuring $event) use ($container) {
call_user_func($this->callback, $event->configurator); if (is_string($this->callback)) {
$callback = $container->make($this->callback);
} else {
$callback = $this->callback;
}
$callback($event->configurator);
} }
); );
} }