Skip to content

Commit

Permalink
udpate doc
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Nov 1, 2023
1 parent bef1df3 commit c054e51
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 60 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
58 changes: 0 additions & 58 deletions docs/further-reading.md
Original file line number Diff line number Diff line change
@@ -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
<?php declare(strict_types=1); // scoper.inc.php

use Isolated\Symfony\Component\Finder\Finder;

$polyfillsBootstraps = array_map(
static fn (SplFileInfo $fileInfo) => $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:
Expand Down

0 comments on commit c054e51

Please sign in to comment.