PHP-Scoper is a tool for adding a prefix to all PHP namespaces in a given file or directory.
PHP-Scoper's goal is to make sure that all code in a directory lies in a distinct PHP namespace. This is necessary when building PHARs that
- Bundle their own vendor dependencies
- Load code of arbitrary PHP projects
These PHARs run the risk of raising conflicts between their bundled vendors and the vendors of the loaded project, if the vendors are required in incompatible versions.
You can install PHP-Scoper with Composer:
composer global require humbug/php-scoper:dev-master
If you cannot install it because of a dependency conflict or you prefer to install it for your project, we recommend you to take a look at bamarni/composer-bin-plugin. Example:
composer require --dev bamarni/composer-bin-plugin
composer bin php-scoper require --dev humbug/php-scoper:dev-master
A PHAR should be availaible soon as well.
php-scoper add-prefix
This will prefix all the files found in the current working directory.
The prefixed files will be accessible in a build
folder. You can
then use the prefixed code to build your PHAR.
Warning: After prefexing the files, if you are relying on Composer for the autoloading, dumping the autoloader again is required.
For a more concrete example, you can take a look at PHP-Scoper's build step in Makefile.
Project originally created by: Bernhard Schussek (@webmozart) which has then been moved under the Humbug umbrella.