Skip to content

Commit 561bcde

Browse files
authored
Fix usage of isolated Composer (#189)
1 parent b0239f0 commit 561bcde

File tree

4 files changed

+845
-32
lines changed

4 files changed

+845
-32
lines changed

Makefile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ tm: vendor/bin/phpunit
6464
$(MAKE) e2e_020
6565

6666
e2e: ## Run end-to-end tests
67-
e2e: e2e_004 e2e_005 e2e_011 e2e_013 e2e_014 e2e_015 e2e_016 e2e_017 e2e_018 e2e_019 e2e_020
67+
e2e: e2e_004 e2e_005 e2e_011 e2e_013 e2e_014 e2e_015 e2e_016 e2e_017 e2e_018 e2e_019 e2e_020 e2e_021
6868

6969
e2e_004: ## Run end-to-end tests for the fixture set 004: source code case
7070
e2e_004: bin/php-scoper.phar
@@ -161,6 +161,16 @@ e2e_020: bin/php-scoper.phar fixtures/set020-infection/vendor clover.xml
161161

162162
diff build/set020-infection/expected-output build/set020-infection/output
163163

164+
e2e_021: ## Run end-to-end tests for the fixture set 020: Composer
165+
e2e_021: bin/php-scoper.phar fixtures/set021-composer/vendor clover.xml
166+
php -d zend.enable_gc=0 $(PHPSCOPER) add-prefix --working-dir=fixtures/set021-composer --output-dir=../../build/set021-composer --force --no-interaction --stop-on-failure --no-config
167+
composer --working-dir=build/set021-composer dump-autoload
168+
169+
php fixtures/set021-composer/vendor/composer/composer/bin/composer licenses --no-plugins > build/set021-composer/expected-output
170+
php build/set021-composer/vendor/composer/composer/bin/composer licenses --no-plugins > build/set021-composer/output
171+
172+
diff build/set021-composer/expected-output build/set021-composer/output
173+
164174
tb: ## Run Blackfire profiling
165175
tb: vendor
166176
rm -rf build
@@ -217,6 +227,9 @@ fixtures/set019-symfony-console/vendor: fixtures/set019-symfony-console/composer
217227
fixtures/set020-infection/vendor: fixtures/set020-infection/composer.lock
218228
composer --working-dir=fixtures/set020-infection install
219229

230+
fixtures/set021-composer/vendor: fixtures/set021-composer/composer.lock
231+
composer --working-dir=fixtures/set021-composer install
232+
220233
composer.lock: composer.json
221234
@echo composer.lock is not up to date.
222235

@@ -247,6 +260,9 @@ fixtures/set019-symfony-console/composer.lock: fixtures/set019-symfony-console/c
247260
fixtures/set020-infection/composer.lock: fixtures/set020-infection/composer.json
248261
@echo fixtures/set020-infection/composer.lock is not up to date.
249262

263+
fixtures/set021-composer/composer.lock: fixtures/set021-composer/composer.json
264+
@echo fixtures/set021-composer/composer.lock is not up to date.
265+
250266
bin/php-scoper.phar: bin/php-scoper src vendor vendor-bin/box/vendor scoper.inc.php box.json
251267
$(MAKE) build
252268

README.md

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ potentially very difficult to debug due to dissimilar or unsupported package ver
3636
- [Configuration](#configuration)
3737
- [Finders and paths](#finders-and-paths)
3838
- [Patchers](#patchers)
39-
- [Global Namespace Whitelisting](#global-namespace-whitelisting)
40-
- [Whitelist](#whitelist)
39+
- [Whitelist][whitelist]
4140
- [Building A Scoped PHAR](#building-a-scoped-phar)
4241
- [Step 1: Configure build location and prep vendors](#step-1-configure-build-location-and-prep-vendors)
4342
- [Step 2: Run PHP-Scoper](#step-2-run-php-scoper)
@@ -46,6 +45,8 @@ potentially very difficult to debug due to dissimilar or unsupported package ver
4645
- [PSR-0 support](#psr-0-support)
4746
- [String values](#string-values)
4847
- [Native functions and constants shadowing](#native-functions-shadowing)
48+
- [Composer](#composer)
49+
- [Composer Plugins](#composer-plugins)
4950
- [Contributing](#contributing)
5051
- [Credits](#credits)
5152

@@ -244,35 +245,6 @@ return [
244245
];
245246
```
246247

247-
### Global Namespace Whitelisting
248-
249-
By default, PHP-Scoper only scopes (or prefixes) code where the namespace is
250-
non-global. In other words, non-namespaced code is not scoped. This leaves the
251-
majority of classes, functions and constants in PHP, and most extensions,
252-
untouched.
253-
254-
This is not necessarily a desirable outcome for vendor dependencies which are
255-
also not namespaced. To ensure they are isolated, you can configure PHP-Scoper to
256-
allow their prefixing from `scoper.inc.php` using basic strings or callables:
257-
258-
```php
259-
<?php declare(strict_types=1);
260-
261-
// scoper.inc.php
262-
263-
return [
264-
'global_namespace_whitelist' => [
265-
'AppKernel',
266-
function ($className) {
267-
return 'PHPUnit' === substr($className, 0, 6);
268-
},
269-
],
270-
];
271-
```
272-
273-
In this example, we're ensuring that the `AppKernal` class, and any
274-
non-namespaced PHPUnit packages are prefixed.
275-
276248

277249
### Whitelist
278250

@@ -473,6 +445,23 @@ is_array([]);
473445
The situation is exactly the same for constants.
474446

475447

448+
### Composer
449+
450+
PHP-Scoper does not support prefixing the dumped Composer autoloader and autoloading files. This is why you have to
451+
manually dump the autoloader again after prefixing an application.
452+
453+
454+
### Composer Plugins
455+
456+
Composer plugins are not supported. The issue is that for [whitelisting symbols](#whitelist) PHP-Scoper relies on the
457+
fact that you should load the `vendor/scoper-autoload.php` file instead of `vendor/autoload.php` to trigger the loading
458+
of the right classes with their class aliases. However Composer does not do that and as a result interfaces such as
459+
`Composer\Plugin\Capability\Capable` are prefixed but the alias is not registered.
460+
461+
This cannot be changed easily so for now when you are using an isolated version of Composer, you will need to use the
462+
`--no-plugins` option.
463+
464+
476465
## Contributing
477466

478467
[Contribution Guide](CONTRIBUTING.md)
@@ -493,3 +482,4 @@ now been moved under the
493482
[releases]: https://github.com/humbug/php-scoper/releases
494483
[symfony_finder]: https://symfony.com/doc/current/components/finder.html
495484
[releases]: https://github.com/humbug/php-scoper/releases
485+
[whitelist]: #whitelist
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"composer/composer": "^1.6"
4+
}
5+
}

0 commit comments

Comments
 (0)