Jump to content

Classdoc inaccurate or incomplete?


websavers

Recommended Posts

Am I just using the classdoc wrong, or is it inadequate for most use cases? Classdoc being here: https://classdocs.whmcs.com/8.13/

Normally I'd use $_SESSSION['uid'] to access a user session, but then I randomly see this here in the community: 

use WHMCS\Session;
Session::get('uid')

This feels like the 'right' way to be doing things, but then I go to look it up in the classdoc linked above, and the Session class is nowhere to be found.

Then I see Authentication\CurrentUser in the ClassDoc, which allows me to get the current user as an object like this:

$user = CurrentUser::user();

But then the classdoc provides no indication as to how to obtain that User ID. You'd think it would be something like one of these:

$user->id;
$user->getId();

But there's nothing under WHMCS\User and WHMCS\User\Client shows neither an ID property nor a getId() method. 

Are we not really meant to utilize the classdoc because nobody at WHMCS maintains it?  Or am I missing ways of finding this data?

 

Link to comment
Share on other sites

Take a look at your /vendor/whmcs/whmcs-foundation/lib/ folder. Every single one of those files contains a class built for WHMCS.
Only a fraction of those classes have made it into the classdocs.

In your case, Session::get('uid') and $_SESSION['uid'] basically does the same. 
When you call Session::get, it just returns $_SESSION[$key] - and returns false if it doesn't exist. It's just a small helper function.

There's a lot of useful classes in WHMCS that isn't documented.
You can do something like this to get a list of all methods provided by a given class, along with the parameters needed:

<?php

include __DIR__.'/init.php';

$reflectionClass = new ReflectionClass('WHMCS\Session');
$methods = $reflectionClass->getMethods();
foreach ($methods as $method) {
    echo "Method: " . $method->getName() . "\n";
    echo "Parameters:\n";
    foreach ($method->getParameters() as $param) {
        echo "- " . $param->getName();
        if ($param->isOptional()) {
            echo " (Optional)";
        }
        echo "\n";
    }
    echo "\n";
}

 

Link to comment
Share on other sites

  • WHMCS Support Manager

Hi there,

The classdocs are automatically generated when a new release is published, so they are always up-to-date.

All classes intended for public use are documented at https://classdocs.whmcs.com

Not all classes are documented, this is intentional. For example a class may not be documented if the functionality is not intended to be extended, a work in progress, or potentially subject to breaking changes in future.

Link to comment
Share on other sites

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