@ 2014-02-03T12:44:40Z <?php
class Cache
{
public static function has( $name ){
return false;
}
public static function get( $name ){
return null;
}
public static function put( $name, $value, $time = 1440 ){
return true;
}
}
class Collivery
{
protected $token;
protected $client;
protected $config;
protected $errors = array();
protected $check_cache = 2;
protected $default_address_id;
protected $client_id;
protected $user_id;
/**
* Setup class with basic Config
*
* @param Array $config Configuration Array
*/
function __construct( array $config = array() )
{
$this->config = (object) array(
'app_name' => 'Default App Name', // Application Name
'app_version' => '0.0.1', // Application Version
'app_host' => '', // Framework/CMS name and version, eg 'Wordpress 3.8.1 WooCommerce 2.0.20' / 'Joomla! 2.5.17 VirtueMart 2.0.26d'
'app_url' => '', // URL your site is hosted on
'user_email' => 'demo@collivery.co.za',
'user_password' => 'demo',
'demo' => false,
);
foreach ( $config as $key => $value ) {
$this->config->$key = $value;
}
if ( $this->config->demo ){
$this->config->user_email = 'demo@collivery.co.za';
$this->config->user_password = 'demo';
}
$this->authenticate();
}
/**
* Setup the Soap Object
*
* @return SoapClient MDS Collivery Soap Client
*/
protected function init ()
{
if ( ! $this->client ){
try {
$this->client = new SoapClient( // Setup the soap client
'http://www.collivery.co.za/wsdl/v2', // URL to WSDL File
array( 'cache_wsdl' => WSDL_CACHE_NONE ) // Don't cache the WSDL file
);
} catch (SoapFault $e) {
$this->catchSoapFault( $e );
return false;
}
}
return true;
}
/**
* Checks if the Soap Client has been set, and returns it.
*
* @return SoapClient Webserver Soap Client
*/
protected function client()
{
if ( ! $this->client ) {
$this->init();
}
if ( ! $this->token ) {
$this->authenticate();
}
return $this->client;
}
/**
* Authenticate and set the token
*
* @return string
*/
protected function authenticate()
{
if ( ( $this->check_cache == 2 ) && Cache::has('collivery.auth') ) {
$authenticate = Cache::get('collivery.auth');
$this->default_address_id = $authenticate['default_address_id'];
$this->client_id = $authenticate['client_id'];
$this->user_id = $authenticate['user_id'];
$this->token = $authenticate['token'];
return true;
} else {
if ( ! $this->init() ) return false;
$user_email = $this->config->user_email;
$user_password = $this->config->user_password;
try {
$authenticate = $this->client->authenticate($user_email, $user_password, $this->token,
array(
'name' => $this->config->app_name . ' mds/collivery/class',
'version' => $this->config->app_version,
'host' => $this->config->app_host,
'url' => $this->config->app_url,
'lang' => 'PHP '. phpversion(),
));
} catch (SoapFault $e) {
$this->catchSoapFault( $e );
return false;
}
if ( is_array( $authenticate ) && isset( $authenticate['token'] ) ){
if ( $this->check_cache != 0 ) Cache::put( 'collivery.auth', $authenticate, 50 );
$this->default_address_id = $authenticate['default_address_id'];
$this->client_id = $authenticate['client_id'];
$this->user_id = $authenticate['user_id'];
$this->token = $authenticate['token'];
return true;
} else {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
$this->setError( 'result_unexpected', 'No address_id returned.' );
return false;
}
}
}
/**
* Returns the available Parcel Type ID and value array for use in adding a collivery.
*
* @param int $address_id The ID of the address you wish to retrieve.
* @return array Address
*/
public function getAddress( $address_id )
{
if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.address.'. $this->client_id .'.'. $address_id ) ) {
return Cache::get( 'collivery.address.'. $this->client_id .'.'. $address_id );
} else {
try {
$result = $this->client()->get_address( $address_id, $this->token );
} catch (SoapFault $e) {
$this->catchSoapFault( $e );
return false;
}
if ( isset( $result['address'] ) ) {
if ( $this->check_cache != 0 ) Cache::put( 'collivery.address.'. $this->client_id .'.'. $address_id, $result['address'], 60*24 );
return $result['address'];
} else {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
$this->setError( 'result_unexpected', 'No address_id returned.' );
return false;
}
}
}
/**
* Returns all the addresses belonging to a client.
*
* @param array $filter Filter Addresses
* @return array
*/
public function getAddresses( array $filter = array() )
{
if ( ( $this->check_cache == 2 ) && empty( $filter ) && Cache::has( 'collivery.addresses.'. $this->client_id ) ) {
return Cache::get( 'collivery.addresses.'. $this->client_id );
} else {
try {
$result = $this->client()->get_addresses( $this->token, $filter );
} catch (SoapFault $e) {
$this->catchSoapFault( $e );
return false;
}
if ( isset( $result['addresses'] ) ) {
if ( $this->check_cache != 0 ) Cache::put( 'collivery.addresses.'. $this->client_id, $result['addresses'], 60*24 );
return $result['addresses'];
} else {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
$this->setError( 'result_unexpected', 'No address_id returned.' );
return false;
}
}
}
/**
* Returns the Contact people of a given Address ID.
*
* @param int $address_id Address ID
* @return array
*/
public function getContacts( $address_id )
{
if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.contacts.'. $this->client_id .'.'. $address_id ) ) {
return Cache::get( 'collivery.contacts.'. $this->client_id .'.'. $address_id );
} else {
try {
$result = $this->client()->get_contacts( $address_id, $this->token );
} catch (SoapFault $e) {
$this->catchSoapFault( $e );
return false;
}
if ( isset( $result['contacts'] ) ) {
if ( $this->check_cache != 0 ) Cache::put( 'collivery.contacts.'. $this->client_id .'.'. $address_id, $result['contacts'], 60*24 );
return $result['contacts'];
} else {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
$this->setError( 'result_unexpected', 'No address_id returned.' );
return false;
}
}
}
/**
* Returns the POD image for a given Waybill Number.
*
* @param int $collivery_id Collivery waybill number
* @return array
*/
public function getPod( $collivery_id )
{
if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.pod.'. $this->client_id .'.'. $collivery_id ) ) {
return Cache::get( 'collivery.pod.'. $this->client_id .'.'. $collivery_id );
} else {
try {
$result = $this->client()->get_pod( $collivery_id, $this->token );
} catch (SoapFault $e) {
$this->catchSoapFault( $e );
return false;
}
if ( isset( $result['pod'] ) ) {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
if ( $this->check_cache != 0 ) Cache::put( 'collivery.pod.'. $this->client_id .'.'. $collivery_id, $result['pod'], 60*24 );
return $result['pod'];
} else {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
$this->setError( 'result_unexpected', 'No address_id returned.' );
return false;
}
}
}
/**
* Returns a list of avaibale parcel images for a given Waybill Number.
*
* @param int $collivery_id Collivery waybill number
* @return array
*/
public function getParcelImageList( $collivery_id )
{
if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.parcel_image_list.'. $this->client_id .'.'. $collivery_id ) ) {
return Cache::get( 'collivery.parcel_image_list.'. $this->client_id .'.'. $collivery_id );
} else {
try {
$result = $this->client()->get_parcel_image_list( $collivery_id, $this->token );
} catch (SoapFault $e) {
$this->catchSoapFault( $e );
return false;
}
if ( isset( $result['images'] ) ) {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
if ( $this->check_cache != 0 ) Cache::put( 'collivery.parcel_image_list.'. $this->client_id .'.'. $collivery_id, $result['images'], 60*12 );
return $result['images'];
} else {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
$this->setError( 'result_unexpected', 'No address_id returned.' );
return false;
}
}
}
/**
* Returns the image of a given parcel-id of a waybill.
* If the Waybill number is 54321 and there are 3 parcels, they would
* be referenced by id's 54321-1, 54321-2 and 54321-3.
*
* @param string $parcel_id Parcel ID
* @return array Array containing all the information
* about the image including the image
* itself in base64
*/
public function getParcelImage( $parcel_id )
{
if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.parcel_image.'. $this->client_id .'.'. $parcel_id ) ) {
return Cache::get( 'collivery.parcel_image.'. $this->client_id .'.'. $parcel_id );
} else {
try {
$result = $this->client()->get_parcel_image( $parcel_id, $this->token );
} catch (SoapFault $e) {
$this->catchSoapFault( $e );
return false;
}
if ( isset( $result['image'] ) ) {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
if ( $this->check_cache != 0 ) Cache::put( 'collivery.parcel_image.'. $this->client_id .'.'. $parcel_id, $result['image'], 60*24 );
return $result['image'];
} else {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
$this->setError( 'result_unexpected', 'No address_id returned.' );
return false;
}
}
}
/**
* Returns the status tracking detail of a given Waybill number.
* If the collivery is still active, the estimated time of delivery
* will be provided. If delivered, the time and receivers name (if availble)
* with returned.
*
* @param int $collivery_id Collivery ID
* @return array Collivery Status Information
*/
public function getStatus( $collivery_id )
{
if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.status.'. $this->client_id .'.'. $collivery_id ) ) {
return Cache::get( 'collivery.status.'. $this->client_id .'.'. $collivery_id );
} else {
try {
$result = $this->client()->get_collivery_status( $collivery_id, $this->token );
} catch (SoapFault $e) {
$this->catchSoapFault( $e );
return false;
}
if ( isset( $result['status_id'] ) ) {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
if ( $this->check_cache != 0 ) Cache::put( 'collivery.status.'. $this->client_id .'.'. $collivery_id, $result, 60*12 );
return $result;
} else {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
$this->setError( 'result_unexpected', 'No address_id returned.' );
return false;
}
}
}
/**
* Handle error messages in SoapFault
*
* @param SoapFault $e SoapFault Object
*/
protected function catchSoapFault( $e )
{
$this->setError( $e->faultcode, $e->faultstring );
}
/**
* Add a new error
*
* @param string $id Error ID
* @param string $text Error text
*/
protected function setError( $id, $text )
{
$this->errors[ $id ] = $text;
}
/**
* Retrieve errors
*/
public function getErrors()
{
return $this->errors;
}
/**
* Check if this instance has an error
*/
public function hasErrors()
{
return !empty($this->errors);
}
/**
* Clears all the Errors
*/
public function clearErrors()
{
$this->errors = array();
}
/**
* Disable Cached completely and retrieve data directly from the webservice
*/
public function disableCache()
{
$this->check_cache = 0;
}
/**
* Ignore Cached data and retrieve data directly from the webservice
* Save returned data to Cache
*/
public function ignoreCache()
{
$this->check_cache = 1;
}
/**
* Check if cache exists before querying the webservice
* If webservice was queried, save returned data to Cache
*/
public function enableCache()
{
$this->check_cache = 2;
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.2.0 0.003 0.009 19.35 7.1.10 0.000 0.014 17.95 7.1.7 0.006 0.003 17.01 7.1.6 0.012 0.012 19.43 7.1.5 0.020 0.020 34.36 7.1.0 0.013 0.070 22.40 7.0.20 0.011 0.004 16.61 7.0.14 0.013 0.063 22.01 7.0.10 0.017 0.070 20.02 7.0.9 0.030 0.050 20.00 7.0.8 0.010 0.073 20.11 7.0.7 0.007 0.067 20.02 7.0.6 0.010 0.080 19.94 7.0.5 0.027 0.050 20.30 7.0.4 0.013 0.070 19.96 7.0.3 0.000 0.070 20.15 7.0.2 0.003 0.090 20.07 7.0.1 0.000 0.067 20.04 7.0.0 0.013 0.050 20.09 5.6.28 0.003 0.070 20.95 5.6.25 0.003 0.077 20.86 5.6.24 0.013 0.053 20.77 5.6.23 0.010 0.077 20.71 5.6.22 0.007 0.080 20.71 5.6.21 0.003 0.093 20.50 5.6.20 0.017 0.083 21.13 5.6.19 0.007 0.053 21.10 5.6.18 0.007 0.083 21.03 5.6.17 0.013 0.080 21.05 5.6.16 0.007 0.063 21.15 5.6.15 0.007 0.040 21.14 5.6.14 0.013 0.077 21.02 5.6.13 0.013 0.080 21.25 5.6.12 0.010 0.053 21.22 5.6.11 0.003 0.087 21.03 5.6.10 0.003 0.080 21.15 5.6.9 0.000 0.047 21.23 5.6.8 0.007 0.077 20.55 5.6.7 0.013 0.070 20.54 5.6.6 0.010 0.067 20.55 5.6.5 0.010 0.057 20.40 5.6.4 0.003 0.087 20.55 5.6.3 0.013 0.073 20.41 5.6.2 0.003 0.080 20.48 5.6.1 0.007 0.080 20.49 5.6.0 0.007 0.067 20.47 5.5.38 0.007 0.083 20.50 5.5.37 0.017 0.077 20.63 5.5.36 0.007 0.083 20.58 5.5.35 0.007 0.087 20.50 5.5.34 0.007 0.057 20.87 5.5.33 0.017 0.047 20.73 5.5.32 0.010 0.043 20.93 5.5.31 0.010 0.080 20.85 5.5.30 0.003 0.053 21.00 5.5.29 0.007 0.087 20.84 5.5.28 0.003 0.053 20.82 5.5.27 0.003 0.047 20.72 5.5.26 0.007 0.097 21.01 5.5.25 0.010 0.077 20.77 5.5.24 0.007 0.067 20.11 5.5.23 0.023 0.067 20.35 5.5.22 0.010 0.070 20.20 5.5.21 0.013 0.070 20.29 5.5.20 0.010 0.070 20.33 5.5.19 0.007 0.073 20.24 5.5.18 0.013 0.077 20.18 5.5.16 0.010 0.033 20.29 5.5.15 0.010 0.053 20.30 5.5.14 0.010 0.077 20.27 5.5.13 0.003 0.047 20.34 5.5.12 0.013 0.063 20.36 5.5.11 0.017 0.060 20.18 5.5.10 0.010 0.057 20.07 5.5.9 0.010 0.077 20.20 5.5.8 0.013 0.073 20.25 5.5.7 0.013 0.063 20.18 5.5.6 0.013 0.067 20.05 5.5.5 0.013 0.073 20.12 5.5.4 0.003 0.037 20.14 5.5.3 0.003 0.080 20.23 5.5.2 0.003 0.037 20.17 5.5.1 0.007 0.080 20.13 5.5.0 0.007 0.070 20.14 5.4.45 0.003 0.043 19.22 5.4.44 0.020 0.073 19.36 5.4.43 0.003 0.087 19.23 5.4.42 0.000 0.083 19.39 5.4.41 0.007 0.080 19.27 5.4.40 0.007 0.047 19.24 5.4.39 0.003 0.050 19.09 5.4.38 0.017 0.067 19.07 5.4.37 0.000 0.083 18.93 5.4.36 0.007 0.063 19.23 5.4.35 0.013 0.077 18.88 5.4.34 0.003 0.047 19.08 5.4.32 0.007 0.080 18.93 5.4.31 0.010 0.073 19.14 5.4.30 0.007 0.073 18.97 5.4.29 0.007 0.067 19.04 5.4.28 0.013 0.077 19.13 5.4.27 0.003 0.077 19.23 5.4.26 0.017 0.057 18.91 5.4.25 0.010 0.063 18.87 5.4.24 0.010 0.070 19.04 5.4.23 0.000 0.050 19.22 5.4.22 0.003 0.040 18.90 5.4.21 0.007 0.043 19.20 5.4.20 0.000 0.040 19.05 5.4.19 0.017 0.070 19.06 5.4.18 0.013 0.043 19.24 5.4.17 0.010 0.063 18.96 5.4.16 0.003 0.070 19.14 5.4.15 0.000 0.047 18.86 5.4.14 0.010 0.070 16.51 5.4.13 0.007 0.073 16.39 5.4.12 0.013 0.063 16.42 5.4.11 0.017 0.060 16.50 5.4.10 0.007 0.060 16.43 5.4.9 0.017 0.060 16.57 5.4.8 0.000 0.080 16.54 5.4.7 0.010 0.070 16.37 5.4.6 0.007 0.063 16.54 5.4.5 0.007 0.063 16.50 5.4.4 0.003 0.047 16.57 5.4.3 0.007 0.070 16.49 5.4.2 0.007 0.073 16.42 5.4.1 0.013 0.053 16.50 5.4.0 0.013 0.030 15.93 5.3.29 0.007 0.060 14.93 5.3.28 0.003 0.040 14.86 5.3.27 0.003 0.057 14.79 5.3.26 0.003 0.083 14.79 5.3.25 0.003 0.073 14.80 5.3.24 0.000 0.047 14.85 5.3.23 0.017 0.070 14.65 5.3.22 0.003 0.067 14.67 5.3.21 0.003 0.083 14.68 5.3.20 0.007 0.047 14.84 5.3.19 0.007 0.070 14.64 5.3.18 0.013 0.057 14.70 5.3.17 0.003 0.083 14.75 5.3.16 0.010 0.070 14.61 5.3.15 0.007 0.060 14.80 5.3.14 0.003 0.077 14.65 5.3.13 0.007 0.043 14.78 5.3.12 0.007 0.077 14.79 5.3.11 0.010 0.043 14.77 5.3.10 0.003 0.040 14.22 5.3.9 0.000 0.040 14.21 5.3.8 0.003 0.077 14.27 5.3.7 0.007 0.040 14.13 5.3.6 0.007 0.043 14.12 5.3.5 0.020 0.057 14.14 5.3.4 0.007 0.073 14.16 5.3.3 0.007 0.073 13.93 5.3.2 0.007 0.070 13.83 5.3.1 0.003 0.070 13.88 5.3.0 0.010 0.063 13.80
preferences:dark mode live preview
34.1 ms | 401 KiB | 5 Q