laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.47k stars 419 forks source link

Unable to resolve dependency error #1123

Closed moeinpaki closed 3 years ago

moeinpaki commented 3 years ago

Description:

Hi, about this commit https://github.com/illuminate/container/commit/005d6b8c64c0c184a5bb26c565a8a458a3ee3d1f?_pjax=%23js-repo-pjax-container the newly added lines from line 177, it caused errors on my application, which started to break my legacy codes, because the variable name in my controller and my route was not the same, but before these changes, it was possible to have different variable names in route and controller.

I think this change will break APIs with older versions of Lumen when we try to run composer install again.

Steps To Reproduce:

SampleController.php

public function method( Request $request, string $unique_id )
{

}

routes.php $router->post('path/{item}/something', [ 'uses' => 'SampleController@method']);

this will throw an error Unable to resolve dependency [Parameter #1 [ <required> string $unique_id ]] in class SampleController

because the URL param name is item in routes and the variable name in the controller is $unique_id

GrahamCampbell commented 3 years ago

Lumen 6.3.0 is no longer supported (and neither is 7.x). Is this issue in Lumen 8?

moeinpaki commented 3 years ago

currently, I am using Lumen 6.3.0 on one of our old APIs which is for less than a year ago, and today we did composer install on the production environment, and then it started to produce this error.

I tried this on Lumen V8.1.0 and yes, It still exists.

driesvints commented 3 years ago

Your route parameter name doesn't matches your controller parameter name.

moeinpaki commented 3 years ago

I do realize that my route parameters do not match my controller parameter names. But since this has not been an issue previously, I have different names for my parameters on multiple projects. I'd like to mention again that I'm running Lumen Version 6 where matching route and controller parameter names were not required.

The problem arises when I try to deploy to the server, and in the build process once "composer install" is run on the project (which is built using the lumen version 6), this new check causes all my lumen v6 projects to crash due to backward incompatibility.

To summarize: this change is affecting older versions of Lumen as well. Matching parameters had not been an issue before.

driesvints commented 3 years ago

Thanks for explaining. This is similar to https://github.com/laravel/framework/issues/34920#issuecomment-717355358

Unfortunately we cannot revert this as it leads to bigger issues. Officially we never really supported route parameters which weren't named the same. Sorry.