Detailed description
I'm maintining a wide variaty of WHMCS modules. Recently WHMCS seems to started using Composer in their own, closed source, software - which conflicts with my modules. Since them I'm looking for such a plugin as Imposter to fix my dependency issues.
Most things seems to work just fine, expect with Guzzle and loading PSR-4 classes.
For example a trace I gathered. Here the core WHMCS software requests Guzzle, and the autoloader seems to respond with my transformed Guzzle instance:
1 Composer\Autoload\includeFile(/var/www/*/app/modules/addons/mollierecurring/vendor/composer/../guzzlehttp/guzzle/src/ClientInterface.php) called at [/var/www/*/app/vendor/composer/ClassLoader.php:322]
--
| #2 Composer\Autoload\ClassLoader->loadClass(DevApp\WHMCS\MollieRecurring\Vendor\GuzzleHttp\ClientInterface)
| #3 spl_autoload_call(DevApp\WHMCS\MollieRecurring\Vendor\GuzzleHttp\ClientInterface) called at [/var/www/*/app/modules/addons/mollierecurring/vendor/guzzlehttp/guzzle/src/Client.php:25]
| #4 include(/var/www/*/app/modules/addons/mollierecurring/vendor/guzzlehttp/guzzle/src/Client.php) called at [/var/www/*/app/vendor/composer/ClassLoader.php:444]
| #5 Composer\Autoload\includeFile(/var/www/*/app/modules/addons/mollierecurring/vendor/composer/../guzzlehttp/guzzle/src/Client.php) called at [/var/www/*/app/vendor/composer/ClassLoader.php:322]
| #6 Composer\Autoload\ClassLoader->loadClass(GuzzleHttp\Client)
| #7 spl_autoload_call(GuzzleHttp\Client) called at [/var/www/*/app/vendor/whmcs/whmcs-foundation/lib/Admin/Setup/General/UriManagement/ConfigurationController.php:0]
| #8 WHMCS\Admin\Setup\General\UriManagement\ConfigurationController->queryEnvironmentMode() called at [/var/www/*/app/vendor/whmcs/whmcs-foundation/lib/Admin/Setup/General/UriManagement/ConfigurationController.php:0]
| #9 WHMCS\Admin\Setup\General\UriManagement\ConfigurationController->remoteDetectEnvironmentMode(WHMCS\Http\Message\ServerRequest Object ([*queryBag] => Symfony\Component\HttpFoundation\ParameterBag Object ([*parameters] => Array ()),[*requestBag] => Symfony\Component\HttpFoundation\ParameterBag Object ([*parameters] => Array ()),[*attributesBag] => Symfony\Component\HttpFoundation\ParameterBag Object ([*parameters] => Array ()),[Zend\Diactoros\ServerRequestattributes] => Array (),[Zend\Diactoros\ServerRequestcookieParams] => Array (),[Zend\Diactoros\ServerRequestparsedBody] => ,[Zend\Diactoros\ServerRequestqueryParams] => Array (),[Zend\Diactoros\ServerRequestserverParams] => Array (),[Zend\Diactoros\ServerRequestuploadedFiles] => Array (),[*headers] => Array (),[*headerNames] => Array (),[Zend\Diactoros\ServerRequestprotocol] => 1.1,[Zend\Diactoros\ServerRequeststream] => Zend\Diactoros\PhpInputStream Object ([Zend\Diactoros\PhpInputStreamcache] => ,[Zend\Diactoros\PhpInputStreamreachedEof] => ,[*resource] => Resource id #361,[*stream] => php://input),[Zend\Diactoros\ServerRequestmethod] => ,[Zend\Diactoros\ServerRequestrequestTarget] => ,[Zend\Diactoros\ServerRequesturi] => Zend\Diactoros\Uri Object ([*allowedSchemes] => Array ([http] => 80,[https] => 443),[Zend\Diactoros\Urischeme] => ,[Zend\Diactoros\UriuserInfo] => ,[Zend\Diactoros\Urihost] => ,[Zend\Diactoros\Uriport] => ,[Zend\Diactoros\Uripath] => ,[Zend\Diactoros\Uriquery] => ,[Zend\Diactoros\Urifragment] => ,[Zend\Diactoros\UriuriString] => ))) called at [/var/www/*/app/vendor/whmcs/whmcs-foundation/lib/Admin/Setup/General/UriManagement/View/Helper/SimpleSetting.php:0]
| #10 WHMCS\Admin\Setup\General\UriManagement\View\Helper\SimpleSetting->getSimpleSettingHtmlPartial() called at [/var/www/*/app/admin/configgeneral.php:0]
This results in either incompatbility or Cannot declare class DevApp\WHMCS\MollieRecurring\Vendor\GuzzleHttp\Client, because the name is already in use in /var/www/*/app/modules/addons/mollierecurring/vendor/guzzlehttp/guzzle/src/Client.php on line 25
-errors.
Also - the autoloading files for Guzzle does not work. This because Guzzle includes this file, which checks if GuzzleHttp\uri_template
is loaded - but most of the time it is (because of the core software, which already has Guzzle loaded) and so my namespace's Guzzle functions won't get loaded.
WHMCS loads Composer itself and I'm not sure how their composer.json looks like. Mine is, for example:
{
"require": {
"mollie/mollie-api-php": "2.0.*",
"typisttech/imposter-plugin": "^0.3.0"
},
"config": {
"vendor-dir": "src/addons/mollierecurring/vendor"
},
"extra": {
"imposter": {
"namespace": "DevApp\\WHMCS\\MollieRecurring\\Vendor\\"
}
}
}
Context
It is important to me to keep using my current packages (I don't use guzzle directly, but most of my packages do). This could also benefit other people, as Guzzle is a widely used package to handle HTTP requests.
Possible implementation
Unsure. Maybe manually update the PSR-4 mapping?
Your environment
- PHP 7.2
- WHMCS addons
- Different Guzzle versions