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

Added 'args' parameter to support route placeholders as an Array type argument in resolved controller from container #72

Closed iGroovyboy closed 3 years ago

iGroovyboy commented 3 years ago

Added 'args' parameter to support route placeholders as an Array type argument in resolved controller from container. Tests and UserController fixture updated; UserController->invite() shows basic usage where missing args caused error.

The 'native' Slim missing args argument caused following issues for the given test case fixture method arguments:

  1. Not being able to use route arguments as keys of $args Array if route was configured to use callable class name (and method name if used).
  2. Error "Unable to invoke the callable because no value was given for parameter 3 ($args)" in Invoker\Exception\NotEnoughParametersException
mnapoli commented 3 years ago

Hi, from the documentation of this package:

By default, Slim controllers have a strict signature: $request, $response, $args. The PHP-DI bridge offers a more flexible and developer friendly alternative.

This package does not support $args in parameters. That's intentional.

iGroovyboy commented 3 years ago

What's the reason behind it? This fix would let all the installations with $args to be working as they are as well as current named parameters. And using the PHP-DI makes all the uses of Slim's signature basically useless with container resolution, doesn't it?

mnapoli commented 3 years ago

Well this how it was designed initially, the reason was simply "because I liked it better that way" (without $args injection, which I found messy at the time).

I'm not 100% sure about the possible BC breaks of merging this. For example what if someone has an $args argument already?

iGroovyboy commented 3 years ago

@mnapoli yes, i see what you mean. I guess you should close this PR.