jagathks Posted August 1, 2017 Share Posted August 1, 2017 Hi, Can some one tell me how to deploy module developed in Composer to the WHMCS development. Recently we started doing some module development, but we have a question about how to actually deploy the module into production. For example the code we developed is using Composer PHP, As you can see, it's a composer package but we're not sure exactly how to deploy the code to WHMCS. Help to impost the package to WHMCS, it really a great module to and definitely benefit many people. Thanks. 0 Quote Link to comment Share on other sites More sharing options...
AffordableDomainsCanada Posted August 1, 2017 Share Posted August 1, 2017 This may be of some assistance? https://github.com/WHMCS/sample-addon-module 0 Quote Link to comment Share on other sites More sharing options...
DigitalDaz Posted September 2, 2017 Share Posted September 2, 2017 I'm surprised you got no answers here from WHMCS supports staff, I'm not really a programmer but it seems they are using composer themselves already, certainly there is plenty of stuff in vendor/composer. I came here searching for a more elegant way to achieve what I have done... Yesterday I installed https://github.com/view-components/grids I simply installed composer then did a composer require view-components/grids. This immediately trashed everything. I then made copies of autoload_* in the composer directory. Then I copied all the whmcs files back over my installation, I then went into the vendor/composer directory and merged all the autoload_ files by hand with the ones from after I had installed grids. Everything then sprung into life and it seems to work perfectly. I know there must be a more elegant way of doing this and would love some input from WHMCS support on this. 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Developer WHMCS Andrew Posted September 4, 2017 WHMCS Developer Share Posted September 4, 2017 Using composer within your own module directory would not be an issue - in fact we do this with the Import Assist addon. Do not attempt to add any new composer files in the WHMCS root as this will cause issues like DigitalDaz listed. Easiest thing to do is to load the auto-loader in your addon module main file, then have all the functions in another file. Example with an addon module called "sample": composer.json { "autoload": { "files": ["lib/functions.php"], "psr-4": { "Sample\\": "lib/Sample/" } } } sample.php <?php include_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'); lib/functions.php <?php if (!defined("WHMCS")) { die("This file cannot be accessed directly");} sample_config() { } sample_activate() { } //other functions required for an addon module lib/Sample/AClass.php <?php namespace Sample; class AClass { //a class here } In this way, you can use the use statements for WHMCS and your custom namespace within your addon module. use Sample\AClass; Hope this helps! 0 Quote Link to comment Share on other sites More sharing options...
DigitalDaz Posted September 6, 2017 Share Posted September 6, 2017 Thank you, this worked perfectly and has opened up a whole new world 0 Quote Link to comment Share on other sites More sharing options...
cyben76 Posted June 19, 2021 Share Posted June 19, 2021 Hi Andrew, Does this apply to the latest version of WHMCS? I'm confused as to where to place the composer.json. Could you show the file structure exampl 0 Quote Link to comment Share on other sites More sharing options...
cyben76 Posted June 23, 2021 Share Posted June 23, 2021 Ok, I understand now after looking at the Import Assist addon. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.