Table of Contents

Services WorkXpress Project

The Services WorkXpress Project archive contains all of the files required to make API calls to a WorkXpress application using the Services WorkXpress PHP Package.

This document refers to Services WorkXpress version 1.0. Services WorkXpress requires PHP 5.2+ with the base PEAR library installed. For more information on PEAR, please visit http://pear.php.net.

Getting Started

First, lets take a look at the directory structure provided in the Services_WorkXpress_Project.tar.gz archive:

Next, we'll walk through each of the files that are not covered in the Services WorkXpress documentation and explain why they exist and what we use them for.

/scripts/test.php

<?php
 
define('BASE_PATH', dirname(dirname(__FILE__)));
include_once(BASE_PATH . '/inc/config.php');
 
echo "BASE_PATH: " . BASE_PATH . "\n";
echo "Test was successful.\n";
 
?>

Execute the /scripts/test.php file via command line using the PHP CLI library. You can do this in linux by doing the following (let's assume your project files are in /var/newproject):

> cd /var/newproject > php scripts/test.php BASE_PATH: /var/newproject Test was successful.

What this test script does is it includes the inc/config.php file, which in turn includes the Services WorkXpress libraries. If you see the line “Test was successful” at the end of the script, then you know there were no problems with includes or missing dependencies. It also shows the value for the BASE_PATH constant, which can be used in any /web or /script PHP file to mean the base of your project folder. This is extremely useful when doing includes. If you do not see the BASE_PATH, or the “Test was successful” line at the end then there was an error processing the script. Check your phpcli error log for details and resolve.

/inc/config.php

<?php
 
set_include_path('.' . PATH_SEPARATOR . BASE_PATH.'/lib/pear');
 
include_once('Services/WorkXpress.php');
 
?>

In this file you will take care of including everything you write in the /lib folder, making them available in any of your scripts. It will also contain the definition of any variables that you want to be available script by script as you go on. In it's earliest form here it only includes Services WorkXpress, but you haven't written any code yet. Here's an example of an /inc/config.php file from a complete project, with includes and configuration variables global to the application:

<?php
 
set_include_path('.' . PATH_SEPARATOR . BASE_PATH.'/lib/pear');
 
include_once('Services/WorkXpress.php');
 
//PHP INI Settings
error_reporting(E_ALL ^ E_DEPRECATED);
set_time_limit(180);
ini_set('display_errors', 'Off');
ini_set('log_errors', 'On');
 
//GLOBAL INCLUDES
require_once BASE_PATH.'/inc/constants.php';
require_once BASE_PATH.'/lib/common.php';
require_once BASE_PATH.'/lib/MaintenanceVariables.php';
require_once BASE_PATH.'/lib/OpenSSL.php';
require_once BASE_PATH.'/lib/Usage.php';
require_once BASE_PATH.'/lib/Webserver.php';
 
//CONFIG
$GLOBALS['conf']                               = array();
$GLOBALS['conf']['app_role']                   = Services_WorkXpress::APPLICATION_ROLE_PROD;
$GLOBALS['conf']['database']['name']           = 'database_name';
$GLOBALS['conf']['database']['user']           = 'database_username';
$GLOBALS['conf']['database']['pass']           = 'database_password';
$GLOBALS['conf']['version']                    = '3.0.6176';
 
//Set the Keys for accessing the application
$GLOBALS['conf']['services_workxpress_config'] = array(
	'api_version' => 1,
   Services_WorkXpress::APPLICATION_ROLE_BUILD => array(
		'auth_key'   => 'KEY REMOVED FOR DOCUMENATION',
		'remote_host' => 'https://dev-a123.workxpress.com',
	),
	Services_WorkXpress::APPLICATION_ROLE_PROD => array(
		'auth_key'   => 'KEY REMOVED FOR DOCUMENATION',
		'remote_host' => 'https://app-a123.workxpress.com',
	),
	Services_WorkXpress::APPLICATION_ROLE_TESTING => array(
		'auth_key'   => 'KEY REMOVED FOR DOCUMENATION',
		'remote_host' => 'https://app-a456.workxpress.com',
	),
);
 
?>