I would like to wrap an existing service with another one, so, I've found that there is a delegator factory mechanism https://docs.mezzio.dev/mezzio/v3/features/container/delegator-factories/
The service is very simple and I've mostly copy-pasted the example in documentation.
Even without simplification the service looks something like this
class MoneyService {
public function __constructor(LoggerService $logger) {
$this->logger = $logger;
}
}
To check that delegator factory works I've created it like this. Just to be sure that the real service was built correctly.
class MoneyServiceDelegatorFactory
{
public function __invoke(ContainerInterface $container, string $name, callable $callback)
{
var_dump($name, $callback());
die;
}
}
And finally I wire it with configureation
'dependencies' => [
'delegators' => [
MoneyService::class => [
MoneyServiceDelegatorFactory::class,
],
],
],
If I try to check if the container has the MoneyService instance then it is true - $container->has(MoneyService::class) === true
.
So, in the delegator factory I expect the result of $callback()
to be an instance of a MoneyService class. But instead I get null.