Skip to content

Commit

Permalink
Merge cbbdcc7 into 6eadf55
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 9, 2020
2 parents 6eadf55 + cbbdcc7 commit cd8374e
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 171 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ before_script:
script:
- if [[ $DEPS == 'latest' ]]; then composer cs-check ; fi
- bin/phpstan analyse src/ --level=max
- composer remove laminas/laminas-zendframework-bridge --update-with-dependencies
- bin/kahlan --coverage=4 --reporter=verbose --clover=build/logs/clover.xml
- bin/php-coveralls -v --exclude-no-stmt

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CONTRIBUTING
To contribute, you can send pull requests with :

- Typo fix.
- Use [Zend Coding Standard](https://github.com/zendframework/zend-coding-standard).
- Use [Zend Coding Standard](https://github.com/laminas/laminas-coding-standard).
- patch(es) need new/updated test(s).
- new feature(s) need test(s).

Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ ApigilityConsumer
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat)](https://github.com/phpstan/phpstan)
[![Downloads](https://poser.pugx.org/samsonasik/apigility-consumer/downloads)](https://packagist.org/packages/samsonasik/apigility-consumer)

ZF Apigility Client module to consume API Services.
Laminas API Tools Client module to consume API Services.

> This is README for version ^2.0 which only support php ^7.1 with zend-servicemanager v3 and zend-json v3
> This is README for version ^3.0 which only support php ^7.1 with laminas-servicemanager v3 and laminas-json v3
> This is README for version ^2.0, you can read at [version 1 readme](https://github.com/samsonasik/ApigilityConsumer/tree/2.x.x) which only support php ^7.1 with zend-servicemanager v3 and zend-json v3
> For version 1, you can read at [version 1 readme](https://github.com/samsonasik/ApigilityConsumer/tree/1.x.x) which still support php ^5.6|^7.0 with zend-servicemanager v2.
Expand All @@ -27,7 +29,7 @@ composer require samsonasik/apigility-consumer
For its configuration, copy `vendor/samsonasik/apigility-consumer/config/apigility-consumer.local.php.dist` to `config/autoload/apigility-consumer.local.php` and configure with your api host url (required), oauth, and/or http auth settings:

```php
use Zend\Http\Client as HttpClient;
use Laminas\Http\Client as HttpClient;

return [
'apigility-consumer' => [
Expand Down Expand Up @@ -112,9 +114,9 @@ return [
],
```

Using at Zend\Expressive
Using at Mezzio
------------------------
You can use at Zend\Expressive, after set up local `config/autoload/apigility-consumer.local.php` like above, you can copy `config/expressive.local.php.dist` to `config/autoload/expressive.local.php`, and you can use it.
You can use at Mezzio, after set up local `config/autoload/apigility-consumer.local.php` like above, you can copy `config/expressive.local.php.dist` to `config/autoload/expressive.local.php`, and you can use it.


Services
Expand Down Expand Up @@ -240,7 +242,7 @@ $clientResult = $client->callAPI($data, $timeout);
if api call require authentication for basic or digest, you can apply `->withHttpAuthType()`:

```php
use Zend\Http\Client as HttpClient;
use Laminas\Http\Client as HttpClient;

$clientResult = $client->withHttpAuthType(HttpClient::AUTH_BASIC)
->callAPI($data, $timeout);
Expand All @@ -254,7 +256,7 @@ that will read of specified basic or digest auth config we defined at `config/au
If you want to specify custom username and password for the Http Auth on `callAPI()` call, you can specify via `$data`:

```php
use Zend\Http\Client as HttpClient;
use Laminas\Http\Client as HttpClient;

$data = [
'api-route-segment' => '/api',
Expand Down
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
],
"require": {
"php": "^7.1",
"zendframework/zend-http": "^2.6",
"zendframework/zend-json": "^3.1.2",
"zendframework/zend-servicemanager": "^3.3.0",
"zendframework/zend-stdlib": "^3.2.1"
"laminas/laminas-http": "^2.6",
"laminas/laminas-json": "^3.1.2",
"laminas/laminas-servicemanager": "^3.3.0",
"laminas/laminas-stdlib": "^3.2.1"
},
"require-dev": {
"guzzlehttp/guzzle": "^6.3",
"kahlan/kahlan": "^4.0",
"php-coveralls/php-coveralls": "^2.0",
"phpstan/phpstan": "^0.11.19",
"symfony/yaml": "^3.2.7",
"zendframework/zend-coding-standard": "^1.0"
"laminas/laminas-coding-standard": "^2.0"
},
"config": {
"bin-dir": "bin"
Expand All @@ -59,5 +59,7 @@
"scripts": {
"cs-check": "phpcs",
"cs-fix": "phpcbf"
}
},
"minimum-stability": "alpha",
"prefer-stable": true
}
2 changes: 1 addition & 1 deletion config/apigility-consumer.local.php.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Zend\Http\Client as HttpClient;
use Laminas\Http\Client as HttpClient;

return [
'apigility-consumer' => [
Expand Down
4 changes: 2 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework Coding Standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>
<ruleset name="Laminas Coding Standard">
<rule ref="./vendor/laminas/laminas-coding-standard/src/LaminasCodingStandard/ruleset.xml"/>

<!-- Paths to check -->
<file>src</file>
Expand Down
6 changes: 3 additions & 3 deletions spec/Service/ClientAuthServiceSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use Kahlan\Plugin\Double;
use ReflectionProperty;
use RuntimeException;
use Zend\Http\Client;
use Zend\Http\Response;
use Zend\Json\Json;
use Laminas\Http\Client;
use Laminas\Http\Response;
use Laminas\Json\Json;

describe('ClientAuthService', function () {
beforeAll(function () {
Expand Down
8 changes: 4 additions & 4 deletions spec/Service/ClientServiceSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use Kahlan\Plugin\Double;
use ReflectionProperty;
use RuntimeException;
use Zend\Http\Client\Adapter\Curl;
use Zend\Http\Client as HttpClient;
use Zend\Http\Response;
use Zend\Json\Json;
use Laminas\Http\Client\Adapter\Curl;
use Laminas\Http\Client as HttpClient;
use Laminas\Http\Response;
use Laminas\Json\Json;

describe('ClientService', function () {
beforeAll(function () {
Expand Down
4 changes: 2 additions & 2 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class ConfigProvider
{
public function __invoke() : array
public function __invoke(): array
{
$config = include __DIR__.'/../config/module.config.php';
$config = include __DIR__ . '/../config/module.config.php';
return [
'dependencies' => $config['service_manager'],
];
Expand Down
19 changes: 9 additions & 10 deletions src/Error/SpecialErrorMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@
* - RESOURCE_NOT_AVAILABLE not available is for server not found/down
* - INVALID_REQUEST_FILE for invalid files data
* - SERVICE_UNAVAILABLE means there is error in server when decode data.
*
*/
final class SpecialErrorMessage
{
const RESOURCE_NOT_AVAILABLE = [
'code' => 410,
'reason' => 'API Call failed, The target resource %s is no longer available, ' .
'please check your ApigilityConsumer config, ' .
'and/or ask API service administrator whether the API server is down.',
public const RESOURCE_NOT_AVAILABLE = [
'code' => 410,
'reason' => 'API Call failed, The target resource %s is no longer available, '
. 'please check your ApigilityConsumer config, '
. 'and/or ask API service administrator whether the API server is down.',
];

const INVALID_REQUEST_FILE = [
'code' => 400,
public const INVALID_REQUEST_FILE = [
'code' => 400,
'reason' => 'Invalid files data, please make sure you have "tmp_name" and "name" key',
];

const SERVICE_UNAVAILABLE = [
'code' => 503,
public const SERVICE_UNAVAILABLE = [
'code' => 503,
'reason' => 'Service Unavailable, please contact API service administrator.',
];
}
4 changes: 2 additions & 2 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class Module
{
public function getConfig() : array
public function getConfig(): array
{
return include __DIR__.'/../config/module.config.php';
return include __DIR__ . '/../config/module.config.php';
}
}
30 changes: 11 additions & 19 deletions src/Result/ClientAuthResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace ApigilityConsumer\Result;

use ApigilityConsumer\Error\SpecialErrorMessage as ErrorMessage;
use Laminas\Json\Json;
use RuntimeException;
use Zend\Json\Json;

class ClientAuthResult implements ResultInterface
{
Expand All @@ -25,7 +25,9 @@ class ClientAuthResult implements ResultInterface
*/
public static $messages = [];

// avoid class instantiation
/**
* avoid class instantiation
*/
private function __construct()
{
}
Expand All @@ -37,11 +39,9 @@ private function __construct()
*
* if decode failed, it will return static::fromFailure() with "Service unavailable" error message
*
* @param string $result
*
* @return self
*/
public static function applyResult(string $result) : ResultInterface
public static function applyResult(string $result): ResultInterface
{
$resultArray = [];
if (! empty(self::$messages)) {
Expand Down Expand Up @@ -72,32 +72,24 @@ public static function applyResult(string $result) : ResultInterface

/**
* A success result, with 'success' property = true.
*
* @param array|null $result
*
* @return self
*/
private static function fromSucceed(?array $result) : self
private static function fromSucceed(?array $result): self
{
$self = new self();
$self = new self();
$self->success = true;
$self->data = $result;
$self->data = $result;

return $self;
}

/**
* A failure result process, return self with success = false
* with brought messages when exists.
*
* @param array|null $result
*
* @return self
*/
private static function fromFailure(?array $result) : self
private static function fromFailure(?array $result): self
{
$self = new self();
$self->success = false;
$self = new self();
$self->success = false;
$self::$messages = $result['validation_messages'] ?? [];

return $self;
Expand Down
27 changes: 9 additions & 18 deletions src/Result/ClientResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
namespace ApigilityConsumer\Result;

use ApigilityConsumer\Error\SpecialErrorMessage as ErrorMessage;
use Laminas\Json\Json;
use RuntimeException;
use Zend\Json\Json;

/**
* An 'entity' as value object that returned in \ApigilityConsumer\Service\ClientService::getClientResult().
*
*/
class ClientResult implements ResultInterface
{
Expand All @@ -29,7 +28,9 @@ class ClientResult implements ResultInterface
*/
public static $messages = [];

// avoid class instantiation
/**
* avoid class instantiation
*/
private function __construct()
{
}
Expand All @@ -47,11 +48,9 @@ private function __construct()
*
* Otherwise, it will return succeed.
*
* @param string $result
*
* @return self
*/
public static function applyResult(string $result) : ResultInterface
public static function applyResult(string $result): ResultInterface
{
if (! empty(self::$messages)) {
$resultArray['validation_messages'] = self::$messages;
Expand Down Expand Up @@ -81,14 +80,10 @@ public static function applyResult(string $result) : ResultInterface

/**
* A success result, with 'success' property = true
*
* @param array|null $result
*
* @return self
*/
private static function fromSucceed(?array $result) : self
private static function fromSucceed(?array $result): self
{
$self = new self();
$self = new self();
$self->success = true;
$self->data = $result;

Expand All @@ -97,14 +92,10 @@ private static function fromSucceed(?array $result) : self

/**
* A failure result process, return self with success = false and its validation_messages when exists.
*
* @param array|null $result
*
* @return self
*/
private static function fromFailure(?array $result) : self
private static function fromFailure(?array $result): self
{
$self = new self();
$self = new self();
$self->success = false;

$self::$messages = ! isset($result['validation_messages'])
Expand Down
7 changes: 1 addition & 6 deletions src/Result/ResultInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,5 @@

interface ResultInterface
{
/**
* @param string $result
*
* @return self
*/
public static function applyResult(string $result) : ResultInterface;
public static function applyResult(string $result): self;
}
7 changes: 1 addition & 6 deletions src/Service/ClientApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ interface ClientApiInterface
{
/**
* Process Call API.
*
* @param array $data
* @param int|null $timeout
*
* @return ResultInterface
*/
public function callAPI(array $data, int $timeout = null) : ResultInterface;
public function callAPI(array $data, ?int $timeout = null): ResultInterface;
}

0 comments on commit cd8374e

Please sign in to comment.