M
M
Mark2022-01-16 17:44:23
Yii
Mark, 2022-01-16 17:44:23

How to skip parameters in Yii2 Dependency Container?

The class UnsavedPurchaseServicehas the following constructor:

public function __construct(OrderRepository $orders, Reporter $reporter)
    {
        $this->orders = $orders;
        $this->reporter = $reporter;
    }


OrderRepositoryis configured by the container itself, and Reporterthe interface, and you need to pass the implementation specifically under theUnsavedPurchaseService .

I need to skip the 1st parameter of the constructor so that the Container configures it itself, and set the second parameter explicitly. Something like this:
$container->set(UnsavedPurchaseService::class, ['', new TelegramReporter($service, $app->params['telegram.developerChat.id'])])


How can I do that?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question