Jump to content

Composer to WHMCS


jagathks

Recommended Posts

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.

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

  • WHMCS Developer

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!

Link to comment
Share on other sites

  • 3 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated