easysys-connector
EasysysConnector PHP 5 library., (*1)
Installation
Composer
Install composer if you haven't it., (*2)
``` bash
$ curl -sS https://getcomposer.org/installer | php, (*3)
Create a composer.json file for your project if you haven't it and put the library in it.
```{.json}
{
"require": {
"remdan/easysys-connector": "dev-master"
}
}
Now tell composer to download the library by running the following command:, (*4)
``` bash
$ php composer.phar composer install, (*5)
or if you have already installed a composer you can update it:
``` bash
$ php composer.phar update remdan/easysys-connector
Composer will now fetch and install this library in the vendor directory vendor/remdan
, (*6)
Add the autoloader:, (*7)
```{.php}
require 'vendor/autoload.php';, (*8)
### Download
If you don't use Composer in your application, just donwload the library and require the provided SplClassLoader:
```{.php}
require 'src/SplClassLoader.php';
Usage
Create a EasysysConnector and add a HttpAdapter and a AuthAdapter:, (*9)
```{.php}
<?php, (*10)
$curlHttpAdapter = new EasysysConnector\HttpAdapter\Curl\CurlHttpAdapter();
$tokenAuthAdapter = new EasysysConnector\AuthAdapter\Token\TokenAuthAdapter();, (*11)
$easysysConnector = new EasysysConnector\EasysysConnector($curlHttpAdapter, $tokenAuthAdapter);, (*12)
Now you have to add the resource-managers that you need:
```{.php}
<?php
$resourceContactManager = new EasysysConnector\Manager\Resource\Contact\ResourceContactManager();
...
$easysysConnector->addResourceManager($resourceContactManager);
Example
```{.php}
<?php, (*13)
$curlHttpAdapter = new EasysysConnector\HttpAdapter\Curl\CurlHttpAdapter();
$tokenAuthAdapter = new EasysysConnector\AuthAdapter\Token\TokenAuthAdapter();, (*14)
$easysysConnector = new EasysysConnector\EasysysConnector($curlHttpAdapter, $tokenAuthAdapter);, (*15)
$resourceContactManager = new EasysysConnector\Manager\Resource\Contact\ResourceContactManager();
$easysysConnector->addResourceManager($resourceContactManager);, (*16)
$data = $easysysConnector->get(ResourceContactManager::getResource())->listData(new Contact(), array('limit' => 5));, (*17)
### Resource
Currently, there are the following resource-interfaces available:
* `ResourceContactInterface` to use [contact](https://docs.easysys.ch/ressources/contact/)
* `ResourceInvoiceInterface` to use [kb_invoice](https://docs.easysys.ch/ressources/kb_invoice/)
If you need your own just create it, but it have to implement this interface:
```{.php}
<?php
namespace EasysysConnector\Model\Resource;
interface ResourceInterface
{
...
}
HttpAdapter
HttpAdapters are responsible to get data from remote APIs.
https://github.com/php-fig/fig-standards/blob/master/proposed/http-message.md, (*18)
Currently, there are the following adapters available:, (*19)
-
CurlHttpAdapter
to use cURL
-
GuzzleHttpAdapter
to use Guzzle
-
BuzzHttpAdapter
to use Buzz
If you need your own just create it, but it have to implement this interface:, (*20)
```{.php}
<?php, (*21)
namespace EasysysConnector\HttpAdapter;, (*22)
use EasysysConnector\HttpAdapter\HttpRequest;
use EasysysConnector\HttpAdapter\HttpResponse;, (*23)
interface HttpAdapterInterface
{
/**
* @param HttpRequest $request
* @return HttpResponse
*/
public function handleRequest(HttpRequest $request);
}, (*24)
### AuthAdapter
HttpAdapters are responsible to create the right request-object.
Currently, there are the following adapters available:
* `TokenAuthAdapter` to use [Public / Signature Key](https://docs.easysys.ch/key_version/)
* `OAuthAuthAdapter` to use [OAuth](https://docs.easysys.ch/oauth/oauth/)
If you need your own just create it, but it have to implement this interface:
```{.php}
<?php
namespace EasysysConnector\AuthAdapter;
use EasysysConnector\HttpAdapter\HttpParameterBag;
interface AuthAdapterInterface
{
/**
* @param HttpParameterBag $httpParameterBag
* @return array|string[]
*/
public function getDefaultHeaders(HttpParameterBag $httpParameterBag);
/**
* @param HttpParameterBag $httpParameterBag
* @return string
*/
public function getRequestUrl(HttpParameterBag $httpParameterBag);
}
OutputHandler
OutputHandler are responsible to handle the content from the response., (*25)
Currently, there are the following adapters available:
* ArrayOutputHandler
to use Array;
* JsonOutputHandler
to use Json;, (*26)
If you need your own just create it, but it have to implement this interface:, (*27)
```{.php}
<?php, (*28)
namespace EasysysConnector\OutputHandler;, (*29)
interface OutputHandlerInterface
{
/**
* @param $data
* @return mixed
*/
public function getContent($data);
}, (*30)
### Manager
Manager are responsible to handle the request and response for a resource.
There are the following methods implemented:
```{.php}
<?php
$resourceManager->listData($resourceObject, array('limit' => 5));
$resourceManager->searchData($resourceObject, array('limit' => 5));
$resourceManager->showData($resourceObject);
$resourceManager->createData($resourceObject);
$resourceManager->editData($resourceObject);
$resourceManager->updateData($resourceObject);
$resourceManager->deleteData($resourceObject);
$resourceManager->execute($parameterBag, $outputHandler)
Currently, there are the following managers available:
* ResourceContactManager
to use contact
* ResourceInvoiceManager
to use kb_invoice, (*31)
If you need your own just create it, but it have to implement this interface:, (*32)
```{.php}
<?php, (*33)
namespace EasysysConnector\Manager\Resource;, (*34)
use EasysysConnector\AuthAdapter\AuthAdapterInterface;
use EasysysConnector\HttpAdapter\HttpAdapterInterface;
use EasysysConnector\Model\Resource\ResourceInterface;, (*35)
interface ResourceManagerInterface
{
...
}
```, (*36)