Skip to content

Instantly share code, notes, and snippets.

@jfinstrom
Last active August 2, 2021 20:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfinstrom/2910174146f974b7aad18c263ecf79cc to your computer and use it in GitHub Desktop.
Save jfinstrom/2910174146f974b7aad18c263ecf79cc to your computer and use it in GitHub Desktop.
FreePBX Functions and Methods

FreePBX Development tip.

It is almost always prefered to use internal functions and methods when interacting with FreePBX. This is made dificult when you don't know what those functions are. Reading the code can be tedious at times. Here is a flow to help you figure out internals.

Standard disclaimer and shameless plug.

This is provided as information only. This is a personal thing and is not supported by my employer. FreePBX is a trademark of Sangoma who also does not endorse or support this doc. While this is not an official project my employment does allow me to feed my family while giving back. Feel free to check out https://clearlyip.com . Buying from them feeds and shelters me and my offspring :)

Finding Methods for a module:

<?php
include '/etc/freepbx.conf';
print_r(get_class_methods(FreePBX::Core()));
...
Array
(
    [0] => __construct
    [1] => getRightNav
    [2] => getAllDrivers
    [3] => getDriver
    [4] => loadDrivers
    [5] => getAllDriversInfo
...

Getting All local Functions then filtering them.

In general there is a naming convention of module_foo for functions.

<?php
include '/etc/freepbx.conf';

$functions = get_defined_functions();
$localFunctions = $functions['user'];

print_r(array_filter($localFunctions , function($current){return strpos($current,'core_') === 0;}));

...
Array
(
    [391] => core_destination_popovers
    [392] => core_destinations
    [393] => core_getdest
    [394] => core_getdestinfo
    [395] => core_do_get_config
    [396] => core_ampusers_add
    [397] => core_ampusers_del
...

You can simply print_r($localFunctions to get everything)

Notes

In both of the above you simply replace core with the module name. This does Not give you the parameters to pass. For those you can review the code but you don't have to comb through it. You can simply go to the function by name. Methods will be in Modulename.class.php and functions will be in functions.inc.php for the most part.

You may also use grep to find the function and args by name.

# grep -r "function core_getdest(" /var/www/html/admin/modules/core/*
/var/www/html/admin/modules/core/functions.inc.php:function core_getdest($exten) {

Hopefully this helps you speed up development while using FreePBX Internals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment