Custom Module Libs

SoftDesigns
SoftDesigns
@softdesigns
7 years ago
242 posts
GOAL : Create our own PHP libs with functions that all JR Custom modules can access
--
Question #1 : In raw PHP to get access to custom lib functions, we may use:
Include("libCore.php);
require_once("libCoreAPI.php");
This does not seem correct to use raw PHP includes inside JR custom modules:

Do you recommend we use raw PHP includes inside custom JR modules?
--
Question #2: Another method would be a custom JR Module used as a library, for example: sdLibCore
Inside sdLibCore module, for example contains "FunctionA" - like: sdLibCore.FunctionA()

In other custom JR Modules, how do we call the lib function: sdLibCore.FunctionA() ?
How to set scope for JR Module Functions, so they can be called from all other custom JR modules?
updated by @softdesigns: 07/09/17 07:13:33AM
michael
@michael
7 years ago
7,714 posts
Take a look over the codebase, you will see require_once used in a lot of places, eg:
require_once APP_DIR . "/modules/jrBackup/contrib/S3/S3.php";

The normal place to put libraries and external packages is in the /contrib/ folder of the module.

a common pattern used in multiple places is to see if the function you're after exits, if it doesn't but you expect it to be there, include the file, then recheck for the function eg:
        $func                        = "{$show_skin}_skin_init";
        if (!function_exists($func)) {
            require_once APP_DIR . "/skins/{$show_skin}/include.php";
            if (function_exists($func)) {
                $func();
            }
        }
SoftDesigns
SoftDesigns
@softdesigns
7 years ago
242 posts
Helpful pointers - will need time to study and reply...

Tags