Differences

This shows you the differences between two versions of the page.

Link to this comparison view

dev resources - services workxpress project [2016/09/14 14:19]
dev resources - services workxpress project [2016/09/14 14:19] (current)
Line 1: Line 1:
 +====== Services WorkXpress Project ======
 +The [[http://​www.workxpress.com/​sites/​default/​files/​api/​Services_WorkXpress_Project.tar.gz|Services WorkXpress Project]] archive contains all of the files required to make API calls to a WorkXpress application using the [[Dev Resources - Services WorkXpress|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:
 +
 +  * /inc //- a folder for includes and project configuration.//​
 +    * config.php //- Constants and configuration for the project. //
 +  * /lib //- a folder for all php library files that we don't want accessed from the web.//
 +    * /pear //- a folder for all pear content.//
 +      * PEAR.php // - Base pear functionality. //
 +      * /PEAR
 +        * Exception.php //- Pear's base exception class //
 +      * /Services
 +        * WorkXpress.php //- Base Class for all Services WorkXpress Objects.//
 +        * /WorkXpress
 +          * Exception.php //- An extended Services WorkXpress Exception object.//
 +          * Request.php //- Base Class for Request XML.//
 +          * Response.php //- Base Class for Response XML.//
 +          * WXQuery.php //- Paired with the WXQueryElement object, these objects are used to generate Query XML.//
 +          * WXQueryElement.php
 +          * wx_query_constants.php
 +          * /Request
 +            * AddItem.php //- The Request_AddItem class handles the XML for an AddItem request.//
 +            * ExecuteAction.php //- The Request_ExecuteAction class handles the XML for an ExecuteAction request.//
 +            * LookupData.php //- The Request_LookupData class handles the XML for an LookupData request.//
 +            * UpdateItem.php //- The Request_UpdateItem class handles the XML for an UpdateItem request.//
 +          * /Response
 +            * AddItem.php //- The Response_AddItem class handles the XML for an AddItem response.//
 +            * ExecuteAction.php //- The Response_ExecuteAction class handles the XML for an ExecuteAction response.//
 +            * LookupData.php //- The Response_LookupData class handles the XML for an LookupData response.//
 +            * UpdateItem.php //- The Response_UpdateItem class handles the XML for an UpdateItem response.//
 +        * /examples
 +          * add_item.php //- An example of how to use AddItem using objects to setup the call.//
 +          * add_item_array.php //- An example of how to use AddItem using an array to setup the call.//
 +          * execute_action.php //- An example of how to use ExecuteAction using objects to setup the call.//
 +          * execute_action_array.php //- An example of how to use ExecuteAction using an array to setup the call.//
 +          * lookup_data.php //- An example of how to use LookupData using objects to setup the call.//
 +          * lookup_data_array.php //- An example of how to use LookupData using an array to setup the call.//
 +          * update_item.php //- An example of how to use UpdateItem using objects to setup the call.//
 +          * update_item_array.php //- An example of how to use UpdateItem using an array to setup the call.//
 +      * /XML
 +        * Parser.php //- Pear's XML_Parser class.//
 +        * Unserializer.php //- Pears XML_Unserializer class.//
 +  * /scripts //- a folder for any script that's meant to be executed at the command line.//
 +    * test.php //- A test file that will perform necessary includes to check and make sure everything is set to go. //
 +  * /web //- a folder for any file to be accessed from the web.//
 +
 +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 =====
 +<code 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";​
 +
 +?></​code>​
 +
 +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 =====
 +<code php><?​php
 +
 +set_include_path('​.'​ . PATH_SEPARATOR . BASE_PATH.'/​lib/​pear'​);​
 +
 +include_once('​Services/​WorkXpress.php'​);​
 +
 +?></​code>​
 +
 +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:​
 +
 +<code php><?​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',​
 + ),
 +);
 +
 +?></​code>​
dev resources - services workxpress project.txt ยท Last modified: 2016/09/14 14:19 (external edit)
Copyright WorkXpress, 2019