PHP-DI / Slim-Bridge

PHP-DI integration with the Slim framework
http://php-di.org/doc/frameworks/slim.html
MIT License
176 stars 38 forks source link

Error during controller invocation #81

Closed greezlu closed 1 year ago

greezlu commented 1 year ago

Got error below during controller invocation.

Slim Application Error

The application could not run because of the following error:

Details

Type: Invoker\Exception\NotEnoughParametersException Code: 0 Message: Unable to invoke the callable because no value was given for parameter 3 ($args) File: /var/www/html/vendor/php-di/invoker/src/Invoker.php Line: 67

Trace

#0 /var/www/html/vendor/php-di/slim-bridge/src/ControllerInvoker.php(48): Invoker\Invoker->call(Array, Array)
#1 /var/www/html/vendor/slim/slim/Slim/Routing/Route.php(358): DI\Bridge\Slim\ControllerInvoker->__invoke(Array, Object(Slim\Psr7\Request), Object(Slim\Psr7\Response), Array)
#2 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(65): Slim\Routing\Route->handle(Object(Slim\Psr7\Request))
#3 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(65): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request))
#4 /var/www/html/vendor/slim/slim/Slim/Routing/Route.php(315): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request))
#5 /var/www/html/vendor/slim/slim/Slim/Routing/RouteRunner.php(68): Slim\Routing\Route->run(Object(Slim\Psr7\Request))
#6 /var/www/html/app/Middleware/DefaultMiddleware.php(33): Slim\Routing\RouteRunner->handle(Object(Slim\Psr7\Request))
#7 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(168): App\Middleware\DefaultMiddleware->process(Object(Slim\Psr7\Request), Object(Slim\Routing\RouteRunner))
#8 /var/www/html/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(76): class@anonymous->handle(Object(Slim\Psr7\Request))
#9 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(121): Slim\Middleware\ErrorMiddleware->process(Object(Slim\Psr7\Request), Object(class@anonymous))
#10 /var/www/html/vendor/slim/twig-view/src/TwigMiddleware.php(115): class@anonymous->handle(Object(Slim\Psr7\Request))
#11 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(121): Slim\Views\TwigMiddleware->process(Object(Slim\Psr7\Request), Object(class@anonymous))
#12 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(65): class@anonymous->handle(Object(Slim\Psr7\Request))
#13 /var/www/html/vendor/slim/slim/Slim/App.php(199): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request))
#14 /var/www/html/vendor/slim/slim/Slim/App.php(183): Slim\App->handle(Object(Slim\Psr7\Request))
#15 /var/www/html/pub/index.php(25): Slim\App->run()
#16 {main}

Description

composer.json

"php": "7.4",
"slim/slim": "4.11.0"
"php-di/slim-bridge": "3.2.0"
"php-di/php-di": "6.4.0"

I think this problem is predictable. Right now slim using 3 parameters for controllers methods:

And current invoker takes care only for first two:

$parameters = [
    'request'  => $request,
    'response' => $response,
];

Arguments are being just merged:

$parameters += $routeArguments;

So my suggesting solution will be:

$parameters += ['args' => $routeArguments];
greezlu commented 1 year ago

Created temporary patch for myself. I'm using cweagans/composer-patches for this.

"extra": {
    "patches": {
        "php-di/slim-bridge": {
            "Fix missing controller argument": "patches/php-di/slim-bridge/issue-81.patch"
        }
    }
}

issue-81.patch

mnapoli commented 1 year ago

This isn't how this bridge is designed to work, check out this doc: https://github.com/PHP-DI/Slim-Bridge#controller-parameters

greezlu commented 1 year ago

@mnapoli Yep, that's why I've opened this issue.

It just bother me. If I'm using slim official documentation with this bridge installed and I'm getting slim and not bridge error. It's nice feature and all but it should not break original method signature in my opinion.

I can see this more like an additional functionality rather than rule. For example: It's not hard to bind arguments to $args parameter and make them available by the name at the same time. It will not break original signature but allow to use this feature "safely". Also it should not be very memory consuming since usually there's a few arguments really.

Anyway, I want to see the resolution.

UPD Second version of patch to proof my point by keeping both functionalities. issue-81.patch

NicoP-S commented 1 year ago

i stumbled across the same error... Would be nice to allow $args too like @greezlu said

greezlu commented 1 year ago

@mnapoli Hello. Any news?

mnapoli commented 1 year ago

Closing per https://github.com/PHP-DI/Slim-Bridge/issues/81#issuecomment-1382951760

greezlu commented 1 year ago

@mnapoli Why do you want to leave a bug, created by bridge, if it can be fixed with single line? What is your problem? Did you even read this issue?

Also, you forgot to close PR as well, asshole.