Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
titleTorneLIB Example
collapsetrue
$LibDir = "/usr/local/TorneLIB/";
if (!file_exists($LibDir . "autoload.php")) { die("TorneLIB missing."); }
require_once($LibDir . "/autoload.php");
/** @var $Tornevall Initialize TorneLIB */
$Tornevall = new \TorneLIB\TorneLIB();


/**
 * API Communication
 * 
 * @param string $method
 * @param array $PostData
 */
function API($method = "", $PostData = array())
{
    // Setting a global here, since TorneLIB are used elsewhere too
    global $Tornevall;
    $API = $Tornevall->API->Intialize("Tornevall");
    // Build a standard output array, as this is implemented as a gateway on the server, that responds with JSON via Ajax calls
    $getApi = array(
        'success' => false,
        'faultstring' => null
    );
    try {
        // Using Post only.
        $getApi['response'] = $API->Post($method, $PostData);
        $getApi['success'] = true;
    } catch (Exception $e) {
        // The API throws exceptions so we can catch any occured errors here
        $getApi['faultstring'] = $e->getMessage();
    }
    $APIResponse = array(
        'api' => $getApi
    );
    header("Content-Type: application/json");
    die(json_encode($APIResponse));
}


var_dump(API("test"));