Skip to content

MPJHorner/Khaos_Control_PHP_Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keystone Khaos API PHP Library

Example Usage

$soapClient = new SoapClient('https://KhaosServer/KhaosIDS.exe/wsdl/IKosWeb');

$khaosApiClient = new KhaosApi\Client($soapClient);

$args = array('stockCode' => array('SKU001',
                                    'SKU002',
                                    'SKU003'));

$stockXML = $khaosApiClient->exportStock($args);

Loading the library

This library is designed to the PSR-0 specification and can therefore ultilise the SplClassLoader Class.

The SplClassLoader Class can be found here: http://www.php-fig.org/psr/psr-0/

The PSR-0 specification is located here: http://www.php-fig.org/psr/psr-0/

Example of registering the autoloader to work with this library.

/**
 * Assumes this library is installed at this location: /path/to/lib/KhaosAPI/
 */

// Include the autoloader
require 'SplClassLoader.php';

// Create an instance of the autoloader referencing your parent library folder.
$classLoader = new SplClassLoader(null, '/path/to/lib/');

// register the autoloader.
$classLoader->register();

// Library can now be autoloaded like so:
$soapClient = new SoapClient('https://KhaosServer/KhaosIDS.exe/wsdl/IKosWeb');
$khaosApiClient = new KhaosApi\Client($soapClient);

Arguments

Arguments should be passed into the methods as multidimensional arrays.

$args = array('foo' => array('bar',
                                'baz'),
                'qux' => true);

$khaosApiClient->doSomething($args);

You'll need to see the relevant Class and Khaos documentation to understand which Classes accept which arguments.

Internal Class API

This library has been designed to have one Class per Khaos API method. All of the Classes reside within the KhaosAPI/Caller/ directory.

Classes have the same (title cased) name as the SOAP method it's calling. So, if the SOAP method is called GetStockList then the Class will be named GetStockList.php KhaosAPI/Caller/GetStockList.php.

These Classes are called Callers.

For example; to execute the GetStockList Caller you do so via a KhaosApi\Client instance variable. See example below:

$khaosApiClient->getStockList($args);

When you execute Callers you reference them in camel case. Not title case. Calling a Caller will execute the run method within that particular Class.

Therefore...

$khaosApiClient->getStockList($args);

...will result in executing KhaosAPI/Caller/GetStockList::run()

Calling bespoke Khaos API methods

To call a bespoke SOAP method you will first need to create a Caller (Class) that handles the request. Your Class must extend \KhaosAPI\Caller\CallerAbstract

So for example, if you wanted to call a Khaos method called DoSomething you could do it like so:

namespace MyNamespace
{   
    class DoSomething extends \KhaosAPI\Caller\CallerAbstract
    {
        public function run()
        {   
            return $this->getClient()->DoSomething(); // This is the call to the SOAP method DoSomething.
        }
    }
}

You would then call your Class like this:

$soapClient = new SoapClient('https://KhaosServer/KhaosIDS.exe/wsdl/IKosWeb');

$khaosApiClient = new KhaosApi\Client($soapClient);

// Register your class
$khaosApiClient->registerCaller(new \MyNamespace\DoSomething);

// Call DoSomething::run
$stockXML = $khaosApiClient->doSomething();

To access supplied arguments within your Caller use the getArgs() method.

namespace MyNamespace
{   
    class DoSomething extends \KhaosAPI\Caller\CallerAbstract
    {
        public function run()
        {   
            $this->getArgs()->myKey; // $args['myKey']
        }
    }
}

Calling methods with differing SoapClient instances.

You can also choose to call SOAP methods using a different SoapClient instance if you wish. The second argument of each method call can accept a SoapClient instance to use just for that request.

$args = array('qux' => true);

$newSoapClient = new SoapClient('https://KhaosServer/KhaosIDS.exe/wsdl/IKosWeb');

$khaosApiClient->doSomething($args, $newSoapClient);

About

Simple wrapper for Khaos Control API in PHP.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages