laravel/framework

Argument typehint should use contract class instead of implementaiton class

jitendra-1217 opened this issue · 1 comments

  • Laravel Version: >=5.4.*
  • PHP Version: 7.*
  • Database Driver & Version: Not applicable

Description:

I am working on a package where I extend 'queue' service following way, where QueueManager is some class of mine, lets say which of course implements the contarct -

$this->app->extend(
    'queue',
    function (\Illuminate\Contracts\Queue\Factory $factory) use ($config) {
        return new QueueManager($factory);
    }
);

Doing this causes an issue where laravel's Queue/Worker's constructor has arg type-hinting for actual implementation instead of the contract. Below is that line for reference -

/**
* Create a new queue worker.
*
* @param \Illuminate\Queue\QueueManager $manager
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @param \Illuminate\Contracts\Debug\ExceptionHandler $exceptions
* @return void
*/
public function __construct(QueueManager $manager,
Dispatcher $events,
ExceptionHandler $exceptions)

Steps To Reproduce:

Explained as part of description ^ above.

Resolution:

Suggesting to use \Illuminate\Contracts\Queue\Factory instead of \Illuminate\Queue\QueueManager for the argument type hinting at above place i.e. Worker.php

I will file a pr as it is not much effort, but will wait for comments.

Heya, thanks for submitting this. This seems like a feature request or an improvement. It's best to post these at the laravel/ideas repository to get support for your idea. After that you may send a PR to the framework. Please only use this issue tracker to report bugs and issues with the framework.