@@ -38,9 +38,10 @@ potentially very difficult to debug due to dissimilar or unsupported package ver
3838 - [ Finders and paths] ( #finders-and-paths )
3939 - [ Patchers] ( #patchers )
4040 - [ Whitelist] [ whitelist ]
41- - [ Class & Constant Whitelisting] ( #class-constant-whitelisting )
42- - [ Namespace Whitelisting] ( #namespace-whitelisting )
43- - [ Building A Scoped PHAR] ( #building-a-scoped-phar )
41+ - [ Constants from the global namespace whitelisting] ( #constants-from-the-global-namespace-whitelisting )
42+ - [ Classes & Constants whitelisting] ( #classes-constants-whitelisting )
43+ - [ Namespaces whitelisting] ( #namespaces-whitelisting )
44+ - [ Building a scoped PHAR] ( #building-a-scoped-phar )
4445 - [ With Box] ( #with-box )
4546 - [ Step 1: Configure build location and prep vendors] ( #step-1-configure-build-location-and-prep-vendors )
4647 - [ Step 2: Run PHP-Scoper] ( #step-2-run-php-scoper )
@@ -125,10 +126,11 @@ with a `--config` option.
125126use Isolated\Symfony\Component\Finder\Finder;
126127
127128return [
128- 'prefix' => null,
129- 'finders' => [],
130- 'patchers' => [],
131- 'whitelist' => [],
129+ 'prefix' => null, // string|null
130+ 'finders' => [], // Finder[]
131+ 'patchers' => [], // callable[]
132+ 'whitelist' => [], // string[]
133+ 'whitelist-global-constants' => true, // bool
132134];
133135```
134136
@@ -261,7 +263,24 @@ a PHPUnit PHAR with isolated code, you still want the PHAR to be able to
261263understand the ` PHPUnit\Framework\TestCase ` class.
262264
263265
264- ### Class & Constant whitelisting
266+ ### Constants from the global namespace whitelisting
267+
268+ By default, PHP-Scoper will not prefix the user defined constants belonging to
269+ the global namespace. You can however change that setting for them to be
270+ prefixed as usual unless explicitely whitelisted:
271+
272+ ``` php
273+ <?php declare(strict_types=1);
274+
275+ // scoper.inc.php
276+
277+ return [
278+ 'whitelist-global-constants' => false,
279+ ];
280+ ```
281+
282+
283+ ### Classes & Constants whitelisting
265284
266285You can whitelist classes, interfaces and constants like so like so:
267286
@@ -282,23 +301,27 @@ This will _not_ work on traits or functions.
282301
283302The class aliasing mechanism is done like follows:
284303- Prefix the class or interface as usual
285- - Append a ` class_alias() ` statement at the end of the class/interface declaration to link the prefixed symbol to the
286- non prefixed one
287- - Append a ` class_exists() ` statement right after the autoloader is registered to trigger the loading of the method
288- which will ensure the ` class_alias() ` statement is executed
289-
290- It is done this way to ensure prefixed and whitelisted classes can co-exist together without breaking the autoloading.
291- The ` class_exists() ` statements are dumped in ` vendor/scoper-autoload.php ` , do not forget to include this file in favour
292- of ` vendor/autoload.php ` . This part is however sorted out by [ Box] [ box ] if you are using it with the
293- [ ` PhpScoper ` compactor] [ php-scoper-integration ] .
294-
295- The constant aliasing mechanism is done by transforming the constant declaration into a ` define() ` statement when this
296- is not already the case. Note that there is a difference here since ` define() ` defines a constant at runtime whereas
297- ` const ` defines it at compile time. You have a more details post regarding the differences
304+ - Append a ` class_alias() ` statement at the end of the class/interface
305+ declaration to link the prefixed symbol to the non prefixed one
306+ - Append a ` class_exists() ` statement right after the autoloader is
307+ registered to trigger the loading of the method which will ensure the
308+ ` class_alias() ` statement is executed
309+
310+ It is done this way to ensure prefixed and whitelisted classes can co-exist
311+ together without breaking the autoloading. The ` class_exists() ` statements are
312+ dumped in ` vendor/scoper-autoload.php ` , do not forget to include this file in
313+ favour of ` vendor/autoload.php ` . This part is however sorted out by [ Box] [ box ]
314+ if you are using it with the [ ` PhpScoper ` compactor] [ php-scoper-integration ] .
315+
316+ The constant aliasing mechanism is done by transforming the constant
317+ declaration into a ` define() ` statement when this is not already the case.
318+ Note that there is a difference here since ` define() ` defines a constant at
319+ runtime whereas ` const ` defines it at compile time. You have a more details
320+ post regarding the differences
298321[ here] ( https://stackoverflow.com/a/3193704/3902761 )
299322
300323
301- ### Namespace whitelisting
324+ ### Namespaces whitelisting
302325
303326If you want to be more generic and whitelist a whole namespace, you can
304327do it so like this:
@@ -331,7 +354,7 @@ return [
331354```
332355
333356
334- ## Building A Scoped PHAR
357+ ## Building a Scoped PHAR
335358
336359### With Box
337360
0 commit comments