https://github.com/dldl/webservice
WebService library that can be used to normalize WebServices calls and add cache support and more.
https://github.com/dldl/webservice
php php-library webservice
Last synced: 6 months ago
JSON representation
WebService library that can be used to normalize WebServices calls and add cache support and more.
- Host: GitHub
- URL: https://github.com/dldl/webservice
- Owner: dldl
- License: mit
- Created: 2016-10-28T20:51:11.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-06T10:28:49.000Z (about 9 years ago)
- Last Synced: 2025-05-20T05:06:31.622Z (about 1 year ago)
- Topics: php, php-library, webservice
- Language: PHP
- Homepage: https://packagist.org/packages/dldl/webservice
- Size: 23.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
dLdLWebService
==============
**⚠ Development for this library has stopped since [HTTPlug](https://github.com/php-http/httplug) is more complete and plays the same role.**
This PHP library allows you to follow a normalized way to connect to your web services, with support for logs and cache following
PSR-3 and PSR-6.
[](https://travis-ci.org/dldl/webservice)
[](https://insight.sensiolabs.com/projects/d5e04165-7382-4cfa-aa34-8860f96af5ab)
[](https://packagist.org/packages/dldl/webservice)

Installation
------------
Install it using Composer:
```sh
composer require dldl/webservice
```
Usage
-----
Here is a simple example to see how this library can be used:
```php
connector = $connector;
$this->parser = $parser;
$this->host = $host;
}
public function getConnector()
{
return $this->connector;
}
public function getPosts($facebookUsername)
{
try {
$this->getConnector()->connect($this->host);
} catch (WebServiceException $e) {
return [];
}
$request = new Request($facebookUsername . '/feed');
$this->getConnector()->getCache()->getConfig()->add($request, 60*60*24);
try {
$postData = $this->getConnector()->sendRequest($request);
} catch (WebServiceException $e) {
return [];
}
$this->getConnector()->disconnect();
return $this->parser->parse($postData);
}
}
```
Of course, you may perform specific actions in the catch blocks.
The main idea is to split the web service requests into three parts:
- *Connector*, in charge to connect to the web service and to grab and/or send raw data from a predefined request
- *Parser*, in charge to transform this raw data to business objects
- *WebService*, in charge to check business conditions calling services but also to delegate the call to *connectors*
and to *parsers*
This allows to separate the way data is retrieve from the way data is aim to be used. It can be easy to cache, log,
add extensions such as proxies and change the type of connector at any moment (for example, to move from a SOAP to a
REST web service).
Connectors must implement the `ConnectorInterface`. The easiest way is to extend the `AbstractConnector` class which provides
logs and cache out of the box. Connectors can use any technology such as `cURL`, `Guzzle`, `Soap` or any specific library
but must be independent to the data it handles.
Contribution
------------
Every functionality must be tested and documented. To contribute:
1. Clone the repository
2. Install dependencies, using composer: `composer install`
3. Run tests, using PHPUnit: `./vendor/bin/phpunit`