deliciousbrains / wp-queue

Job queues for WordPress
MIT License
164 stars 39 forks source link

Imposter plugin doesn't change namespaces correctly #15

Open dingo-d opened 3 years ago

dingo-d commented 3 years ago

In my project, I'm using the imposter plugin to avoid any conflicts in my project in case I have a plugin that is using different versions of some packages that my project is using.

But for some reason, it only covers these packages and files

Generating optimized autoload files

Running Imposter...
======================
Loading package information from /Users/denis.zoljom/Sites/infinum/myproject/wp-content/themes/myproject/composer.json
 - 1/16: Transforming /Users/denis.zoljom/Sites/infinum/myproject/wp-content/themes/myproject/vendor/a5hleyrich/wp-queue/src/functions.php
 - 2/16: Transforming /Users/denis.zoljom/Sites/infinum/myproject/wp-content/themes/myproject/vendor/nesbot/carbon/src/
 - 3/16: Transforming /Users/denis.zoljom/Sites/infinum/myproject/wp-content/themes/myproject/vendor/kylekatarnls/update-helper/src/
 - 4/16: Transforming /Users/denis.zoljom/Sites/infinum/myproject/wp-content/themes/myproject/vendor/symfony/translation/
 - 5/16: Transforming /Users/denis.zoljom/Sites/infinum/myproject/wp-content/themes/myproject/vendor/symfony/polyfill-mbstring/
 - 6/16: Transforming /Users/denis.zoljom/Sites/infinum/myproject/wp-content/themes/myproject/vendor/symfony/polyfill-mbstring/bootstrap.php
 - 7/16: Transforming /Users/denis.zoljom/Sites/infinum/myproject/wp-content/themes/myproject/vendor/symfony/translation-contracts/

It picks up the dependencies correctly, but from the wp-queue, only the functions.php namespace gets changed. In other classes it remains the same, so now the functions.php file looks like


<?php

use MyProjectVendor\WP_Queue\Queue;
use MyProjectVendor\WP_Queue\QueueManager;

if ( ! function_exists( 'wp_queue' ) ) {

And I get the errors because the Queue.php still has the namespace namespace WP_Queue; and not MyProjectVendor\WP_Queue\Queue.

Any ideas why? It should pick up the namespaces from the autoload directive in the composer.json 🤷🏼‍♂️

Love the library btw! Works like a charm locally, can't wait to test it out on our staging site 🙂

szepeviktor commented 3 years ago

PHP-Scoper may be a superior namespace changer. https://github.com/humbug/php-scoper/issues/303

dingo-d commented 3 years ago

For scoper I think I'd need to use https://github.com/bamarni/composer-bin-plugin plugin, plus they say that:

Keep in mind however that this library is not designed to be extended.

Which is a bit worrying :S

szepeviktor commented 3 years ago

bin-plugin is really called PHIVE.

phive update humbug/php-scoper --force-accept-unsigned

There is a GitHub Action for PHIVE.

tangrufus commented 3 years ago

PHP-Scoper may be a superior namespace changer.

Agree.