-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Skip AbstractProvider when generating provider list #107
Skip AbstractProvider when generating provider list #107
Conversation
Thank you for your PR. Can you maybe share your code or an example where this issue appears? I tried to replicate it myself with the following simple script, but couldn't see any issue:
Output:
|
I was thinking about making a dedicated test for it, but it'd require quite a lot of refactoring. To replicate this bug, you'd have to replace filesystem iterators with a method call, and inject some mock here, that would return predefined file list. But for the sake of example, I'd hardcode it into Yasumi. Let's hardcode normal file order into
Now let's see what's inside the array that was returned:
Everything seems fine. But now let's change the order in which filesystem returned file list:
And now the output is:
Why? Because the pair We could fix this issue in many different ways. One of them is to sort the input iterator by filename, but that's kind of a naive approach that relies on believing that we get the input in a specific order. My idea was to make sure that we load only actual providers basing on one thing we know: it has to extend |
Thanks for the example! Totally understand the issue now. So it looks like the FilesystemIterator may return an array of the files in an order that is not always guaranteed to be the same. The ID constant acts merely as an identifier for the provider. I believe I used 'US' as a default for no particular reason :) Let me have a look in a bit more detail tomorrow; however your PR looks like a good solution. |
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.
I've checked this and looks to address the issue. Would you mind adding an entry to the CHANGELOG.md file as part of this PR?
Once added, I will merge it.
Added the changelog entry. |
Why 2.0.0? It looks like something that should be fixed in earliest possible version. It does not break anything, I dont think anybody was relying on random behavior. |
@norzechowicz v2.0.0 will be the next official release. This PR will be merged in the development branch, so anyone can use that branch if they like :) |
merge into develop does not sounds like a solution, my project relies on that library (and probably many others as well), it's also having composer.json in pretty good shape (meaning we can update dependencies without risk of breaking things), using not stable branches is against our dependencies policy. I would really appreciate if you could at least release 1.8.1 with this fix. |
Sure, understand your concern. Let me see if I can create a 1.8 patched version. :) Just FYI: v2.0.0 will be a new branch supporting PHP 7 only going forward. v1.8 will be the last version based on PHP 5 and will not include any new features. Not sure yet when I'm going to release v2.0.0 yet (kind of occupied with other projects). |
hey @stelgenhof any chance to release 1.8.1 anytime soon? |
@norzechowicz No. Do you experience any critical issues with the current release? |
Yes, random behavior that can't be predicted fixed by this particular PR |
@norzechowicz Perhaps I am not seeing the entire picture here, but could you describe your situation in more detail? That may give me more context. Are there also other unpredictable results besides the one described in this PR (USA example)? Thanks! |
In some cases, when filesystem iterator returned
AbstractProvider.php
afterUSA.php
, provider list generator returnedAbstractProvider
as the provider for USA, as abstract provider has theID
constant set toUS
(I'm unsure why it has this constant at all). The mechanism is simple: loop checksUSA.php
, adds'US' => 'USA'
to the array, then checks AbstractProvider, and overwrites the USA provider by adding'US' => 'AbstractProvider'
to the output.To overcome this issue, I've expanded the condition checking if the class is a proper provider by checking if it's a subclass of
AbstractProvider
. That's why AbstractProvider won't be taken into consideration at all.