sebastiaanluca / laravel-auto-morph-map

THIS PACKAGE HAS BEEN DEPRECATED — Automatically alias and map the polymorphic types of Eloquent models.

Home Page:https://sebastiaanluca.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException

thejacer87 opened this issue · comments

  • Laravel Version: 5.8.21
  • PHP Version: 7.3.4
  • Database Driver & Version: mysql 8.0.16
  • PHPUnit: 8.2.1

Description:

i'm getting this error after requiring laravel-auto-morph-map via composer. when i run phpunit i get a few fatal errors. not sure how/why the package would have messed it up. so any help would be great!

might have something to do with laravel/framework#26874, but it was closed 6 months ago without any answers from what i can tell. but there have been a few comments in the last month or so.

PHP Fatal error:  Cannot declare class App\Middleware\FixedStartSession, because the name is already in use in /app/app/Http/Middleware/FixedStartSession.php on line 21

PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php:958

Fatal error: Cannot declare class App\Middleware\FixedStartSession, because the name is already in use in /app/app/Http/Middleware/FixedStartSession.php on line 21

Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 958

Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 958

This is a known, unfixed bug in the laravel framework: laravel/framework#10808

This is a known, unfixed bug in the laravel framework: laravel/framework#10808

ic, thanks.

looks like you are one of the last commenters. did you figure out a solution? im trying a couple from the thread and not working yet.

any idea why enabling this package would trigger it for me?

I am also having same issue, did not get any solution yet

Is there something special or different about App\Middleware\FixedStartSession? The app/app section of /app/app/Http/Middleware/FixedStartSession.php seems a bit odd to me, but could be you have the app namespace in the app dir. Could you post your composer.json and morph map config file (if you have one)? Especially the namespace autoload sections are important here.

ya the /app/app comes from using lando. the lando docker containers put the application in /app inside the container.

composer.json: https://pastebin.com/Azumim0n

using default auto-morph-map.php

edit: hmmm. i just tried removing the FixedStartSession. and it might be a problem with that. at the very least i am getting errors about the session instead of the BindingResolutionException and co.

digging in, looks like this FixedStartSession is to " essentially a rewrite of Laravel's StartSession to save the session before * termination." according to the comments (i'm new to this project at work).

so maybe it is just something in this class. seems weird that it showed up only after adding this package

Can you post the FixedStartSession class? You can strip the contents of methods for privacy reasons if you don't want to share those. I think it's related to the namespace of the class. PHP namespace exceptions can be quite cryptic, but the error you're getting can mean your directory structure isn't identical to the used namespace and therefore it can't load the class. This package does some directory reading and autoloading, so it can happen it pops up like this.

Cannot declare class App\Middleware\FixedStartSession, because the name is already in use in /app/app/Http/Middleware/FixedStartSession.php on line 21

Probably App\Middleware vs App\Http\Middleware.

Additionally, in composer.json, I think the App namespace directory should be app/app, shouldn't it? But that depends on the server configuration, don't have any insight in that.

it does indeed have namespace App\Middleware; instead of App\Http\Middleware. and changing it and the path allowed phpunit to run

thanks so much for your help @sebastiaanluca

i'm still not sure how/if/why laravel/framework#10808 is a part of the problem here. of if this package needs a better error to handle the issue caused by laravel/framework#10808. but ya, that's for smarter people to handle :)

thanks again

Weird that you didn't have the error in the application itself. Should've been triggered by Laravel's autoloading, but glad it's resolved ;)

The exception you got can probably not be handled, as it's a namespace/autoloading issue. It's handled/thrown before any meaningful code gets executed. One to be aware of, had the same issue today and took a while before it hit me 😅

i think the app worked fine cuz in Kernel.php had the "right" key:

protected $middlewarePriority = [
       \App\Http\Middleware\FixedStartSession::class,
       ...
];