phar-install icon indicating copy to clipboard operation
phar-install copied to clipboard

Feature/avoid hard coding developer paths

Open snim2 opened this issue 7 months ago • 0 comments

By default, Composer creates a classmap of PHP classes to source files. Where those source files are written into the application or repository, the Composer classmap will hard code absolute paths to those files within the classmap.

In situations where a phar file is created on a development machine and then deployed to a live environment this is unhelpful because the absolute paths will not exist where the vendor.phar is loaded.

This commit re-writes the autoload files generated by Composer to replace the absolute paths with a common path to wp-content which is used in many hosting environments:

/var/www/html

For users who prefer not to have this, the PHAR_INSTALL_PATH_TO_WP_CONTENT environment variable can be used to change the path.

See: https://getcomposer.org/doc/articles/autoloader-optimization.md

Testing

It's probably easiest not to test here, but to copy the phar-install file into a binary that you already have in a site repo theme. Run ./vendor/bin/phar-install with the new code and check that the site theme still loads.

You can also check for hard-coded paths in the vendor.phar file by running strings vendor.phar | grep Users.

I'm not sure whether we want to go much further with testing on Linux, but sed is annoyingly not very portable between GNU and BSD versions.

snim2 avatar Jun 09 '25 11:06 snim2