Conversation
added 3 commits
February 8, 2013 00:22
In other words, instances of classes that implement the __invoke() method. To accept class names instead of only instances we need to change the validation of callable objects in Routine\AbstractRoutine, something that would be nice to have. :) Also created a *src* directory inside tests to put classes related to tests only (stubs). Let me know if this bothers you a lot, I still think that this is better than declaring multiple namespaces on files.
- Creates an execute() method in AbstractSyncedRoutine;
- Creates test for Respect\Rest\Routines\AbstractRoutine:
- Add provider for valid constructor arguments
- Add assert for getCallback() method on AbstractRoutine.
Member
|
This is awesome definitely a useful addition and arguably incomplete without it. |
Member
|
Some other peculiarities with Reflection on callbacks php > $func = function () { return "I'm funky!"; }
php > is_callable($func)
true
php > $func()
"I'm funky!"
php > return var_export($func);
Closure::__set_state(array(
))
php > class INVOK { public function __invoke() { return "Invoke me bebe!"; }}
php > $invok = new INVOK;
php > is_callable($invok)
true
php > $invok()
"Invoke me bebe!"
php > var_export($invok)
INVOK::__set_state(array(
))
php > method_exists($func, '__invoke')
true
php > $rmeth = new ReflectionMethod($func, '__invoke');
php > $rmeth->invoke($func);
"I'm funky!"
php > $rmeth->invoke($func);
null
php > $rmeth->invoke($func);
null
php > $rmeth = new ReflectionMethod(new INVOK, '__invoke');
php > $rmeth->invoke(new INVOK);
"Invoke me bebe!"
php > $rmeth->invoke(new INVOK);
"Invoke me bebe!"
php > $rmeth->invoke(new INVOK);
"Invoke me bebe!"
php > $rfunc = new ReflectionFunction($func);
php > $func->invoke($func);
"I'm funky!"
php > $rfunc->invoke($func);
"I'm funky!"
php > $rfunc->invoke($func);
"I'm funky!"
php > $rfunc = new ReflectionFunction(new INVOK);
php > $rfunc->invoke(new INVOK);
PHP Fatal error: ReflectionFunction::invoke(): Internal error:
Failed to retrieve the reflection object in ...
null
php > $rfunc = new ReflectionFunction($invok);
Error Type: E_WARNING
Message: ReflectionFunction::__construct() expects parameter 1 to be string, object given
ReflectionFunction
php > $rfunc->invoke($invok);
PHP Fatal error: ReflectionFunction::invoke():
Internal error: Failed to retrieve the reflection object in ...
null
php > new Closure
Error Type: E_RECOVERABLE_ERROR
Message: Instantiation of 'Closure' is not allowed
null
php > $rfunc = new ReflectionFunction(new Closure);
Error Type: E_RECOVERABLE_ERROR
Message: Instantiation of 'Closure' is not allowed
null
php > $rfunc = new ReflectionFunction(Closure);
Error Type: E_NOTICE
Message: Use of undefined constant Closure - assumed 'Closure'
null
php > $rfunc = new ReflectionFunction('Closure');
Uncaught exception: Type: ReflectionException
Message: Function Closure() does not exist
null
php > $rmeth = new ReflectionMethod(new Closure, '__invoke');
Error Type: E_RECOVERABLE_ERROR
Message: Instantiation of 'Closure' is not allowed
ReflectionMethod
php > $rmeth->invoke($func);
"I'm funky!" |
Member
Author
|
I will make the changes to make it simpler. I went from many iterations and just want to make availiable so the guy with problems could test it. |
Member
|
Overall lots of good work, well done! =) 🐼 |
Member
|
@augustohp need a hand with this? Or has it already been committed elsewhere? |
alganet
added a commit
that referenced
this pull request
Jun 9, 2013
Make routines accept instances that are callable
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As noted on issue #85 I added the possibility of passing callable instances to routines. Let me hear what you people think, please.