Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 10 and Symfony 6 setDispatcher() function being provided wrong type #51650

Closed
SNett00 opened this issue May 30, 2024 · 2 comments
Closed

Comments

@SNett00
Copy link

SNett00 commented May 30, 2024

Laravel Version

10.10

PHP Version

8.1.0

Database Driver & Version

No response

Description

I am having an error occur while trying to execute composer update. The issue appears to be from $this->symfonyDispatcher being of an incorrect type.

Steps To Reproduce

When executing composer update this error is thrown:

Symfony\Component\Console\Application::setDispatcher(): Argument #1 ($dispatcher) must be of type Symfony\Contracts\EventDispatcher\EventDispatcherInterface, Symfony\Component\EventDispatcher\EventDispatcher given, called in /home/shawn/cwUpgrade2/cw/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php on line 486

Digging into this deeper I have found that $this->symfonyDispatcher within vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php is supposed to be of type Symfony\Contracts\EventDispatcher\EventDispatcherInterface but on line 141 is defined as Symfony\Component\EventDispatcher\EventDispatcher. When the function setDispatcher() is called on line 486 this causes an error as the function is expecting the type EventDispatcherInterface.

I have attempted to understand why on starting in Laravel 10.x the function getArtisan() was updated from:

protected function getArtisan()
{
    if (is_null($this->artisan)) {
        $this->artisan = (new Artisan($this->app, $this->events, $this->app->version()))
                                ->resolveCommands($this->commands)
                                ->setContainerCommandLoader();

        if ($this->symfonyDispatcher instanceof EventDispatcher) {
            $this->artisan->setDispatcher($this->symfonyDispatcher);
            $this->artisan->setSignalsToDispatchEvent();
        }
    }

    return $this->artisan;
}

while on Laravel 9.x it is this:

protected function getArtisan()
{
    if (is_null($this->artisan)) {
        $this->artisan = (new Artisan($this->app, $this->events, $this->app->version()))
                                ->resolveCommands($this->commands)
                                ->setContainerCommandLoader();
    }

    return $this->artisan;
}

A simple workaround would be to remove that added check as it seems unnecessary.

@crynobone
Copy link
Member

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@driesvints
Copy link
Member

Closing this issue because it's inactive, already solved, old or not relevant anymore. Feel to open up a new issue if you're still experiencing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants