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
4.x - Deferred callable as string without resolver #2804
Comments
I briefly looked - https://github.com/slimphp/Slim/blob/4.x/Slim/DeferredCallable.php#L40. It seems correct. Please, give a counterexample. function add($a, $b) {
return $a + $b;
}
$callable = new DeferredCallable('add');
echo $callable(10, 20) . PHP_EOL; |
For example if the callable string is in Slim notation class Calculator
{
function add($a, $b)
{
return $a + $b;
}
}
$callable = new DeferredCallable('Calculator:add', new \Slim\CallableResolver());
echo $callable(10, 20).PHP_EOL;
$callable = new DeferredCallable('Calculator:add');
try {
echo $callable(10, 20).PHP_EOL;
} catch (Error $e) {
echo $e->getMessage().PHP_EOL;
} This would output
The first one is working as it has a callable resolver. Although. I am not sure if this would ever happen. |
@adriansuter yes, let's throw a |
@l0gicgate Sure. Is this class actually used somewhere? I haven't found any references. |
@adriansuter it is not anymore. I think we can remove it altogether. It was an oversight when we merged the PSR-15 PR I believe. |
If we remove that, could that bug someone - for example someone who used it already somewhere? Chances are small, but still. |
Actually it is used: Slim/tests/Routing/RouteTest.php Lines 388 to 403 in 335b5fd
Slim/tests/Routing/RouteTest.php Lines 405 to 452 in 335b5fd
|
@adriansuter we should either move it into the test mocks, or delete it an not use it at all. It shouldn't be in there and for people using it, why? you can already defer any route/middleware callable. |
@adriansuter and @l0gicgate I created a draft PR. It shows how the |
Seems to be a nice idea. What do you think @l0gicgate? |
If we use I don't think we need it anymore. Change my mind 😂 |
Right. So I will close #2807, as soon as I can as it is not needed anymore. |
@l0gicgate Agh, this is what I get for being on effectively Almost certainly this is a case of XKCD 1172, and I don't blame you guys for getting rid of it for Slim itself, but it was a nice little utility class to have to fulfill the same purpose in other places that don't take advantage of Slim's CallableResolver (in my case, Symfony's EventDispatcher). |
Sorry @SlvrEagle23, it should be fairly easy to re-implement in your code base though if you need it though. |
Dear reader
In
DeferredCallable
we can pass astring
as callable. But the callable resolver is allowed to benull
and therefore the__invoke
will fail. Shouldn't we throw aRuntimeException
if that happens? If yes, already in the constructor or later in the invocation?The text was updated successfully, but these errors were encountered: