Last active
August 29, 2015 14:13
-
-
Save hannesvdvreken/328d3e85cc920a3d3759 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set_exception_handler($app->wrap(function (\Exception $exception, \Whoops\Run $run) { | |
$run->handleException($exception); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was using the Illuminate Container in a non-laravel project and figured it would be useful to wrap callables like this.
Right now the anonymous function returned by
App::wrap
doesn't accept arguments and when it is called it calls the original function and returns the result.What I'm trying to archieve here is quite hard to solve because of several reasons:
Will correctly inject argument 1 and 2 from the given array.
It would also be possible to intelligently figure out what to do with this:
But this is a more challenging situation.
What will be the value of
$arg1
and what will be the value of$arg2
?Also it would require people NOT to type hint arguments, because otherwise the
$app->call
method will try to resolve it from the container.Or the given arguments (
func_get_args
) must be matched with the type hinted arguments of the wrapped anonymous function first before resolving the rest...Here's a proposed solution:
This would give priority to the parameters passed to the new anonymous function returned by the
wrap
method.Another solution (with respect to type hints):
Maybe enforce a specific order:
func_get_args
arguments first, then arguments resolvable from the container, then the $parameters array arguments.