Closed designermonkey closed 9 years ago
To get this to work, I have to manually create an instance of every callback class, which goes against the point of making this all accept string references to classes and methods.
$app->get('/', new Test);
or tell it to look for the invoke method:
$app->get('/', Test::class . ':__invoke');
All this seems a little odd. Could the CallableResolver
be updated to allow the use of invokable classes?
Pretty embarrassed here, I looked at the code in the repo here and it has been changed since my local copy. Updated and it all works fine.
Sorry chaps.
I don't technically want to reopen this, but I still don't understand how Slim verifies that a class is invokable. It seems to me to just assume it is right at the end of the if/else block in the CallableResolver?
https://github.com/slimphp/Slim/blob/3.x/Slim/CallableResolver.php#L76
Line 73 ensures that $class can be autoloaded and so line 76 instantiates it.
Line 81 checks that it is invokable.
Why am I so blind recently? Thanks.
Using the following (not pretty I know)
And after reading @silentworks article here, and with my own expectations that an invokable object should just be invoked, this is the result I get:
Sadly @silentworks this isn't right, although I agree with you it should be.