-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add support for functions polyfills for the requirement checker #131
Comments
@MacFJA if you have any idea of how it could be implemented, I'm all ears. Otherwise I'm for closing this as I'm not sure it's actually possible... |
I'm working on it. I should be able to have something to show soon |
Here the solution that I came up: https://github.com/MacFJA/polyfill-registry I still need to make some work (add a README, add examples, add to packagist, etc.) but it should work. To summarize, the code will be something like: $registry = new PolyfillRegistry();
// ...
$polyfilledExtensions = [];
foreach ($packages as $packageInfo) {
$polyfilledExtensions = array_merge($polyfilledExtensions, $registry->getPolyfillExtensions($packageInfo['name']));
}
$polyfilledExtensions = array_filter(array_unique($polyfilledExtensions));
$polyfilledExtensions = array_fill_keys(array_values(polyfilledExtensions), true); The huge drawback of my solution is the list of polyfill to keep up to date |
Not so much of drawback since it's the same for what is currently done in Box. Maybe a small difference is that right now Box supports some come to be polyfills since it relies on a package name pattern for the Symfony polyfills. So there's still two things I'm wondering:
In any case I think having a polyfill registry would be a good idea. I would just suggest to support some "pattern based" polyfills like for the Symfony ones to reduce the work. |
A tool like PhpCodeAnalyser can found functions/constants/classes of extensions used.
As I design the tool to work in both way (find a polyfill for an extension and find extensions of a polyfill), I need to have a relativily precise dataset. |
Sorry I may not have been clear enough for the second point. Here's the scenarios I can think of:
|
For the case of psysh we have an indirect requirement as the composer.json (and lock) have a
The |
I think relying on the suggest is harder:
So I don't think there is anything else to do here.
Sure but how can you know that the application needs to load third-party code and how it should do it? You could very well have:
So making any assumption here looks very brittle |
Bump on the issue.
I think it's actually not an issue per se since there is no way to tell Composer you have a dependency on @MacFJA unless I'm missing something, I think we can close the issue for now. I still think the idea of a polyfill registry is a good one but maybe we don't need to keep track of the functions. |
The requirement checker currently extension based polyfills. In other words, if the project or a dependency requires a certain extension, when it is declared in their
composer.json
files like so:The requirement checker will be able to pick those requirements. It also supports a range of polyfills. So with the example above, if
phpseclib/mcrypt_compat
is found in the installed dependencies (not as a dev dependency), the extensionmcrypt
will actually not be required. Likewise, ifsymfony/polyfill-mbstring
is found, it will not requireext-mbstring
.However no function support is currently provided. For example if the project requires the Intl
grapheme_*
functions, there is no way to tell the requirement checker that those functions are required and that they are not if thesymfony/polyfill-intl-grapheme
package is installedThe text was updated successfully, but these errors were encountered: