diff --git a/README.md b/README.md index b06bab2a..c49cba7b 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,6 @@ potentially very difficult to debug due to dissimilar or unsupported package ver - [Step 2: Run PHP-Scoper](#step-2-run-php-scoper) - [Recommendations](#recommendations) - [Further Reading](docs/further-reading.md#further-reading) - - [Polyfills](docs/further-reading.md#polyfills) - [How to deal with unknown third-party symbols](docs/further-reading.md#how-to-deal-with-unknown-third-party-symbols) - [Autoload aliases](docs/further-reading.md#autoload-aliases) - [Class aliases](docs/further-reading.md#class-aliases) diff --git a/docs/configuration.md b/docs/configuration.md index d8eba4fd..3e181bff 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -236,12 +236,13 @@ if (!function_exists('Prefix\trigger_deprecation')) { } ``` -Indeed the namespace _needs_ to be added in order to not break autoloading, in which +Indeed, the namespace _needs_ to be added in order to not break autoloading, in which case wrapping the function declaration into a non-namespace could work, but is tricky (so not implemented so far, PoC for supporting it are welcomed) hence was not attempted. So if left alone, this will break any piece of code that relied on `\trigger_deprecation`, which is why PHP-Scoper will still add an alias for it, as if it was an exposed function. +Another benefit of this, is that it allows to scope any polyfill without any issues. **WARNING**: This exclusion feature should be use very carefully as it can easily break the Composer auto-loading. Indeed, if you have the following package: diff --git a/docs/further-reading.md b/docs/further-reading.md index e7e90c31..33ab9a6b 100644 --- a/docs/further-reading.md +++ b/docs/further-reading.md @@ -1,69 +1,11 @@ ## Further Reading -- [Polyfills](#polyfills) - [How to deal with unknown third-party symbols](#how-to-deal-with-unknown-third-party-symbols) - [Autoload aliases](#autoload-aliases) - [Class aliases](#class-aliases) - [Function aliases](#function-aliases) -### Polyfills - -**Note: should be obsolete as of 0.18.0.** - -At the moment there is no way to automatically handles polyfills. This is mainly -due to the nature of polyfills: the code is sometimes a bit... special and there -is also not only one way on how to approach it. - -If all of what you have is Symfony polyfills however, the following should get -you covered: - -```php - $fileInfo->getPathname(), - iterator_to_array( - Finder::create() - ->files() - ->in(__DIR__ . '/vendor/symfony/polyfill-*') - ->name('bootstrap*.php'), - false, - ), -); - -$polyfillsStubs = array_map( - static fn (SplFileInfo $fileInfo) => $fileInfo->getPathname(), - iterator_to_array( - Finder::create() - ->files() - ->in(__DIR__ . '/vendor/symfony/polyfill-*/Resources/stubs') - ->name('*.php'), - false, - ), -); - -return [ - // ... - - 'exclude-namespaces' => [ - 'Symfony\Polyfill' - ], - 'exclude-constants' => [ - // Symfony global constants - '/^SYMFONY\_[\p{L}_]+$/', - ], - 'exclude-files' => [ - ...$polyfillsBootstraps, - ...$polyfillsStubs, - ], -]; - -``` - - ### How to deal with unknown third-party symbols If you consider the following code: