A
A
Artemio Vegas2021-05-12 17:39:58
symfony
Artemio Vegas, 2021-05-12 17:39:58

How to override dependency injection via setter in descendant?

Good day!
there is an abstract class that defines a setter for dependency injection

abstract class FastDealsCreatingDelegate
{
    protected $fastDealsService;

    /**
     * @required
     *
     * @param NewFastDealsManagerService $fastDealsService
     */
    public function setService(NewFastDealsManagerService $fastDealsService)
    {
        $this->fastDealsService = $fastDealsService;
    }
}


We implement the successor, in it I want to override the injected dependency

class FastDealsOpenbankPayoutsCreatingDelegate extends FastDealsCreatingDelegate
{
    /**
     * @required
     *
     * @param NewFastDealsManagerService $fastDealsService
     */
    public function setService(OpenbankPayoutsFastDealsManageService $fastDealsService)
    {
        $this->fastDealsService = $fastDealsService;
    }
}


the class OpenbankPayoutsFastDealsManageService is a successor of NewFastDealsManagerService

What the error is that - Warning: Declaration should be compatible

Tell me, is it possible to change the type of injected dependency in this case?

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