Jaxl 2.0 Core classes, available methods and directory structure

In this blog post we will dig deep into the core of Jaxl 2.0 – An XMPP framework written in PHP. Specifically, we will go through Jaxl core directory structure. Towards the end we will get familiar with various core classes and their available methods (e.g. $jaxl->sendMessage()), that developers can use in their XMPP applications.

Core Directory Structure
Now that you have the source code, lets get familiar with the Jaxl directory structure. Downloaded source code consists of following 5 directories:

  • xmpp: Contain core stack which implements XMPP rfc’s. All files follow naming convention like xmpp.*.php
  • core: Contains core stack which manages the library workflow. Also provides an xpath based XML parser, an event mechanism and various other utilities to the framework. All files follow naming convention like jaxl.*.php
  • xep: Contains implemented XMPP extensions (XEP’s). All files follow naming convention like jaxl.XEP-NUMBER.php
  • env: Contains Jaxl main() file jaxl.php, Jaxl core configuration file jaxl.conf and application environment setup file jaxl.ini. For bosh application developers jaxl.js is a must include from this directory.
  • app: Contains example applications which comes packed with Jaxl library

Core Classes and Available Methods
Below is a detailed list of all the core classes and available methods in developer land space:

This class is located inside core/jaxl.class.php and extends base XMPP class. Following is a list of methods available:

  • __construct($config=array()) : Constructor accepts following configuration parameters. Passed parameters will overwrite corresponding jaxl.ini values:
    $config = array(
        'user'=>'', // JAXL_USER_NAME
        'pass'=>'', // JAXL_USER_PASS
        'host'=>'', // JAXL_HOST_NAME
        'port'=>'', // JAXL_HOST_PORT
        'domain'=>'', // JAXL_HOST_DOMAIN
        'component'=>'', // JAXL_COMPONENT_HOST
        'logPath'=>'', // JAXL_LOG_PATH
        'logRotate'=>'', // false or second in which to rotate log
        'logLevel'=>'', // JAXL_LOG_LEVEL
        'pidPath'=>'', // JAXL_PID_PATH
        'boshHost'=>'', // JAXL_BOSH_HOST
        'boshPort'=>'', // JAXL_BOSH_PORT
        'boshSuffix'=>'', // JAXL_BOSH_SUFFIX
        'resource'=>'', // connecting user resource identifier
        'streamTimeout'=>'', // connecting stream timeout
        'sigh'=>'', // boolean to forcible enable/disable sigh term
        'dumpStat'=>'', // false or numeric specifying second after which to dump stat
  • auth($type) : Performs authentication with the jabber server. DIGEST-MD5, PLAIN, X-FACEBOOK-PLATFORM and ANONYMOUS are the supported auth $type
  • setStatus($status=FALSE, $show=FALSE, $priority=FALSE, $caps=FALSE) : Update the status of connected jabber user. Pass $caps=TRUE for sending entity capability information while setting connected user status.
  • subscribe($toJid)
  • subscribed($toJid)
  • unsubscribe($toJid)
  • unsubscribed($toJid)
  • getRosterList($callback=FALSE) : Fetch roster list for the connected user. See example usage inside echobot application.
  • addRoster($jid, $group, $name=FALSE)
  • updateRoster($jid, $group, $name=FALSE, $subscription=FALSE)
  • deleteRoster($jid)
  • sendMessage($to, $message, $from=FALSE, $type=’chat’)
  • sendMessages($to, $from, $child, $type)
  • sendPresence($to, $from, $child, $type)
  • $jaxl->requires($class) : It is an alternative for jaxl_require($class, $jaxl).
  • $jaxl->xml->xmlize($xml) : Use this method to convert raw XML string into an array.
  • $jaxl->log($log, $level) : Use this method for logging purposes

This class is located inside core/jaxl.plugin.php. Following is a list of methods available:

  • add($hook, $callback, $priority=10) : Register callback on available hooks
  • remove($hook, $callback) : Un-register callback on a previously registered hooks using add method

This class is located inside core/jaxl.cron.php. Use this call methods to run periodic background jobs. Following is a list of methods available:

  • add($callback, $interval) : $callback methods is called every $interval second
  • delete($callback, $interval) : Removes a previously registered cron job

This class is located inside core/jaxl.util.php. Following is a list of methods available:

  • isWin() : Window OS detection, return bool
  • getTime()
  • getBareJid($jid)
  • splitJid($jid)
  • curl($url, $type=’GET’, $headers=FALSE, $data=FALSE, $user=FALSE, $pass=FALSE)

More methods might get added in future and will be updated here.

Using available XEP methods
Once have included required XEP class inside your application code, either by using jaxl_require('JAXLxxxx', $jaxl) or by calling $jaxl->requires('JAXLxxxx'), you can start using the available methods inside included XEP class as follows:

$jaxl->JAXLxxxx('methodName', $param1, $param2, ....);

e.g. If you want to call joinRoom methods of Multi-User Chat XEP-0045, you can do so by calling

$jaxl->JAXL0045('joinRoom', $jid, $roomJid.'/'.$nick, $history, $seconds)

. DO-NOT call the method like JAXL0045::joinRoom(…)