I'm using php-di 6.0.10
I have the interface implementation in my DI config:
\App\Writer\WriterInterface::class => DI\get(\App\Writer\Text::class)
It has constructor like this:
class TextWriter implements WriterInterface
...
public function __construct(Settings $settings, DataConverter $dataConverter, string $filePath)
{
$this->init($filePath);
$this->settings = $settings;
$this->dataConverter = $dataConverter;
}
In my app I want to instantiate writer with dynamic $filePath parameter:
$this->container->make(WriterInterface::class, ['filePath' => $this->getFilePath()]);
But I get this error:
DI\Definition\Exception\InvalidDefinition: Entry "App\Writer\Text" cannot be resolved: Parameter $filePath of __construct() has no value defined or guessable Full definition: Object ( class = App\Writer\Text lazy = false __construct( $settings = get(App\Settings) $dataConverter = get(App\DataConverter) $filePath = #UNDEFINED# )
What is wrong? I dig into DI code and see that it handles my definition like \DI\Definition\SelfResolvingDefinition and doesn't pass the parameters to resolve() method. It works only if I explicitly specify the interface implementation - App\Writer\Text fot the make() method. But I need to have dynamic interface implementation.
How to get it working the way I want?