-
Notifications
You must be signed in to change notification settings - Fork 46
Flexible discovery #59
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
Conversation
a5b302c
to
96a650b
Compare
$exceptions = []; | ||
foreach (self::$strategies as $strategy) { | ||
try { | ||
$bindings = call_user_func($strategy.'::find', $type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "binding" the best name here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puli terminology
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but Im hesitant over using "binding" since this is not in the Puli scope. I'll use "binding"
Huh, nice work. Haven't reviewed yet, but definitely will. About strategies: not sure if we want discoveries to be made configurable. It's like creating a custom configuration layer which we don't want to. I think the idea in the linked ticket was to use puli if available, fallback to our known resources if they are available. If this is what strategies intend to do (with a better abstraction) then it's fine, but we should keep it minimal: not too much extension points, etc |
Thank you Mark.
Have a look at #58. It did that exactly. But it felt weird and it did not follow the Open/Close principle. But maybe you are correct, this is too many of extension points. |
Discovery is for convenience, so I would rather follow KISS. |
@@ -47,7 +47,7 @@ function it_throws_an_exception_when_binding_not_found(Discovery $discovery) | |||
{ | |||
$discovery->findBindings('InvalidBinding')->willReturn([]); | |||
|
|||
$this->shouldThrow('Http\Discovery\NotFoundException')->duringFindOneByType('InvalidBinding'); | |||
$this->shouldThrow('Http\Discovery\Exception\NotFoundException')->duringFindOneByType('InvalidBinding'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use NotFoundException::class here?
i like it. its indeed quite a thing you built here, but i think its clearly structured. i think there are too many public methods that are additional extension points we should not need. i think hard-setting the answer for a $type on the discovery itself should be all the configuration we allow. the whole discovery interface and implementations should have i also feel a bit unsure about the number of static methods. but as we don't want the discoveries to be configurable anyways, it should not matter. |
i like this! the implementation looks good to me. |
['class' => Curl::class, 'condition' => Curl::class], | ||
['class' => Socket::class, 'condition' => Socket::class], | ||
['class' => Buzz::class, 'condition' => Buzz::class], | ||
['class' => React::class, 'condition' => React::class], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this work when you have only one HttpClient and not the other since you will only have one class, the other will not be found and this will throw an autoloading exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the beauty of Foo::class, it doesn't throw an exception if the class not exists. =)
@Nyholm can you check the build failures please? |
Yes of course. I started to fix the tests this morning but did not have time to finish. |
sure, no hurry. just wanted to be sure we understand who is waiting on whom ;-) |
Yooho. Tests are passing. I added a fix for the composer/puli thing. Please feel free to make suggestions on the tests. PHPSpec is not my strongest suit. |
{ | ||
self::$classes = []; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline
Let me see if I understand well: we have x strategies which all return some resources, which we cache and then use this cache to find the actual resource? |
Thank you for your review. We work with a strategy at the time, if a strategy return a "candidate" were its dependencies are met we have found a class and we will return without investigating further strategies. This candidate is saved to the cache. The cache is only read from the second time we ask for the same resource. The great thing about the strategies is that we can easily support Puli2 or WhatveverDiscovery without editing any existing class. |
*/ | ||
private static $puliFactory; | ||
public static $strategies = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to configure the strategies in the abstract class? Can't we do it on a per discovery basis?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we are using strategies that we know would fail. Example; the HttpClients strategy will always fail for the FactoryDiscovery. I'll fix this by merging the strategies suggested bellow.
This is cool, I like it, great job @Nyholm. I've added a few more comments besides the CS ones from earlier. Can you please take a look at them and at least answer them? If you have no time, I can do the improvements I suggested, but I need your comment to make sure I understood everything right. Thank you! |
Thank you. I've address all your comments, either with a reply or a code change (or both). |
This is still an open question from my POV: #59 (comment) |
Great, I am happy with the current state. Can you please add some change log and squash? |
7ca6695
to
1c37482
Compare
Awesome. I'll must go afk now. Please feel free to make some changes or merge this when the tests passes. Thank you for the reviews! |
I was not too happy about #58. We treat Puli in a special manner which feels weird. Also, I was not too happy about the logic in the fallback strategies.
This PR continues the work and replaces #58. The user has now the possibility to select what strategies to use and also add some more custom if there is a need for it.
Changes
Stratiegies
that do the discovery. We try the strategies one by one until we find what we're looking forClassDiscovery
toStrategy\Puli
.TODO
This is just a proof of concept. Do we like to go this way?