From ae3f8e5a518b6edcc65ed815e359b3f7532e3548 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 09:10:09 +0100 Subject: [PATCH 01/58] - New "EveScout" API client --- app/Client/AbstractApi.php | 2 +- app/Client/{ => Ccp}/AbstractCcp.php | 5 +++-- app/Client/{ESI.php => Ccp/Esi/Esi.php} | 10 ++++++---- app/Client/{ => Ccp/Esi}/EsiInterface.php | 2 +- app/Client/{SSO.php => Ccp/Sso/Sso.php} | 6 +++--- app/Client/{ => Ccp/Sso}/SsoInterface.php | 2 +- app/Client/EveScout/EveScout.php | 18 ++++++++++++++++++ app/Client/EveScout/EveScoutInterface.php | 9 +++++++++ app/Client/{Github.php => GitHub/GitHub.php} | 6 +++--- app/Client/{ => GitHub}/GitHubInterface.php | 2 +- .../{ESIConf.php => Ccp/Esi/EsiConf.php} | 2 +- 11 files changed, 47 insertions(+), 17 deletions(-) rename app/Client/{ => Ccp}/AbstractCcp.php (96%) rename app/Client/{ESI.php => Ccp/Esi/Esi.php} (99%) rename app/Client/{ => Ccp/Esi}/EsiInterface.php (99%) rename app/Client/{SSO.php => Ccp/Sso/Sso.php} (94%) rename app/Client/{ => Ccp/Sso}/SsoInterface.php (95%) create mode 100644 app/Client/EveScout/EveScout.php create mode 100644 app/Client/EveScout/EveScoutInterface.php rename app/Client/{Github.php => GitHub/GitHub.php} (93%) rename app/Client/{ => GitHub}/GitHubInterface.php (92%) rename app/Config/{ESIConf.php => Ccp/Esi/EsiConf.php} (99%) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index 2ce9dbe..c07c777 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -71,7 +71,7 @@ abstract class AbstractApi extends \Prefab implements ApiInterface { /** * WebClient instance - * @var \Exodus4D\ESI\Lib\WebClient|null + * @var WebClient|null */ private $client = null; diff --git a/app/Client/AbstractCcp.php b/app/Client/Ccp/AbstractCcp.php similarity index 96% rename from app/Client/AbstractCcp.php rename to app/Client/Ccp/AbstractCcp.php index 8225158..4f07e6f 100644 --- a/app/Client/AbstractCcp.php +++ b/app/Client/Ccp/AbstractCcp.php @@ -6,13 +6,14 @@ * Time: 18:41 */ -namespace Exodus4D\ESI\Client; +namespace Exodus4D\ESI\Client\Ccp; +use Exodus4D\ESI\Client; use Exodus4D\ESI\Lib\Middleware\GuzzleCcpErrorLimitMiddleware; use Exodus4D\ESI\Lib\Middleware\GuzzleCcpLogMiddleware; use GuzzleHttp\HandlerStack; -abstract class AbstractCcp extends AbstractApi { +abstract class AbstractCcp extends Client\AbstractApi { /** * see parent diff --git a/app/Client/ESI.php b/app/Client/Ccp/Esi/Esi.php similarity index 99% rename from app/Client/ESI.php rename to app/Client/Ccp/Esi/Esi.php index 64c9468..5747771 100644 --- a/app/Client/ESI.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -6,12 +6,14 @@ * Time: 16:37 */ -namespace Exodus4D\ESI\Client; +namespace Exodus4D\ESI\Client\Ccp\Esi; + +use Exodus4D\ESI\Client\Ccp; use Exodus4D\ESI\Config; use Exodus4D\ESI\Mapper\Esi as Mapper; -class ESI extends AbstractCcp implements EsiInterface { +class Esi extends Ccp\AbstractCcp implements EsiInterface { /** * error message for set waypoint @@ -963,7 +965,7 @@ public function getStatus(string $version = 'last') : array { public function getStatusForRoutes(string $version = 'last') : array { // data for all configured ESI endpoints $statusData = [ - 'status' => Config\ESIConf::getEndpointsData() + 'status' => Config\EsiConf::getEndpointsData() ]; $statusDataAll = $this->getStatus($version); @@ -1044,7 +1046,7 @@ protected function formatUrlParams(array $query = [], array $format = []) : arra * @return string */ protected function getEndpointURI(array $path = [], array $placeholders = []) : string { - $uri = Config\ESIConf::getEndpoint($path, $placeholders); + $uri = Config\EsiConf::getEndpoint($path, $placeholders); // overwrite endpoint version (debug) if( !empty($endpointVersion = $this->getVersion()) ){ diff --git a/app/Client/EsiInterface.php b/app/Client/Ccp/Esi/EsiInterface.php similarity index 99% rename from app/Client/EsiInterface.php rename to app/Client/Ccp/Esi/EsiInterface.php index 8f35888..74ceee9 100644 --- a/app/Client/EsiInterface.php +++ b/app/Client/Ccp/Esi/EsiInterface.php @@ -6,7 +6,7 @@ * Time: 20:27 */ -namespace Exodus4D\ESI\Client; +namespace Exodus4D\ESI\Client\Ccp\Esi; interface EsiInterface { diff --git a/app/Client/SSO.php b/app/Client/Ccp/Sso/Sso.php similarity index 94% rename from app/Client/SSO.php rename to app/Client/Ccp/Sso/Sso.php index 06b6c4b..5c6c459 100644 --- a/app/Client/SSO.php +++ b/app/Client/Ccp/Sso/Sso.php @@ -6,12 +6,12 @@ * Time: 16:21 */ -namespace Exodus4D\ESI\Client; - +namespace Exodus4D\ESI\Client\Ccp\Sso; +use Exodus4D\ESI\Client\Ccp; use Exodus4D\ESI\Mapper; -class SSO extends AbstractCcp implements SsoInterface { +class Sso extends Ccp\AbstractCcp implements SsoInterface { /** * verify character data by "access_token" diff --git a/app/Client/SsoInterface.php b/app/Client/Ccp/Sso/SsoInterface.php similarity index 95% rename from app/Client/SsoInterface.php rename to app/Client/Ccp/Sso/SsoInterface.php index 52e3e39..bce45a6 100644 --- a/app/Client/SsoInterface.php +++ b/app/Client/Ccp/Sso/SsoInterface.php @@ -6,7 +6,7 @@ * Time: 16:23 */ -namespace Exodus4D\ESI\Client; +namespace Exodus4D\ESI\Client\Ccp\Sso; interface SsoInterface { diff --git a/app/Client/EveScout/EveScout.php b/app/Client/EveScout/EveScout.php new file mode 100644 index 0000000..8894d4d --- /dev/null +++ b/app/Client/EveScout/EveScout.php @@ -0,0 +1,18 @@ +request('GET', $uri, $requestOptions)->getContents(); + + return $response; + } +} \ No newline at end of file diff --git a/app/Client/EveScout/EveScoutInterface.php b/app/Client/EveScout/EveScoutInterface.php new file mode 100644 index 0000000..a8a5000 --- /dev/null +++ b/app/Client/EveScout/EveScoutInterface.php @@ -0,0 +1,9 @@ + Date: Sat, 7 Dec 2019 09:26:13 +0100 Subject: [PATCH 02/58] - New "EveScout" API client --- app/Client/Ccp/Esi/Esi.php | 6 +++--- app/Config/Ccp/Esi/EsiConf.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index 5747771..99fb53b 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -10,7 +10,7 @@ use Exodus4D\ESI\Client\Ccp; -use Exodus4D\ESI\Config; +use Exodus4D\ESI\Config\Ccp\Esi\EsiConf; use Exodus4D\ESI\Mapper\Esi as Mapper; class Esi extends Ccp\AbstractCcp implements EsiInterface { @@ -965,7 +965,7 @@ public function getStatus(string $version = 'last') : array { public function getStatusForRoutes(string $version = 'last') : array { // data for all configured ESI endpoints $statusData = [ - 'status' => Config\EsiConf::getEndpointsData() + 'status' => EsiConf::getEndpointsData() ]; $statusDataAll = $this->getStatus($version); @@ -1046,7 +1046,7 @@ protected function formatUrlParams(array $query = [], array $format = []) : arra * @return string */ protected function getEndpointURI(array $path = [], array $placeholders = []) : string { - $uri = Config\EsiConf::getEndpoint($path, $placeholders); + $uri = EsiConf::getEndpoint($path, $placeholders); // overwrite endpoint version (debug) if( !empty($endpointVersion = $this->getVersion()) ){ diff --git a/app/Config/Ccp/Esi/EsiConf.php b/app/Config/Ccp/Esi/EsiConf.php index 5a030a1..700c4f6 100644 --- a/app/Config/Ccp/Esi/EsiConf.php +++ b/app/Config/Ccp/Esi/EsiConf.php @@ -7,7 +7,7 @@ * Time: 20:32 */ -namespace Exodus4D\ESI\Config; +namespace Exodus4D\ESI\Config\Ccp\Esi; class EsiConf extends \Prefab { From 3c938ec7e64c94caf838d0220df8b847e43bbb53 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 10:17:44 +0100 Subject: [PATCH 03/58] - New "EveScout" API client --- app/Client/AbstractApi.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index c07c777..bfe412b 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -136,7 +136,7 @@ abstract class AbstractApi extends \Prefab implements ApiInterface { /** * Debug requests if enabled * @see https://guzzle.readthedocs.io/en/latest/request-options.html#debug - * @var bool + * @var bool|resource */ private $debugRequests = self::DEFAULT_DEBUG_REQUESTS; @@ -365,9 +365,9 @@ public function setVerify(bool $verify){ /** * debug requests - * @param bool $debugRequests + * @param bool|resource $debugRequests */ - public function setDebugRequests(bool $debugRequests = self::DEFAULT_DEBUG_REQUESTS){ + public function setDebugRequests($debugRequests = self::DEFAULT_DEBUG_REQUESTS){ $this->debugRequests = $debugRequests; } @@ -552,7 +552,7 @@ public function getVerify(): bool { } /** - * @return bool + * @return bool|resource */ public function getDebugRequests() : bool { return $this->debugRequests; From 4c19a4d4635f9ce149740e7180655d148cd8b12f Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 10:19:39 +0100 Subject: [PATCH 04/58] - New "EveScout" API client --- app/Client/AbstractApi.php | 2 +- app/Client/ApiInterface.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index bfe412b..ad9bc85 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -554,7 +554,7 @@ public function getVerify(): bool { /** * @return bool|resource */ - public function getDebugRequests() : bool { + public function getDebugRequests(){ return $this->debugRequests; } diff --git a/app/Client/ApiInterface.php b/app/Client/ApiInterface.php index 999dcd4..8be429a 100644 --- a/app/Client/ApiInterface.php +++ b/app/Client/ApiInterface.php @@ -202,9 +202,9 @@ public function getProxy(); public function getVerify() : bool; /** - * @return bool + * @return bool|resource */ - public function getDebugRequests() : bool; + public function getDebugRequests(); /** * @return int From 7f5914f31b20555c0722f1164bd534c20ec0d8fe Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 10:22:46 +0100 Subject: [PATCH 05/58] - New "EveScout" API client --- app/Client/AbstractApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index ad9bc85..703b28c 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -136,7 +136,7 @@ abstract class AbstractApi extends \Prefab implements ApiInterface { /** * Debug requests if enabled * @see https://guzzle.readthedocs.io/en/latest/request-options.html#debug - * @var bool|resource + * @var bool|resource e.g. fopen('php://stderr', 'w') */ private $debugRequests = self::DEFAULT_DEBUG_REQUESTS; From 981ddfbc6b854eb15ccd21fcd62e3076b6306245 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 11:03:59 +0100 Subject: [PATCH 06/58] - New "EveScout" API client --- app/Client/EveScout/EveScout.php | 10 ++++++++++ app/Mapper/EveScout/Connection.php | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 app/Mapper/EveScout/Connection.php diff --git a/app/Client/EveScout/EveScout.php b/app/Client/EveScout/EveScout.php index 8894d4d..7130d58 100644 --- a/app/Client/EveScout/EveScout.php +++ b/app/Client/EveScout/EveScout.php @@ -4,15 +4,25 @@ namespace Exodus4D\ESI\Client\EveScout; use Exodus4D\ESI\Client; +use Exodus4D\ESI\Mapper\EveScout as Mapper; class EveScout extends Client\AbstractApi implements EveScoutInterface { public function getTheraConnections() { $uri = 'https://www.eve-scout.com/api/wormholes'; + $connectionsData = []; $requestOptions = []; $response = $this->request('GET', $uri, $requestOptions)->getContents(); + if($response->error){ + $connectionsData['error'] = $response->error; + }else{ + foreach((array)$response as $data){ + $connectionsData['connections'][(int)$data->id] = (new Mapper\Connection($data))->getData(); + } + } + return $response; } } \ No newline at end of file diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php new file mode 100644 index 0000000..331e6a8 --- /dev/null +++ b/app/Mapper/EveScout/Connection.php @@ -0,0 +1,21 @@ + 'id', + 'type' => 'type', + 'status' => 'status', + 'signatureId' => ['signature' => 'name'], + 'wormholeMass' => ['wormhole' => 'mass'], + 'wormholeEol' => ['wormhole' => 'eol'] + ]; +} \ No newline at end of file From 271c5f113c449fa05e066569f250ab7b7f99dc84 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 11:07:05 +0100 Subject: [PATCH 07/58] - New "EveScout" API client --- app/Mapper/EveScout/Connection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index 331e6a8..768ee0a 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -15,6 +15,7 @@ class Connection extends mapper\AbstractIterator { 'type' => 'type', 'status' => 'status', 'signatureId' => ['signature' => 'name'], + 'wormhole' => 'wormhole', 'wormholeMass' => ['wormhole' => 'mass'], 'wormholeEol' => ['wormhole' => 'eol'] ]; From c2e0f35aba6210171c85a348ffe12df32dee73e5 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 11:08:21 +0100 Subject: [PATCH 08/58] - New "EveScout" API client --- app/Mapper/EveScout/Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index 768ee0a..cf5e016 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -15,7 +15,7 @@ class Connection extends mapper\AbstractIterator { 'type' => 'type', 'status' => 'status', 'signatureId' => ['signature' => 'name'], - 'wormhole' => 'wormhole', + 'wormhole' => [], 'wormholeMass' => ['wormhole' => 'mass'], 'wormholeEol' => ['wormhole' => 'eol'] ]; From 7723ed9871f0037f19c268e905fa3f731ddfe946 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 12:05:08 +0100 Subject: [PATCH 09/58] - New "EveScout" API client --- app/Mapper/EveScout/Connection.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index cf5e016..0957ac2 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -15,8 +15,10 @@ class Connection extends mapper\AbstractIterator { 'type' => 'type', 'status' => 'status', 'signatureId' => ['signature' => 'name'], - 'wormhole' => [], - 'wormholeMass' => ['wormhole' => 'mass'], - 'wormholeEol' => ['wormhole' => 'eol'] + + //'wormholeMass' => 'wormholeMass', + //'wormholeEol' => 'wormholeEol' + 'wormholeMass' => ['wormhole' => 'mass'], + 'wormholeEol' => ['wormhole' => 'eol'], ]; } \ No newline at end of file From f6711746e460bcda417b79d43a302533287dfab6 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 12:19:01 +0100 Subject: [PATCH 10/58] - New "EveScout" API client --- app/Mapper/EveScout/Connection.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index 0957ac2..2fe630c 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -11,14 +11,21 @@ class Connection extends mapper\AbstractIterator { * @var array */ protected static $map = [ - 'id' => 'id', - 'type' => 'type', - 'status' => 'status', - 'signatureId' => ['signature' => 'name'], + 'id' => 'id', + 'type' => 'type', + 'status' => 'status', + //'signatureId' => ['signature' => 'name'], + 'sourceSolarSystem' => 'source', + 'destinationSolarSystem' => 'target', + + 'signatureId' => ['sourceSignature' => 'name'], + 'wormholeDestinationSignatureId' => ['targetSignature' => 'name'], //'wormholeMass' => 'wormholeMass', //'wormholeEol' => 'wormholeEol' - 'wormholeMass' => ['wormhole' => 'mass'], - 'wormholeEol' => ['wormhole' => 'eol'], + 'wormholeMass' => ['wormhole' => 'mass'], + 'wormholeEol' => ['wormhole' => 'eol'], + + ]; } \ No newline at end of file From 34c0e7048e924756f74d8b21c71386d267b02328 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 12:29:50 +0100 Subject: [PATCH 11/58] - New "EveScout" API client --- app/Mapper/EveScout/Connection.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index 2fe630c..bcbbc05 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -16,15 +16,21 @@ class Connection extends mapper\AbstractIterator { 'status' => 'status', //'signatureId' => ['signature' => 'name'], - 'sourceSolarSystem' => 'source', - 'destinationSolarSystem' => 'target', + //'sourceSolarSystem' => 'source', + //'destinationSolarSystem' => 'target', + + 'solarSystemId' => ['source' => 'id'], + 'wormholeDestinationSolarSystemId' => ['target' => 'id'], 'signatureId' => ['sourceSignature' => 'name'], 'wormholeDestinationSignatureId' => ['targetSignature' => 'name'], //'wormholeMass' => 'wormholeMass', //'wormholeEol' => 'wormholeEol' - 'wormholeMass' => ['wormhole' => 'mass'], - 'wormholeEol' => ['wormhole' => 'eol'], + 'wormholeMass' => ['wormhole' => 'mass'], + 'wormholeEol' => ['wormhole' => 'eol'], + + 'createdAt' => ['created' => 'created'], + 'updatedAt' => ['updated' => 'updated'] ]; From d42c0b2c71210e4c21d352aa55722424b8d9b039 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 12:49:57 +0100 Subject: [PATCH 12/58] - New "EveScout" API client --- app/Mapper/EveScout/Connection.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index bcbbc05..dacc4e2 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -23,9 +23,11 @@ class Connection extends mapper\AbstractIterator { 'wormholeDestinationSolarSystemId' => ['target' => 'id'], 'signatureId' => ['sourceSignature' => 'name'], + 'sourceWormholeType' => ['sourceSignature' => 'type'], + 'wormholeDestinationSignatureId' => ['targetSignature' => 'name'], - //'wormholeMass' => 'wormholeMass', - //'wormholeEol' => 'wormholeEol' + 'destinationWormholeType' => ['targetSignature' => 'type'], + 'wormholeMass' => ['wormhole' => 'mass'], 'wormholeEol' => ['wormhole' => 'eol'], From 2f8e08416577740141358c1a278890a2fbde6864 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 12:53:33 +0100 Subject: [PATCH 13/58] - New "EveScout" API client --- app/Client/EveScout/EveScout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Client/EveScout/EveScout.php b/app/Client/EveScout/EveScout.php index 7130d58..02e93f4 100644 --- a/app/Client/EveScout/EveScout.php +++ b/app/Client/EveScout/EveScout.php @@ -23,6 +23,6 @@ public function getTheraConnections() { } } - return $response; + return $connectionsData; } } \ No newline at end of file From e14ad592fb096d2ebc4c53ac70b09306d10d07f0 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 12:58:19 +0100 Subject: [PATCH 14/58] - New "EveScout" API client --- app/Mapper/EveScout/Connection.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index dacc4e2..d11de55 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -13,11 +13,6 @@ class Connection extends mapper\AbstractIterator { protected static $map = [ 'id' => 'id', 'type' => 'type', - 'status' => 'status', - //'signatureId' => ['signature' => 'name'], - - //'sourceSolarSystem' => 'source', - //'destinationSolarSystem' => 'target', 'solarSystemId' => ['source' => 'id'], 'wormholeDestinationSolarSystemId' => ['target' => 'id'], @@ -28,12 +23,13 @@ class Connection extends mapper\AbstractIterator { 'wormholeDestinationSignatureId' => ['targetSignature' => 'name'], 'destinationWormholeType' => ['targetSignature' => 'type'], + 'status' => ['status' => 'name'], + 'statusUpdatedAt' => ['status' => 'updated'], + 'wormholeMass' => ['wormhole' => 'mass'], 'wormholeEol' => ['wormhole' => 'eol'], 'createdAt' => ['created' => 'created'], 'updatedAt' => ['updated' => 'updated'] - - ]; } \ No newline at end of file From 8ef5704380c5daef41d97164bb4bc371123123dd Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 13:02:26 +0100 Subject: [PATCH 15/58] - New "EveScout" API client --- app/Mapper/EveScout/Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index d11de55..24fb479 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -23,7 +23,7 @@ class Connection extends mapper\AbstractIterator { 'wormholeDestinationSignatureId' => ['targetSignature' => 'name'], 'destinationWormholeType' => ['targetSignature' => 'type'], - 'status' => ['status' => 'name'], + 'status' => ['status' => 'namep'], 'statusUpdatedAt' => ['status' => 'updated'], 'wormholeMass' => ['wormhole' => 'mass'], From 58d4999778fd0b72d12ebca9b50dd4324680a9eb Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 13:03:10 +0100 Subject: [PATCH 16/58] - New "EveScout" API client --- app/Mapper/EveScout/Connection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index 24fb479..f7cf740 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -14,6 +14,9 @@ class Connection extends mapper\AbstractIterator { 'id' => 'id', 'type' => 'type', + 'status' => ['status' => 'namep'], + 'statusUpdatedAt' => ['status' => 'updated'], + 'solarSystemId' => ['source' => 'id'], 'wormholeDestinationSolarSystemId' => ['target' => 'id'], @@ -23,9 +26,6 @@ class Connection extends mapper\AbstractIterator { 'wormholeDestinationSignatureId' => ['targetSignature' => 'name'], 'destinationWormholeType' => ['targetSignature' => 'type'], - 'status' => ['status' => 'namep'], - 'statusUpdatedAt' => ['status' => 'updated'], - 'wormholeMass' => ['wormhole' => 'mass'], 'wormholeEol' => ['wormhole' => 'eol'], From 094c8ebd749fec429b313742cd0b704bf3e39920 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 13:04:59 +0100 Subject: [PATCH 17/58] - New "EveScout" API client --- app/Mapper/EveScout/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index f7cf740..d1399c8 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -14,8 +14,8 @@ class Connection extends mapper\AbstractIterator { 'id' => 'id', 'type' => 'type', - 'status' => ['status' => 'namep'], - 'statusUpdatedAt' => ['status' => 'updated'], + 'status' => ['state' => 'name'], + 'statusUpdatedAt' => ['state' => 'updated'], 'solarSystemId' => ['source' => 'id'], 'wormholeDestinationSolarSystemId' => ['target' => 'id'], From ac4c284b2839cb98ff234ae4d078fae305424328 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 16:56:03 +0100 Subject: [PATCH 18/58] - New "EveScout" API client --- app/Client/AbstractApi.php | 13 +++ app/Client/ApiInterface.php | 6 ++ app/Client/Ccp/Esi/Esi.php | 14 ++- app/Client/Ccp/Sso/Sso.php | 9 ++ app/Client/EveScout/EveScout.php | 18 +++- app/Client/GitHub/GitHub.php | 9 ++ app/Config/AbstractConfig.php | 88 +++++++++++++++++++ .../Ccp/Esi/{EsiConf.php => Config.php} | 82 ++--------------- app/Config/Ccp/Sso/Config.php | 15 ++++ app/Config/ConfigInterface.php | 25 ++++++ app/Config/EveScout/Config.php | 19 ++++ app/Config/GitHub/Config.php | 15 ++++ 12 files changed, 230 insertions(+), 83 deletions(-) create mode 100644 app/Config/AbstractConfig.php rename app/Config/Ccp/Esi/{EsiConf.php => Config.php} (67%) create mode 100644 app/Config/Ccp/Sso/Config.php create mode 100644 app/Config/ConfigInterface.php create mode 100644 app/Config/EveScout/Config.php create mode 100644 app/Config/GitHub/Config.php diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index 703b28c..8629e31 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -20,6 +20,7 @@ use Exodus4D\ESI\Lib\Middleware\Cache\Storage\Psr6CacheStorage; use Exodus4D\ESI\Lib\Middleware\Cache\Strategy\CacheStrategyInterface; use Exodus4D\ESI\Lib\Middleware\Cache\Strategy\PrivateCacheStrategy; +use Exodus4D\ESI\Config\ConfigInterface; use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Psr7\Response; use GuzzleHttp\HandlerStack; @@ -176,6 +177,12 @@ abstract class AbstractApi extends \Prefab implements ApiInterface { */ private $isLoggable = null; + /** + * Endpoint config for this API + * @var ConfigInterface + */ + protected $config; + // Guzzle Log Middleware config ----------------------------------------------------------------------------------- /** @@ -810,4 +817,10 @@ protected function request(string $method, string $uri, array $options = []) : ? return $body; } + + /** + * get Config instance for this API + * @return ConfigInterface + */ + abstract protected function getConfig() : ConfigInterface; } \ No newline at end of file diff --git a/app/Client/ApiInterface.php b/app/Client/ApiInterface.php index 8be429a..1a5b8ee 100644 --- a/app/Client/ApiInterface.php +++ b/app/Client/ApiInterface.php @@ -11,6 +11,12 @@ interface ApiInterface { + /** + * ApiInterface constructor. + * @param string $url + */ + public function __construct(string $url); + /** * @param string $url * @return mixed diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index 99fb53b..f03c04b 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -10,7 +10,8 @@ use Exodus4D\ESI\Client\Ccp; -use Exodus4D\ESI\Config\Ccp\Esi\EsiConf; +use Exodus4D\ESI\Config\ConfigInterface; +use Exodus4D\ESI\Config\Ccp\Esi\Config; use Exodus4D\ESI\Mapper\Esi as Mapper; class Esi extends Ccp\AbstractCcp implements EsiInterface { @@ -965,7 +966,7 @@ public function getStatus(string $version = 'last') : array { public function getStatusForRoutes(string $version = 'last') : array { // data for all configured ESI endpoints $statusData = [ - 'status' => EsiConf::getEndpointsData() + 'status' => $this->getConfig()->getEndpointsData() ]; $statusDataAll = $this->getStatus($version); @@ -1046,7 +1047,7 @@ protected function formatUrlParams(array $query = [], array $format = []) : arra * @return string */ protected function getEndpointURI(array $path = [], array $placeholders = []) : string { - $uri = EsiConf::getEndpoint($path, $placeholders); + $uri = $this->getConfig()->getEndpoint($path, $placeholders); // overwrite endpoint version (debug) if( !empty($endpointVersion = $this->getVersion()) ){ @@ -1090,4 +1091,11 @@ protected function getRequestOptions(string $accessToken = '', $content = null, return $options; } + + /** + * @return ConfigInterface + */ + protected function getConfig() : ConfigInterface{ + return ($this->config instanceof ConfigInterface) ? $this->config : $this->config = new Config(); + } } \ No newline at end of file diff --git a/app/Client/Ccp/Sso/Sso.php b/app/Client/Ccp/Sso/Sso.php index 5c6c459..af4de57 100644 --- a/app/Client/Ccp/Sso/Sso.php +++ b/app/Client/Ccp/Sso/Sso.php @@ -9,6 +9,8 @@ namespace Exodus4D\ESI\Client\Ccp\Sso; use Exodus4D\ESI\Client\Ccp; +use Exodus4D\ESI\Config\ConfigInterface; +use Exodus4D\ESI\Config\Ccp\Sso\Config; use Exodus4D\ESI\Mapper; class Sso extends Ccp\AbstractCcp implements SsoInterface { @@ -87,4 +89,11 @@ public function getVerifyUserEndpointURI() : string { public function getVerifyAuthorizationCodeEndpointURI() : string { return '/oauth/token'; } + + /** + * @return ConfigInterface + */ + protected function getConfig() : ConfigInterface{ + return ($this->config instanceof ConfigInterface) ? $this->config : $this->config = new Config(); + } } \ No newline at end of file diff --git a/app/Client/EveScout/EveScout.php b/app/Client/EveScout/EveScout.php index 02e93f4..314af10 100644 --- a/app/Client/EveScout/EveScout.php +++ b/app/Client/EveScout/EveScout.php @@ -4,16 +4,21 @@ namespace Exodus4D\ESI\Client\EveScout; use Exodus4D\ESI\Client; +use Exodus4D\ESI\Config\ConfigInterface; +use Exodus4D\ESI\Config\EveScout\Config; use Exodus4D\ESI\Mapper\EveScout as Mapper; class EveScout extends Client\AbstractApi implements EveScoutInterface { - public function getTheraConnections() { + + public function getTheraConnections() : array { $uri = 'https://www.eve-scout.com/api/wormholes'; + var_dump('11111'); + var_dump($this->getConfig()); + var_dump($this->getConfig()); $connectionsData = []; - $requestOptions = []; - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + $response = $this->request('GET', $uri)->getContents(); if($response->error){ $connectionsData['error'] = $response->error; @@ -25,4 +30,11 @@ public function getTheraConnections() { return $connectionsData; } + + /** + * @return ConfigInterface + */ + protected function getConfig() : ConfigInterface{ + return ($this->config instanceof ConfigInterface) ? $this->config : $this->config = new Config(); + } } \ No newline at end of file diff --git a/app/Client/GitHub/GitHub.php b/app/Client/GitHub/GitHub.php index c7a6ad4..1ab4fad 100644 --- a/app/Client/GitHub/GitHub.php +++ b/app/Client/GitHub/GitHub.php @@ -9,6 +9,8 @@ namespace Exodus4D\ESI\Client\GitHub; use Exodus4D\ESI\Client; +use Exodus4D\ESI\Config\ConfigInterface; +use Exodus4D\ESI\Config\GitHub\Config; use Exodus4D\ESI\Mapper; class GitHub extends Client\AbstractApi implements GitHubInterface { @@ -81,4 +83,11 @@ protected function getReleasesEndpointURI(string $projectName) : string { protected function getMarkdownToHtmlEndpointURI() : string { return '/markdown'; } + + /** + * @return ConfigInterface + */ + protected function getConfig() : ConfigInterface{ + return ($this->config instanceof ConfigInterface) ? $this->config : $this->config = new Config(); + } } \ No newline at end of file diff --git a/app/Config/AbstractConfig.php b/app/Config/AbstractConfig.php new file mode 100644 index 0000000..e3957d5 --- /dev/null +++ b/app/Config/AbstractConfig.php @@ -0,0 +1,88 @@ + return found version + * @param string $endpoint + * @return string|null + */ + protected function stripVersion(string &$endpoint) : ?string { + $version = null; + $endpoint = preg_replace_callback( + '/^\/(v\d{1})\//', + function($matches) use (&$version){ + // set found version and strip it from $endpoint + $version = $matches[1]; + return '/'; + }, + $endpoint, + 1 + ); + + return $version; + } + + /** + * get endpoint data for all configured ESI endpoints + * @return array + */ + public function getEndpointsData() : array { + $endpointsData = []; + $conf = static::$spec; + + array_walk_recursive($conf, function($value, $key) use (&$endpointsData){ + if(is_string($value) && !empty($value)){ + // get version from route and remove it + $version = $this->stripVersion($value); + $endpointsData[] = [ + 'method' => strtolower($key), + 'route' => $value, + 'version' => $version, + 'status' => null + ]; + } + }); + + return $endpointsData; + } + + /** + * @param array $path + * @param array $placeholders + * @return string + */ + public function getEndpoint(array $path, array $placeholders = []) : string { + $endpoint = ''; + $spec = static::$spec; + + foreach($path as $key){ + if(is_array($spec) && array_key_exists($key, $spec)){ + $spec = $spec[$key]; + }else{ + throw new \InvalidArgumentException(sprintf(self::ERROR_UNKNOWN_ENDPOINT, implode('→', $path))); + } + } + + if(is_string($spec)){ + // replace vars + $pattern = '/\{x\}/'; + foreach($placeholders as $placeholder){ + $spec = preg_replace($pattern, $placeholder, $spec, 1); + } + $endpoint = trim($spec); + } + + return $endpoint; + } +} \ No newline at end of file diff --git a/app/Config/Ccp/Esi/EsiConf.php b/app/Config/Ccp/Esi/Config.php similarity index 67% rename from app/Config/Ccp/Esi/EsiConf.php rename to app/Config/Ccp/Esi/Config.php index 700c4f6..03e73df 100644 --- a/app/Config/Ccp/Esi/EsiConf.php +++ b/app/Config/Ccp/Esi/Config.php @@ -9,12 +9,15 @@ namespace Exodus4D\ESI\Config\Ccp\Esi; -class EsiConf extends \Prefab { +use Exodus4D\ESI\Config\AbstractConfig; + + +class Config extends AbstractConfig { /** * Swagger endpoint configuration */ - const SWAGGER_SPEC = [ + protected static $spec = [ 'meta' => [ 'status' => [ 'GET' => '/status.json' @@ -156,79 +159,4 @@ class EsiConf extends \Prefab { 'GET' => '/v2/search/' ] ]; - - /** - * removes version from $endpoint - * -> return found version - * @param string $endpoint - * @return string|null - */ - static function stripVersion(string &$endpoint) : ?string { - $version = null; - $endpoint = preg_replace_callback( - '/^\/(v\d{1})\//', - function($matches) use (&$version){ - // set found version and strip it from $endpoint - $version = $matches[1]; - return '/'; - }, - $endpoint, - 1 - ); - - return $version; - } - - /** - * get endpoint data for all configured ESI endpoints - * @return array - */ - static function getEndpointsData() : array { - $endpointsData = []; - $conf = self::SWAGGER_SPEC; - - array_walk_recursive($conf, function($value, $key) use (&$endpointsData){ - if(is_string($value) && !empty($value)){ - // get version from route and remove it - $version = self::stripVersion($value); - $endpointsData[] = [ - 'method' => strtolower($key), - 'route' => $value, - 'version' => $version, - 'status' => null - ]; - } - }); - - return $endpointsData; - } - - /** - * get an ESI endpoint path - * @param array $path - * @param array $placeholders - * @return string - */ - static function getEndpoint($path = [], $placeholders = []): string{ - $endpoint = ''; - - $tmp = self::SWAGGER_SPEC; - foreach($path as $key){ - if(array_key_exists($key, $tmp)){ - $tmp = $tmp[$key]; - } - } - - if(is_string($tmp)){ - // replace vars - $pattern = '/\{x\}/'; - foreach($placeholders as $placeholder){ - $tmp = preg_replace($pattern, $placeholder, $tmp, 1); - } - - $endpoint = trim($tmp); - } - - return $endpoint; - } } \ No newline at end of file diff --git a/app/Config/Ccp/Sso/Config.php b/app/Config/Ccp/Sso/Config.php new file mode 100644 index 0000000..c540005 --- /dev/null +++ b/app/Config/Ccp/Sso/Config.php @@ -0,0 +1,15 @@ + [ + 'GET' => '/wormholes' + ] + ]; +} \ No newline at end of file diff --git a/app/Config/GitHub/Config.php b/app/Config/GitHub/Config.php new file mode 100644 index 0000000..7339143 --- /dev/null +++ b/app/Config/GitHub/Config.php @@ -0,0 +1,15 @@ + Date: Sat, 7 Dec 2019 16:59:13 +0100 Subject: [PATCH 19/58] - New "EveScout" API client --- app/Client/EveScout/EveScout.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Client/EveScout/EveScout.php b/app/Client/EveScout/EveScout.php index 314af10..44f417d 100644 --- a/app/Client/EveScout/EveScout.php +++ b/app/Client/EveScout/EveScout.php @@ -13,9 +13,10 @@ class EveScout extends Client\AbstractApi implements EveScoutInterface { public function getTheraConnections() : array { $uri = 'https://www.eve-scout.com/api/wormholes'; + $uri2 = $this->getConfig()->getEndpoint(['wormholes', 'GET']);; var_dump('11111'); - var_dump($this->getConfig()); - var_dump($this->getConfig()); + var_dump($uri); + var_dump($uri2); $connectionsData = []; $response = $this->request('GET', $uri)->getContents(); From 0540586d7bc1fe692f60525f4f91a25f3e873ddc Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 17:01:02 +0100 Subject: [PATCH 20/58] - New "EveScout" API client --- app/Client/EveScout/EveScout.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Client/EveScout/EveScout.php b/app/Client/EveScout/EveScout.php index 44f417d..744ab82 100644 --- a/app/Client/EveScout/EveScout.php +++ b/app/Client/EveScout/EveScout.php @@ -12,11 +12,10 @@ class EveScout extends Client\AbstractApi implements EveScoutInterface { public function getTheraConnections() : array { - $uri = 'https://www.eve-scout.com/api/wormholes'; - $uri2 = $this->getConfig()->getEndpoint(['wormholes', 'GET']);; + //$uri = 'https://www.eve-scout.com/api/wormholes'; + $uri = $this->getConfig()->getEndpoint(['wormholes', 'GET']);; var_dump('11111'); var_dump($uri); - var_dump($uri2); $connectionsData = []; $response = $this->request('GET', $uri)->getContents(); From e53df8adeef7be74ffbf8b5885ffced27d868d9f Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 17:09:58 +0100 Subject: [PATCH 21/58] - New "EveScout" API client --- app/Config/EveScout/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Config/EveScout/Config.php b/app/Config/EveScout/Config.php index ccedea3..c431e27 100644 --- a/app/Config/EveScout/Config.php +++ b/app/Config/EveScout/Config.php @@ -13,7 +13,7 @@ class Config extends AbstractConfig { */ protected static $spec = [ 'wormholes' => [ - 'GET' => '/wormholes' + 'GET' => '/api/wormholes' ] ]; } \ No newline at end of file From b8168428ad94130c845ef7029c0f1042ad0b6c7c Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 17:24:45 +0100 Subject: [PATCH 22/58] - New "EveScout" API client --- app/Client/ApiInterface.php | 1 - app/Client/Ccp/Esi/Esi.php | 3 +-- app/Client/Ccp/Esi/EsiInterface.php | 1 - app/Client/Ccp/Sso/Sso.php | 2 +- app/Client/Ccp/Sso/SsoInterface.php | 1 - app/Client/EveScout/EveScout.php | 11 +++++------ app/Client/EveScout/EveScoutInterface.php | 5 ++++- app/Client/GitHub/GitHub.php | 4 ++-- app/Client/GitHub/GitHubInterface.php | 1 - app/Config/AbstractConfig.php | 1 - app/Config/Ccp/Esi/Config.php | 1 - app/Config/Ccp/Sso/Config.php | 1 - app/Config/ConfigInterface.php | 1 - app/Config/EveScout/Config.php | 1 - app/Config/GitHub/Config.php | 7 +++++-- 15 files changed, 18 insertions(+), 23 deletions(-) diff --git a/app/Client/ApiInterface.php b/app/Client/ApiInterface.php index 1a5b8ee..e6caa59 100644 --- a/app/Client/ApiInterface.php +++ b/app/Client/ApiInterface.php @@ -8,7 +8,6 @@ namespace Exodus4D\ESI\Client; - interface ApiInterface { /** diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index f03c04b..646c39c 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -8,7 +8,6 @@ namespace Exodus4D\ESI\Client\Ccp\Esi; - use Exodus4D\ESI\Client\Ccp; use Exodus4D\ESI\Config\ConfigInterface; use Exodus4D\ESI\Config\Ccp\Esi\Config; @@ -1095,7 +1094,7 @@ protected function getRequestOptions(string $accessToken = '', $content = null, /** * @return ConfigInterface */ - protected function getConfig() : ConfigInterface{ + protected function getConfig() : ConfigInterface { return ($this->config instanceof ConfigInterface) ? $this->config : $this->config = new Config(); } } \ No newline at end of file diff --git a/app/Client/Ccp/Esi/EsiInterface.php b/app/Client/Ccp/Esi/EsiInterface.php index 74ceee9..33c987b 100644 --- a/app/Client/Ccp/Esi/EsiInterface.php +++ b/app/Client/Ccp/Esi/EsiInterface.php @@ -8,7 +8,6 @@ namespace Exodus4D\ESI\Client\Ccp\Esi; - interface EsiInterface { /** diff --git a/app/Client/Ccp/Sso/Sso.php b/app/Client/Ccp/Sso/Sso.php index af4de57..a26d08f 100644 --- a/app/Client/Ccp/Sso/Sso.php +++ b/app/Client/Ccp/Sso/Sso.php @@ -93,7 +93,7 @@ public function getVerifyAuthorizationCodeEndpointURI() : string { /** * @return ConfigInterface */ - protected function getConfig() : ConfigInterface{ + protected function getConfig() : ConfigInterface { return ($this->config instanceof ConfigInterface) ? $this->config : $this->config = new Config(); } } \ No newline at end of file diff --git a/app/Client/Ccp/Sso/SsoInterface.php b/app/Client/Ccp/Sso/SsoInterface.php index bce45a6..d464e79 100644 --- a/app/Client/Ccp/Sso/SsoInterface.php +++ b/app/Client/Ccp/Sso/SsoInterface.php @@ -8,7 +8,6 @@ namespace Exodus4D\ESI\Client\Ccp\Sso; - interface SsoInterface { /** diff --git a/app/Client/EveScout/EveScout.php b/app/Client/EveScout/EveScout.php index 744ab82..dd3d078 100644 --- a/app/Client/EveScout/EveScout.php +++ b/app/Client/EveScout/EveScout.php @@ -10,12 +10,11 @@ class EveScout extends Client\AbstractApi implements EveScoutInterface { - + /** + * @return array + */ public function getTheraConnections() : array { - //$uri = 'https://www.eve-scout.com/api/wormholes'; - $uri = $this->getConfig()->getEndpoint(['wormholes', 'GET']);; - var_dump('11111'); - var_dump($uri); + $uri = $this->getConfig()->getEndpoint(['wormholes', 'GET']); $connectionsData = []; $response = $this->request('GET', $uri)->getContents(); @@ -34,7 +33,7 @@ public function getTheraConnections() : array { /** * @return ConfigInterface */ - protected function getConfig() : ConfigInterface{ + protected function getConfig() : ConfigInterface { return ($this->config instanceof ConfigInterface) ? $this->config : $this->config = new Config(); } } \ No newline at end of file diff --git a/app/Client/EveScout/EveScoutInterface.php b/app/Client/EveScout/EveScoutInterface.php index a8a5000..b2440fa 100644 --- a/app/Client/EveScout/EveScoutInterface.php +++ b/app/Client/EveScout/EveScoutInterface.php @@ -3,7 +3,10 @@ namespace Exodus4D\ESI\Client\EveScout; - interface EveScoutInterface { + /** + * @return array + */ + public function getTheraConnections() : array; } \ No newline at end of file diff --git a/app/Client/GitHub/GitHub.php b/app/Client/GitHub/GitHub.php index 1ab4fad..d53d305 100644 --- a/app/Client/GitHub/GitHub.php +++ b/app/Client/GitHub/GitHub.php @@ -21,7 +21,7 @@ class GitHub extends Client\AbstractApi implements GitHubInterface { * @return array */ public function getProjectReleases(string $projectName, int $count = 1) : array { - $uri = $this->getReleasesEndpointURI($projectName); + $uri = $this->getConfig()->getEndpoint(['releases', 'GET'], [$projectName]); $releasesData = []; $requestOptions = [ @@ -87,7 +87,7 @@ protected function getMarkdownToHtmlEndpointURI() : string { /** * @return ConfigInterface */ - protected function getConfig() : ConfigInterface{ + protected function getConfig() : ConfigInterface { return ($this->config instanceof ConfigInterface) ? $this->config : $this->config = new Config(); } } \ No newline at end of file diff --git a/app/Client/GitHub/GitHubInterface.php b/app/Client/GitHub/GitHubInterface.php index 69b1370..7ba0fa2 100644 --- a/app/Client/GitHub/GitHubInterface.php +++ b/app/Client/GitHub/GitHubInterface.php @@ -8,7 +8,6 @@ namespace Exodus4D\ESI\Client\GitHub; - interface GitHubInterface { /** diff --git a/app/Config/AbstractConfig.php b/app/Config/AbstractConfig.php index e3957d5..e58cf91 100644 --- a/app/Config/AbstractConfig.php +++ b/app/Config/AbstractConfig.php @@ -3,7 +3,6 @@ namespace Exodus4D\ESI\Config; - class AbstractConfig implements ConfigInterface { /** diff --git a/app/Config/Ccp/Esi/Config.php b/app/Config/Ccp/Esi/Config.php index 03e73df..6af1c30 100644 --- a/app/Config/Ccp/Esi/Config.php +++ b/app/Config/Ccp/Esi/Config.php @@ -11,7 +11,6 @@ use Exodus4D\ESI\Config\AbstractConfig; - class Config extends AbstractConfig { /** diff --git a/app/Config/Ccp/Sso/Config.php b/app/Config/Ccp/Sso/Config.php index c540005..e78adaf 100644 --- a/app/Config/Ccp/Sso/Config.php +++ b/app/Config/Ccp/Sso/Config.php @@ -3,7 +3,6 @@ namespace Exodus4D\ESI\Config\Ccp\Sso; - use Exodus4D\ESI\Config\AbstractConfig; class Config extends AbstractConfig { diff --git a/app/Config/ConfigInterface.php b/app/Config/ConfigInterface.php index 7022421..25ea7d4 100644 --- a/app/Config/ConfigInterface.php +++ b/app/Config/ConfigInterface.php @@ -3,7 +3,6 @@ namespace Exodus4D\ESI\Config; - interface ConfigInterface { /** diff --git a/app/Config/EveScout/Config.php b/app/Config/EveScout/Config.php index c431e27..bc533b3 100644 --- a/app/Config/EveScout/Config.php +++ b/app/Config/EveScout/Config.php @@ -3,7 +3,6 @@ namespace Exodus4D\ESI\Config\EveScout; - use Exodus4D\ESI\Config\AbstractConfig; class Config extends AbstractConfig { diff --git a/app/Config/GitHub/Config.php b/app/Config/GitHub/Config.php index 7339143..cfcbfef 100644 --- a/app/Config/GitHub/Config.php +++ b/app/Config/GitHub/Config.php @@ -3,7 +3,6 @@ namespace Exodus4D\ESI\Config\GitHub; - use Exodus4D\ESI\Config\AbstractConfig; class Config extends AbstractConfig { @@ -11,5 +10,9 @@ class Config extends AbstractConfig { /** * @var array */ - protected static $spec = []; + protected static $spec = [ + 'releases' => [ + 'GET' => '/repos/{x}/releases' + ] + ]; } \ No newline at end of file From be5173309f89f06108997a426285d837a51bc96a Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 17:30:01 +0100 Subject: [PATCH 23/58] - New "EveScout" API client --- app/Client/GitHub/GitHub.php | 19 ++----------------- app/Config/GitHub/Config.php | 3 +++ 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/app/Client/GitHub/GitHub.php b/app/Client/GitHub/GitHub.php index d53d305..044d135 100644 --- a/app/Client/GitHub/GitHub.php +++ b/app/Client/GitHub/GitHub.php @@ -16,7 +16,7 @@ class GitHub extends Client\AbstractApi implements GitHubInterface { /** - * @param string $projectName + * @param string $projectName e.g. "exodus4d/pathfinder" * @param int $count * @return array */ @@ -48,7 +48,7 @@ public function getProjectReleases(string $projectName, int $count = 1) : array * @return string */ public function markdownToHtml(string $context, string $markdown) : string { - $uri = $this->getMarkdownToHtmlEndpointURI(); + $uri = $this->getConfig()->getEndpoint(['markdown', 'POST']); $html = ''; $requestOptions = [ @@ -69,21 +69,6 @@ public function markdownToHtml(string $context, string $markdown) : string { return $html; } - /** - * @param string $projectName e.g. "exodus4d/pathfinder" - * @return string - */ - protected function getReleasesEndpointURI(string $projectName) : string { - return '/repos/' . $projectName . '/releases'; - } - - /** - * @return string - */ - protected function getMarkdownToHtmlEndpointURI() : string { - return '/markdown'; - } - /** * @return ConfigInterface */ diff --git a/app/Config/GitHub/Config.php b/app/Config/GitHub/Config.php index cfcbfef..0d0b8f9 100644 --- a/app/Config/GitHub/Config.php +++ b/app/Config/GitHub/Config.php @@ -13,6 +13,9 @@ class Config extends AbstractConfig { protected static $spec = [ 'releases' => [ 'GET' => '/repos/{x}/releases' + ], + 'markdown' => [ + 'POST' => '/markdown' ] ]; } \ No newline at end of file From fe7d8a66432abc162436bb871b6f8952aa1bc136 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Dec 2019 19:34:53 +0100 Subject: [PATCH 24/58] - added endpoint "getTheraConnections()" --- app/Mapper/EveScout/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index d1399c8..c8078f6 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -17,8 +17,8 @@ class Connection extends mapper\AbstractIterator { 'status' => ['state' => 'name'], 'statusUpdatedAt' => ['state' => 'updated'], - 'solarSystemId' => ['source' => 'id'], - 'wormholeDestinationSolarSystemId' => ['target' => 'id'], + 'sourceSolarSystem' => 'source', + 'destinationSolarSystem' => 'target', 'signatureId' => ['sourceSignature' => 'name'], 'sourceWormholeType' => ['sourceSignature' => 'type'], From 357905c305521bf0e7eefc9dc617ec2423140603 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 9 Dec 2019 22:28:00 +0100 Subject: [PATCH 25/58] - Upgraded Composer dependencies --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 869c84c..6da213f 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,8 @@ }, "require": { "php-64bit": ">=7.1", - "guzzlehttp/guzzle": "6.3.*", - "caseyamcl/guzzle_retry_middleware": "2.2.*", + "guzzlehttp/guzzle": "6.5.*", + "caseyamcl/guzzle_retry_middleware": "2.3.*", "cache/void-adapter": "1.0.*" } } \ No newline at end of file From 34284ebc0fe8393b56e160375172c5b26b04e491 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Fri, 13 Dec 2019 09:23:55 +0100 Subject: [PATCH 26/58] - Compatibility changes for _PHP_ `v7.4` --- app/Config/AbstractConfig.php | 2 +- app/Mapper/Esi/Status.php | 2 +- composer.json | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Config/AbstractConfig.php b/app/Config/AbstractConfig.php index e58cf91..e301b08 100644 --- a/app/Config/AbstractConfig.php +++ b/app/Config/AbstractConfig.php @@ -19,7 +19,7 @@ class AbstractConfig implements ConfigInterface { protected function stripVersion(string &$endpoint) : ?string { $version = null; $endpoint = preg_replace_callback( - '/^\/(v\d{1})\//', + '/^\/(v\d)\//', function($matches) use (&$version){ // set found version and strip it from $endpoint $version = $matches[1]; diff --git a/app/Mapper/Esi/Status.php b/app/Mapper/Esi/Status.php index dd48776..7395431 100644 --- a/app/Mapper/Esi/Status.php +++ b/app/Mapper/Esi/Status.php @@ -30,7 +30,7 @@ class Status extends mapper\AbstractIterator { public function getData(){ $normalize = function(\Iterator $iterator){ - return preg_replace('/\/\{(\w+)\}/', '/{x}', $iterator->current()); + return preg_replace('/\/{(\w+)}/', '/{x}', $iterator->current()); }; self::$map['route'] = $normalize; diff --git a/composer.json b/composer.json index 6da213f..48105d0 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ }, "require": { "php-64bit": ">=7.1", + "ext-json": "*", "guzzlehttp/guzzle": "6.5.*", "caseyamcl/guzzle_retry_middleware": "2.3.*", "cache/void-adapter": "1.0.*" From 4f6cf5665a1d6838e9113a71c934fb57e03bd9c0 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Fri, 13 Dec 2019 12:27:10 +0100 Subject: [PATCH 27/58] =?UTF-8?q?-=20Increased=20required=20PHP=20version?= =?UTF-8?q?=20`v7.1`=20=E2=86=92=20`v7.2`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 48105d0..37325a7 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ } }, "require": { - "php-64bit": ">=7.1", + "php-64bit": ">=7.2", "ext-json": "*", "guzzlehttp/guzzle": "6.5.*", "caseyamcl/guzzle_retry_middleware": "2.3.*", From 57f36a03f79f22bebf3757030c930d0b1a6e2e48 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 14 Dec 2019 14:29:08 +0100 Subject: [PATCH 28/58] - Improved `composer.json` config --- composer.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/composer.json b/composer.json index 37325a7..9c3d43f 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,8 @@ { "name": "exodus4d/pathfinder_esi", "description": "ESI API library for Pathfinder", + "type": "library", + "homepage": "https://github.com/exodus4d/pathfinder_esi", "minimum-stability": "stable", "license": "MIT", "authors": [ @@ -9,6 +11,10 @@ "email": "pathfinder@exodus4d.de" } ], + "config": { + "optimize-autoloader": true, + "lock": false + }, "repositories": [ { "type": "vcs", From f8c70818cdb6999bfce463f13a4fa6dddc0ef1cc Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sun, 15 Dec 2019 13:22:52 +0100 Subject: [PATCH 29/58] - Refactoring for Class names --- app/Mapper/Esi/Alliance/Alliance.php | 4 ++-- app/Mapper/Esi/Character/Affiliation.php | 4 ++-- app/Mapper/Esi/Character/Character.php | 4 ++-- app/Mapper/Esi/Character/CharacterClone.php | 4 ++-- app/Mapper/Esi/Character/Location.php | 4 ++-- app/Mapper/Esi/Character/Online.php | 4 ++-- app/Mapper/Esi/Character/Ship.php | 4 ++-- app/Mapper/Esi/Corporation/Corporation.php | 4 ++-- app/Mapper/Esi/Dogma/Attribute.php | 4 ++-- app/Mapper/Esi/FactionWarfare/System.php | 4 ++-- app/Mapper/Esi/InventoryType.php | 4 ++-- app/Mapper/Esi/Search/Search.php | 4 ++-- app/Mapper/Esi/Sovereignty/Map.php | 4 ++-- app/Mapper/Esi/Status.php | 4 ++-- app/Mapper/Esi/Status/Status.php | 4 ++-- app/Mapper/Esi/Universe/Category.php | 4 ++-- app/Mapper/Esi/Universe/Constellation.php | 4 ++-- app/Mapper/Esi/Universe/Faction.php | 4 ++-- app/Mapper/Esi/Universe/Group.php | 4 ++-- app/Mapper/Esi/Universe/Planet.php | 4 ++-- app/Mapper/Esi/Universe/Race.php | 4 ++-- app/Mapper/Esi/Universe/Region.php | 4 ++-- app/Mapper/Esi/Universe/Star.php | 4 ++-- app/Mapper/Esi/Universe/Stargate.php | 4 ++-- app/Mapper/Esi/Universe/Station.php | 4 ++-- app/Mapper/Esi/Universe/Structure.php | 4 ++-- app/Mapper/Esi/Universe/System.php | 4 ++-- app/Mapper/Esi/Universe/Type.php | 4 ++-- app/Mapper/EveScout/Connection.php | 4 ++-- app/Mapper/GitHub/Release.php | 4 ++-- app/Mapper/Sso/Access.php | 4 ++-- app/Mapper/Sso/Character.php | 4 ++-- 32 files changed, 64 insertions(+), 64 deletions(-) diff --git a/app/Mapper/Esi/Alliance/Alliance.php b/app/Mapper/Esi/Alliance/Alliance.php index b4ddf72..569dd03 100644 --- a/app/Mapper/Esi/Alliance/Alliance.php +++ b/app/Mapper/Esi/Alliance/Alliance.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Alliance; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Alliance extends mapper\AbstractIterator { +class Alliance extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Character/Affiliation.php b/app/Mapper/Esi/Character/Affiliation.php index 3c6b98b..ff9e00d 100644 --- a/app/Mapper/Esi/Character/Affiliation.php +++ b/app/Mapper/Esi/Character/Affiliation.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Character; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Affiliation extends mapper\AbstractIterator { +class Affiliation extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Character/Character.php b/app/Mapper/Esi/Character/Character.php index 373d56a..9cd2335 100644 --- a/app/Mapper/Esi/Character/Character.php +++ b/app/Mapper/Esi/Character/Character.php @@ -9,9 +9,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Character; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Character extends mapper\AbstractIterator { +class Character extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Character/CharacterClone.php b/app/Mapper/Esi/Character/CharacterClone.php index 778ae29..bbe5800 100644 --- a/app/Mapper/Esi/Character/CharacterClone.php +++ b/app/Mapper/Esi/Character/CharacterClone.php @@ -3,9 +3,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Character; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class CharacterClone extends mapper\AbstractIterator { +class CharacterClone extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Character/Location.php b/app/Mapper/Esi/Character/Location.php index ecb97cf..a5f9656 100644 --- a/app/Mapper/Esi/Character/Location.php +++ b/app/Mapper/Esi/Character/Location.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Character; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Location extends mapper\AbstractIterator { +class Location extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Character/Online.php b/app/Mapper/Esi/Character/Online.php index 06ea78c..5872c50 100644 --- a/app/Mapper/Esi/Character/Online.php +++ b/app/Mapper/Esi/Character/Online.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Character; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Online extends mapper\AbstractIterator { +class Online extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Character/Ship.php b/app/Mapper/Esi/Character/Ship.php index eec8dc3..bafd9f0 100644 --- a/app/Mapper/Esi/Character/Ship.php +++ b/app/Mapper/Esi/Character/Ship.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Character; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Ship extends mapper\AbstractIterator { +class Ship extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Corporation/Corporation.php b/app/Mapper/Esi/Corporation/Corporation.php index 533ed2d..2d970f2 100644 --- a/app/Mapper/Esi/Corporation/Corporation.php +++ b/app/Mapper/Esi/Corporation/Corporation.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Corporation; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Corporation extends mapper\AbstractIterator { +class Corporation extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Dogma/Attribute.php b/app/Mapper/Esi/Dogma/Attribute.php index 93a99dc..199b13e 100644 --- a/app/Mapper/Esi/Dogma/Attribute.php +++ b/app/Mapper/Esi/Dogma/Attribute.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Dogma; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Attribute extends mapper\AbstractIterator { +class Attribute extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/FactionWarfare/System.php b/app/Mapper/Esi/FactionWarfare/System.php index 9595718..f635185 100644 --- a/app/Mapper/Esi/FactionWarfare/System.php +++ b/app/Mapper/Esi/FactionWarfare/System.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\FactionWarfare; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class System extends mapper\AbstractIterator { +class System extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/InventoryType.php b/app/Mapper/Esi/InventoryType.php index c7cebc2..3850c51 100644 --- a/app/Mapper/Esi/InventoryType.php +++ b/app/Mapper/Esi/InventoryType.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class InventoryType extends mapper\AbstractIterator { +class InventoryType extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Search/Search.php b/app/Mapper/Esi/Search/Search.php index 5d37018..3345209 100644 --- a/app/Mapper/Esi/Search/Search.php +++ b/app/Mapper/Esi/Search/Search.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Search; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Search extends mapper\AbstractIterator { +class Search extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Sovereignty/Map.php b/app/Mapper/Esi/Sovereignty/Map.php index ddb19b5..51cf4d4 100644 --- a/app/Mapper/Esi/Sovereignty/Map.php +++ b/app/Mapper/Esi/Sovereignty/Map.php @@ -3,9 +3,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Sovereignty; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Map extends mapper\AbstractIterator { +class Map extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Status.php b/app/Mapper/Esi/Status.php index 7395431..f2785ed 100644 --- a/app/Mapper/Esi/Status.php +++ b/app/Mapper/Esi/Status.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Status extends mapper\AbstractIterator { +class Status extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Status/Status.php b/app/Mapper/Esi/Status/Status.php index f97a0f4..cd1b797 100644 --- a/app/Mapper/Esi/Status/Status.php +++ b/app/Mapper/Esi/Status/Status.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Status; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Status extends mapper\AbstractIterator { +class Status extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Category.php b/app/Mapper/Esi/Universe/Category.php index d79dbc8..c73ecab 100644 --- a/app/Mapper/Esi/Universe/Category.php +++ b/app/Mapper/Esi/Universe/Category.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Category extends mapper\AbstractIterator { +class Category extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Constellation.php b/app/Mapper/Esi/Universe/Constellation.php index f700a0e..9a9e372 100644 --- a/app/Mapper/Esi/Universe/Constellation.php +++ b/app/Mapper/Esi/Universe/Constellation.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Constellation extends mapper\AbstractIterator { +class Constellation extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Faction.php b/app/Mapper/Esi/Universe/Faction.php index 03180e1..d478fae 100644 --- a/app/Mapper/Esi/Universe/Faction.php +++ b/app/Mapper/Esi/Universe/Faction.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Faction extends mapper\AbstractIterator { +class Faction extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Group.php b/app/Mapper/Esi/Universe/Group.php index 17d186d..9fd9181 100644 --- a/app/Mapper/Esi/Universe/Group.php +++ b/app/Mapper/Esi/Universe/Group.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Group extends mapper\AbstractIterator { +class Group extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Planet.php b/app/Mapper/Esi/Universe/Planet.php index 63d56e4..69cc389 100644 --- a/app/Mapper/Esi/Universe/Planet.php +++ b/app/Mapper/Esi/Universe/Planet.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Planet extends mapper\AbstractIterator { +class Planet extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Race.php b/app/Mapper/Esi/Universe/Race.php index f20310d..21a95f5 100644 --- a/app/Mapper/Esi/Universe/Race.php +++ b/app/Mapper/Esi/Universe/Race.php @@ -3,9 +3,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Race extends mapper\AbstractIterator { +class Race extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Region.php b/app/Mapper/Esi/Universe/Region.php index af97bb3..f793820 100644 --- a/app/Mapper/Esi/Universe/Region.php +++ b/app/Mapper/Esi/Universe/Region.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Region extends mapper\AbstractIterator { +class Region extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Star.php b/app/Mapper/Esi/Universe/Star.php index 0c2182d..3ff5c6f 100644 --- a/app/Mapper/Esi/Universe/Star.php +++ b/app/Mapper/Esi/Universe/Star.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Star extends mapper\AbstractIterator { +class Star extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Stargate.php b/app/Mapper/Esi/Universe/Stargate.php index ec190f6..1f59a7b 100644 --- a/app/Mapper/Esi/Universe/Stargate.php +++ b/app/Mapper/Esi/Universe/Stargate.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Stargate extends mapper\AbstractIterator { +class Stargate extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Station.php b/app/Mapper/Esi/Universe/Station.php index 2a42fbe..965ca48 100644 --- a/app/Mapper/Esi/Universe/Station.php +++ b/app/Mapper/Esi/Universe/Station.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Station extends mapper\AbstractIterator { +class Station extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Structure.php b/app/Mapper/Esi/Universe/Structure.php index b7cb727..d4461fe 100644 --- a/app/Mapper/Esi/Universe/Structure.php +++ b/app/Mapper/Esi/Universe/Structure.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Structure extends mapper\AbstractIterator { +class Structure extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/System.php b/app/Mapper/Esi/Universe/System.php index ed779f3..50a5db9 100644 --- a/app/Mapper/Esi/Universe/System.php +++ b/app/Mapper/Esi/Universe/System.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class System extends mapper\AbstractIterator { +class System extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Esi/Universe/Type.php b/app/Mapper/Esi/Universe/Type.php index 405ca8d..01b61f7 100644 --- a/app/Mapper/Esi/Universe/Type.php +++ b/app/Mapper/Esi/Universe/Type.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Esi\Universe; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Type extends mapper\AbstractIterator { +class Type extends AbstractIterator { /** * @var array diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index c8078f6..ab12e52 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -3,9 +3,9 @@ namespace Exodus4D\ESI\Mapper\EveScout; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Connection extends mapper\AbstractIterator { +class Connection extends AbstractIterator { /** * @var array diff --git a/app/Mapper/GitHub/Release.php b/app/Mapper/GitHub/Release.php index 296db4c..d315599 100644 --- a/app/Mapper/GitHub/Release.php +++ b/app/Mapper/GitHub/Release.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\GitHub; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Release extends mapper\AbstractIterator { +class Release extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Sso/Access.php b/app/Mapper/Sso/Access.php index 4830332..34f67ee 100644 --- a/app/Mapper/Sso/Access.php +++ b/app/Mapper/Sso/Access.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Sso; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Access extends mapper\AbstractIterator { +class Access extends AbstractIterator { /** * @var array diff --git a/app/Mapper/Sso/Character.php b/app/Mapper/Sso/Character.php index 2d1e46f..efa1630 100644 --- a/app/Mapper/Sso/Character.php +++ b/app/Mapper/Sso/Character.php @@ -8,9 +8,9 @@ namespace Exodus4D\ESI\Mapper\Sso; -use data\mapper; +use Exodus4D\Pathfinder\Data\Mapper\AbstractIterator; -class Character extends mapper\AbstractIterator { +class Character extends AbstractIterator { /** * @var array From 919f798299cf969362f69e24c5d46ca237e05048 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sun, 2 Feb 2020 23:51:10 +0100 Subject: [PATCH 30/58] - New "batch" request (parallel async) --- app/Client/AbstractApi.php | 114 +++++++++++++++++++++++++++++-------- app/Client/Ccp/Esi/Esi.php | 39 +++++++++++++ app/Lib/WebClient.php | 76 +++++++++++++++++-------- 3 files changed, 180 insertions(+), 49 deletions(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index 8629e31..3da8b6f 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -768,25 +768,6 @@ protected function getRetryMiddlewareConfig() : array { ]; } - /** - * same as PHP´s array_merge_recursive() function except of "distinct" array values in return - * -> works like jQuery extend() - * @param array $array1 - * @param array $array2 - * @return array - */ - protected static function array_merge_recursive_distinct(array &$array1, array &$array2) : array { - $merged = $array1; - foreach($array2 as $key => &$value){ - if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])){ - $merged[$key] = self::array_merge_recursive_distinct($merged[$key], $value); - }else{ - $merged[$key] = $value; - } - } - return $merged; - } - /** * @param string $method * @param string $uri @@ -797,10 +778,7 @@ protected function request(string $method, string $uri, array $options = []) : ? $body = null; try{ - $request = $this->getClient()->newRequest($method, $uri); - /** - * @var $response Response - */ + $request = WebClient::newRequest($method, $uri); $response = $this->getClient()->send($request, $options); $body = $response->getBody(); }catch(TransferException $e){ @@ -808,16 +786,102 @@ protected function request(string $method, string $uri, array $options = []) : ? // -> this includes "expected" errors like 4xx responses (ClientException) // and "unexpected" errors like cURL fails (ConnectException)... // -> error is already logged by LogMiddleware - $body = $this->getClient()->newErrorResponse($e, $this->getAcceptType())->getBody(); + $body = WebClient::newErrorResponse($e, $this->getAcceptType())->getBody(); }catch(\Exception $e){ // Hard fail! Any other type of error // -> e.g. RuntimeException,... - $body = $this->getClient()->newErrorResponse($e, $this->getAcceptType())->getBody(); + $body = WebClient::newErrorResponse($e, $this->getAcceptType())->getBody(); } return $body; } + public function send(callable $requestHandler, ...$handlerParams){ + $config = $requestHandler(...$handlerParams); + + $response = $this->getClient()->send($config->request, $config->options); + } + + public function sendAsync(callable $requestHandler, ...$handlerParams){ + + } + + /** + * @param array $requestsConfig + * @return array + */ + public function sendBatch(array $requestsConfig) : array { + + $requestsConfig = array_map(function(array $config){ + return array_shift($config)(...$config); + }, $requestsConfig); + + /* + $batchRequests = [ + (object)[ + 'request' => WebClient::newRequest('GET', 'abc'), + 'options' => [], + 'formatter' => function(JsonStreamInterface $body){ + return $body; + }] + ];*/ + + // must be 'Traversable of Promises'. + // So we’ll create a generator method which will only start the async request when the promise is grabbed + $requests = (function() use ($requestsConfig) { + foreach($requestsConfig as $config){ + // don't forget using generator + yield $this->getClient()->sendAsync($config->request, $config->options); + } + })(); + + // run requests async (parallel) + // -> but wait()´s until all requests are either "fulfilled" or "rejected" + $results = $this->getClient()->runBatch($requests, [ + 'concurrency' => 2 + ]); + + return array_map(function($result, $key) use ($requestsConfig) { + // check result for valid responses + // -> wrap rejected requests into errorResponses + if($result instanceof Response){ + $response = $result; + }elseif($result instanceof \Exception){ + $response = WebClient::newErrorResponse($result, $this->getAcceptType()); + }else{ + // invalid result type. Hard fail! + $response = WebClient::newErrorResponse( + new \InvalidArgumentException('Invalid result type: ' . gettype($result)), + $this->getAcceptType() + ); + } + + $body = $response->getBody(); + + // call custom formatter for current $result (same $key) + return is_callable($formatter = $requestsConfig[$key]->formatter) ? $formatter($body) : $body; + }, $results, array_keys($results)); + } + + /** + * same as PHP´s array_merge_recursive() function except of "distinct" array values in return + * -> works like jQuery extend() + * @param array $array1 + * @param array $array2 + * @return array + */ + protected static function array_merge_recursive_distinct(array &$array1, array &$array2) : array { + $merged = $array1; + foreach($array2 as $key => &$value){ + if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])){ + $merged[$key] = self::array_merge_recursive_distinct($merged[$key], $value); + }else{ + $merged[$key] = $value; + } + } + return $merged; + } + /** * get Config instance for this API * @return ConfigInterface diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index 646c39c..72690fc 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -11,6 +11,8 @@ use Exodus4D\ESI\Client\Ccp; use Exodus4D\ESI\Config\ConfigInterface; use Exodus4D\ESI\Config\Ccp\Esi\Config; +use Exodus4D\ESI\Lib\WebClient; +use Exodus4D\ESI\Lib\Stream\JsonStreamInterface; use Exodus4D\ESI\Mapper\Esi as Mapper; class Esi extends Ccp\AbstractCcp implements EsiInterface { @@ -827,6 +829,43 @@ public function getRouteData(int $sourceId, int $targetId, array $options = []) return $routeData; } + public function getRouteRequest(int $sourceId, int $targetId, array $options = []){ + $query = []; + if( !empty($options['avoid']) ){ + $query['avoid'] = $options['avoid']; + } + if( !empty($options['connections']) ){ + $query['connections'] = $options['connections']; + } + if( !empty($options['flag']) ){ + $query['flag'] = $options['flag']; + } + + $query = $this->formatUrlParams($query, [ + 'connections' => [',', '|'], + 'avoid' => [','] + ]); + + $requestOptions = $this->getRequestOptions('', null, $query); + + // 404 'No route found' error -> should not be logged + $requestOptions['log_off_status'] = [404]; + + return (object)[ + 'request' => WebClient::newRequest('GET', $this->getEndpointURI(['routes', 'GET'], [$sourceId, $targetId])), + 'options' => $requestOptions, + 'formatter' => function(JsonStreamInterface $body) : array { + $routeData = []; + if(!$body->error){ + $routeData['route'] = array_unique(array_map('intval', (array)$body)); + }else{ + $routeData['error'] = $body->error; + } + return $routeData; + } + ]; + } + /** * @param int $destinationId * @param string $accessToken diff --git a/app/Lib/WebClient.php b/app/Lib/WebClient.php index 55c4c95..3034962 100644 --- a/app/Lib/WebClient.php +++ b/app/Lib/WebClient.php @@ -18,14 +18,18 @@ use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\ServerException; +use GuzzleHttp\Pool; +use GuzzleHttp\Promise; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; /** * Class WebClient * @package Exodus4D\ESI\Lib - * @method Client send(RequestInterface $request, array $options = []) + * @method ResponseInterface send(RequestInterface $request, array $options = []) + * @method Promise\PromiseInterface sendAsync(RequestInterface $request, array $options = []) */ class WebClient { @@ -59,12 +63,54 @@ public function __construct(string $baseUri, array $config = [], ?\Closure $init $this->client = new Client($config); } + /** + * @param array|\Iterator $requests Requests or functions that return + * requests to send concurrently. + * @param array $config Passes through the options available in + * {@see Pool::__construct} + * @return Pool + */ + public function newPool(iterable $requests, array $config = []) : Pool { + return new Pool($this->client, $requests, $config); + } + + /** + * @param array|\Iterator $requests Requests or functions that return + * requests to send concurrently. + * @param array $config Passes through the options available in + * {@see Pool::__construct} + * @return array Returns an array containing the response or an exception + * in the same order that the requests were sent. + */ + public function runBatch(iterable $requests, array $config = []) : array { + return Pool::batch($this->client, $requests, $config); + } + + /** + * pipe undefined method calls right into the Client + * @param string $name + * @param array $arguments + * @return array|mixed + */ + public function __call(string $name, array $arguments = []){ + $return = []; + + if(is_object($this->client)){ + if(method_exists($this->client, $name)){ + $return = call_user_func_array([$this->client, $name], $arguments); + } + } + + return $return; + } + + /** * @param string $method * @param string $uri * @return Request */ - public function newRequest(string $method, string $uri) : Request { + public static function newRequest(string $method, string $uri) : Request { return new Request($method, $uri); } @@ -77,20 +123,20 @@ public function newRequest(string $method, string $uri) : Request { * @param string|null $reason * @return Response */ - public function newResponse(int $status = 200, array $headers = [], $body = null, string $version = '1.1', ?string $reason = null) : Response { + public static function newResponse(int $status = 200, array $headers = [], $body = null, string $version = '1.1', ?string $reason = null) : Response { return new Response($status, $headers, $body, $version, $reason); } /** * get error response with error message in body * -> wraps a GuzzleException (or any other Exception) into an error response - * -> this class should handle any Exception thrown within Guzzle Context + * -> handles any Exception thrown within Guzzle Context * @see http://docs.guzzlephp.org/en/stable/quickstart.html#exceptions * @param \Exception $e * @param bool $json * @return Response */ - public function newErrorResponse(\Exception $e, bool $json = true) : Response { + public static function newErrorResponse(\Exception $e, bool $json = true) : Response { $message = [get_class($e)]; if($e instanceof ConnectException){ @@ -122,28 +168,10 @@ public function newErrorResponse(\Exception $e, bool $json = true) : Response { $bodyStream = new JsonStream($bodyStream); } - $response = $this->newResponse(); + $response = static::newResponse(); $response = $response->withStatus(200, 'Error Response'); $response = $response->withBody($bodyStream); return $response; } - - /** - * pipe all functions right into the Client - * @param string $name - * @param array $arguments - * @return array|mixed - */ - public function __call(string $name, array $arguments = []){ - $return = []; - - if(is_object($this->client)){ - if( method_exists($this->client, $name) ){ - $return = call_user_func_array([$this->client, $name], $arguments); - } - } - - return $return; - } } \ No newline at end of file From 2511258ef94c72f6b21bb7727eebdafd46f7c2e1 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 3 Feb 2020 00:42:56 +0100 Subject: [PATCH 31/58] - New "batch" request (parallel async) --- app/Client/AbstractApi.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index 3da8b6f..3156214 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -813,7 +813,11 @@ public function sendAsync(callable $requestHandler, ...$handlerParams){ public function sendBatch(array $requestsConfig) : array { $requestsConfig = array_map(function(array $config){ - return array_shift($config)(...$config); + if(is_callable([$this, $requestHandler = array_shift($config)])){ + // return $requestHandler(...$config); + return call_user_func_array([$this, $requestHandler], $config); + } + return null; }, $requestsConfig); /* From d09c295e96a5e6de1792245e335c7c45ad53b090 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 3 Feb 2020 17:40:15 +0100 Subject: [PATCH 32/58] - New "batch" request (parallel async) --- app/Client/AbstractApi.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index 3156214..36e72be 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -835,7 +835,10 @@ public function sendBatch(array $requestsConfig) : array { $requests = (function() use ($requestsConfig) { foreach($requestsConfig as $config){ // don't forget using generator - yield $this->getClient()->sendAsync($config->request, $config->options); + //yield $this->getClient()->sendAsync($config->request, $config->options); + yield function() use ($config) { + return $this->getClient()->sendAsync($config->request, $config->options); + }; } })(); From 910ecb4460571e597af81c2be833997d099ca901 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 3 Feb 2020 17:43:54 +0100 Subject: [PATCH 33/58] - New "batch" request (parallel async) --- app/Client/Ccp/Esi/Esi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index 72690fc..65eca91 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -854,7 +854,7 @@ public function getRouteRequest(int $sourceId, int $targetId, array $options = [ return (object)[ 'request' => WebClient::newRequest('GET', $this->getEndpointURI(['routes', 'GET'], [$sourceId, $targetId])), 'options' => $requestOptions, - 'formatter' => function(JsonStreamInterface $body) : array { + 'formatter' => function($body) : array { $routeData = []; if(!$body->error){ $routeData['route'] = array_unique(array_map('intval', (array)$body)); From 272e2e57fbc1f32accbf593d82fc07f1cbf0e0e8 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 3 Feb 2020 18:18:51 +0100 Subject: [PATCH 34/58] - New "batch" request (parallel async) --- app/Client/AbstractApi.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index 36e72be..d954bcd 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -864,9 +864,10 @@ public function sendBatch(array $requestsConfig) : array { } $body = $response->getBody(); + $bodyContent = $body->getContents(); // call custom formatter for current $result (same $key) - return is_callable($formatter = $requestsConfig[$key]->formatter) ? $formatter($body) : $body; + return is_callable($formatter = $requestsConfig[$key]->formatter) ? $formatter($bodyContent) : $bodyContent; }, $results, array_keys($results)); } From 6379575d722046d9c4b32951f9c008471d545302 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 3 Feb 2020 18:35:49 +0100 Subject: [PATCH 35/58] - New "batch" request (parallel async) --- app/Client/AbstractApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index d954bcd..d1e1885 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -845,7 +845,7 @@ public function sendBatch(array $requestsConfig) : array { // run requests async (parallel) // -> but wait()´s until all requests are either "fulfilled" or "rejected" $results = $this->getClient()->runBatch($requests, [ - 'concurrency' => 2 + 'concurrency' => 5 ]); return array_map(function($result, $key) use ($requestsConfig) { From cc324be8d769ffe5a6c2732eb321d825d9cb93fb Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 3 Feb 2020 22:08:44 +0100 Subject: [PATCH 36/58] - New "batch" request (parallel async) --- app/Client/AbstractApi.php | 98 ++++++++++++++++++++++++++------------ app/Client/Ccp/Esi/Esi.php | 15 +++--- app/Lib/RequestConfig.php | 93 ++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 37 deletions(-) create mode 100644 app/Lib/RequestConfig.php diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index d1e1885..8c74bfa 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -11,6 +11,7 @@ use lib\logging\LogInterface; use Exodus4D\ESI\Lib\WebClient; +use Exodus4D\ESI\Lib\RequestConfig; use Exodus4D\ESI\Lib\Stream\JsonStreamInterface; use Exodus4D\ESI\Lib\Middleware\GuzzleJsonMiddleware; use Exodus4D\ESI\Lib\Middleware\GuzzleLogMiddleware; @@ -49,6 +50,11 @@ abstract class AbstractApi extends \Prefab implements ApiInterface { */ const DEFAULT_READ_TIMEOUT = 10.0; + /** + * default for: max count of parallel requests (batch request) + */ + const DEFAULT_BATCH_CONCURRENCY = 5; + /** * default for: auto decode responses with encoded body * -> checks "Content-Encoding" response HTTP Header for 'gzip' or 'deflate' value @@ -66,6 +72,12 @@ abstract class AbstractApi extends \Prefab implements ApiInterface { */ const DEFAULT_DEBUG_LEVEL = 0; + /** + * error message for invalid request config + * -> e.g. method name not callable + */ + const ERROR_INVALID_REQUEST_CONFIG = 'Invalid request config'; + // ================================================================================================================ // API class properties // ================================================================================================================ @@ -110,6 +122,12 @@ abstract class AbstractApi extends \Prefab implements ApiInterface { */ private $readTimeout = self::DEFAULT_READ_TIMEOUT; + /** + * Max count of parallel requests (batch request) + * @var int + */ + private $batchConcurrency = self::DEFAULT_BATCH_CONCURRENCY; + /** * decode response body * @see http://docs.guzzlephp.org/en/stable/request-options.html#decode-content @@ -342,6 +360,13 @@ public function setConnectTimeout(float $connectTimeout = self::DEFAULT_CONNECT_ $this->connectTimeout = $connectTimeout; } + /** + * @param int $batchConcurrency + */ + public function setBatchConcurrency(int $batchConcurrency = self::DEFAULT_BATCH_CONCURRENCY){ + $this->batchConcurrency = $batchConcurrency; + } + /** * @param float $readTimeout */ @@ -537,6 +562,13 @@ public function getReadTimeout() : float { return $this->readTimeout; } + /** + * @return int + */ + public function getBatchConcurrency() : int { + return $this->batchConcurrency; + } + /** * @return array|bool|string */ @@ -768,6 +800,18 @@ protected function getRetryMiddlewareConfig() : array { ]; } + /** + * get config for API request call from config + * @param array $config + * @return RequestConfig|null + */ + protected function getRequestConfig(array $config) : ?RequestConfig { + if(is_callable([$this, $requestHandler = array_shift($config)])){ + return call_user_func_array([$this, $requestHandler], $config); + } + return null; + } + /** * @param string $method * @param string $uri @@ -802,42 +846,36 @@ public function send(callable $requestHandler, ...$handlerParams){ $response = $this->getClient()->send($config->request, $config->options); } - public function sendAsync(callable $requestHandler, ...$handlerParams){ - } /** - * @param array $requestsConfig + * send batch requests (parallel async requests) + * @param array $configs * @return array */ - public function sendBatch(array $requestsConfig) : array { + public function sendBatch(array $configs) : array { - $requestsConfig = array_map(function(array $config){ - if(is_callable([$this, $requestHandler = array_shift($config)])){ - // return $requestHandler(...$config); - return call_user_func_array([$this, $requestHandler], $config); + /** + * @var RequestConfig[] $requestConfigs + */ + $requestConfigs = array_map(function(array $config){ + if($requestConfig = $this->getRequestConfig($config)){ + return $requestConfig; } - return null; - }, $requestsConfig); - - /* - $batchRequests = [ - (object)[ - 'request' => WebClient::newRequest('GET', 'abc'), - 'options' => [], - 'formatter' => function(JsonStreamInterface $body){ - return $body; - }] - ];*/ - - // must be 'Traversable of Promises'. + // invalid config + throw new \InvalidArgumentException(self::ERROR_INVALID_REQUEST_CONFIG); + }, $configs); + + // $requests must be 'Traversable of Promises' // So we’ll create a generator method which will only start the async request when the promise is grabbed - $requests = (function() use ($requestsConfig) { - foreach($requestsConfig as $config){ + $requests = (function() use ($requestConfigs) { + foreach($requestConfigs as $requestConfig){ // don't forget using generator - //yield $this->getClient()->sendAsync($config->request, $config->options); - yield function() use ($config) { - return $this->getClient()->sendAsync($config->request, $config->options); + yield function() use ($requestConfig) { + return $this->getClient()->sendAsync( + $requestConfig->getRequest(), + $requestConfig->getOptions() + ); }; } })(); @@ -845,10 +883,10 @@ public function sendBatch(array $requestsConfig) : array { // run requests async (parallel) // -> but wait()´s until all requests are either "fulfilled" or "rejected" $results = $this->getClient()->runBatch($requests, [ - 'concurrency' => 5 + 'concurrency' => $this->getBatchConcurrency() ]); - return array_map(function($result, $key) use ($requestsConfig) { + return array_map(function($result, $key) use ($requestConfigs) { // check result for valid responses // -> wrap rejected requests into errorResponses if($result instanceof Response){ @@ -867,7 +905,7 @@ public function sendBatch(array $requestsConfig) : array { $bodyContent = $body->getContents(); // call custom formatter for current $result (same $key) - return is_callable($formatter = $requestsConfig[$key]->formatter) ? $formatter($bodyContent) : $bodyContent; + return is_callable($formatter = $requestConfigs[$key]->getFormatter()) ? $formatter($bodyContent) : $bodyContent; }, $results, array_keys($results)); } diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index 65eca91..e934640 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -11,8 +11,8 @@ use Exodus4D\ESI\Client\Ccp; use Exodus4D\ESI\Config\ConfigInterface; use Exodus4D\ESI\Config\Ccp\Esi\Config; +use Exodus4D\ESI\Lib\RequestConfig; use Exodus4D\ESI\Lib\WebClient; -use Exodus4D\ESI\Lib\Stream\JsonStreamInterface; use Exodus4D\ESI\Mapper\Esi as Mapper; class Esi extends Ccp\AbstractCcp implements EsiInterface { @@ -829,7 +829,7 @@ public function getRouteData(int $sourceId, int $targetId, array $options = []) return $routeData; } - public function getRouteRequest(int $sourceId, int $targetId, array $options = []){ + public function getRouteRequest(int $sourceId, int $targetId, array $options = []) : RequestConfig { $query = []; if( !empty($options['avoid']) ){ $query['avoid'] = $options['avoid']; @@ -851,10 +851,11 @@ public function getRouteRequest(int $sourceId, int $targetId, array $options = [ // 404 'No route found' error -> should not be logged $requestOptions['log_off_status'] = [404]; - return (object)[ - 'request' => WebClient::newRequest('GET', $this->getEndpointURI(['routes', 'GET'], [$sourceId, $targetId])), - 'options' => $requestOptions, - 'formatter' => function($body) : array { + + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['routes', 'GET'], [$sourceId, $targetId])), + $requestOptions, + function($body) : array { $routeData = []; if(!$body->error){ $routeData['route'] = array_unique(array_map('intval', (array)$body)); @@ -863,7 +864,7 @@ public function getRouteRequest(int $sourceId, int $targetId, array $options = [ } return $routeData; } - ]; + ); } /** diff --git a/app/Lib/RequestConfig.php b/app/Lib/RequestConfig.php new file mode 100644 index 0000000..b8e2228 --- /dev/null +++ b/app/Lib/RequestConfig.php @@ -0,0 +1,93 @@ +setRequest($request); + $this->setOptions($options); + $this->setFormatter($formatter); + } + + /** + * @return Request + */ + public function getRequest() : Request{ + return $this->request; + } + + /** + * @param Request $request + * @return RequestConfig + */ + public function setRequest(Request $request) : RequestConfig{ + $this->request = $request; + return $this; + } + + /** + * @return array + */ + public function getOptions() : array{ + return $this->options; + } + + /** + * @param array $options + * @return RequestConfig + */ + public function setOptions(array $options) : RequestConfig{ + $this->options = $options; + return $this; + } + + /** + * @return callable|null + */ + public function getFormatter() : ?callable{ + return $this->formatter; + } + + /** + * @param callable|null $formatter + * @return RequestConfig + */ + public function setFormatter(?callable $formatter) : RequestConfig{ + $this->formatter = $formatter; + return $this; + } + +} \ No newline at end of file From 32c8801d566bc641e26b5dfca72f3291f4a7d29c Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 3 Feb 2020 22:50:29 +0100 Subject: [PATCH 37/58] - New "batch" request (parallel async) --- app/Client/AbstractApi.php | 36 ++++++++++++++++++++++++++++-------- app/Client/Ccp/Esi/Esi.php | 2 +- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index 8c74bfa..b321400 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -802,12 +802,13 @@ protected function getRetryMiddlewareConfig() : array { /** * get config for API request call from config - * @param array $config + * @param string $requestHandler + * @param mixed ...$handlerParams * @return RequestConfig|null */ - protected function getRequestConfig(array $config) : ?RequestConfig { - if(is_callable([$this, $requestHandler = array_shift($config)])){ - return call_user_func_array([$this, $requestHandler], $config); + protected function getRequestConfig(string $requestHandler, ...$handlerParams) : ?RequestConfig { + if(is_callable([$this, $requestHandler])){ + return call_user_func_array([$this, $requestHandler], $handlerParams); } return null; } @@ -840,10 +841,29 @@ protected function request(string $method, string $uri, array $options = []) : ? return $body; } - public function send(callable $requestHandler, ...$handlerParams){ - $config = $requestHandler(...$handlerParams); + public function send(string $requestHandler, ...$handlerParams){ + $bodyContent = null; + + if($requestConfig = $this->getRequestConfig($requestHandler, ...$handlerParams)){ + try{ + $response = $this->getClient()->send($requestConfig->getRequest(), $requestConfig->getOptions()); + }catch(TransferException $e){ + // Base Exception of Guzzle errors + // -> this includes "expected" errors like 4xx responses (ClientException) + // and "unexpected" errors like cURL fails (ConnectException)... + // -> error is already logged by LogMiddleware + $response = WebClient::newErrorResponse($e, $this->getAcceptType()); + }catch(\Exception $e){ + // Hard fail! Any other type of error + // -> e.g. RuntimeException,... + $response = WebClient::newErrorResponse($e, $this->getAcceptType()); + } + + $body = $response->getBody(); + $bodyContent = $body->getContents(); + } - $response = $this->getClient()->send($config->request, $config->options); + return $bodyContent; } @@ -859,7 +879,7 @@ public function sendBatch(array $configs) : array { * @var RequestConfig[] $requestConfigs */ $requestConfigs = array_map(function(array $config){ - if($requestConfig = $this->getRequestConfig($config)){ + if($requestConfig = $this->getRequestConfig(...$config)){ return $requestConfig; } // invalid config diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index e934640..a728d98 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -829,7 +829,7 @@ public function getRouteData(int $sourceId, int $targetId, array $options = []) return $routeData; } - public function getRouteRequest(int $sourceId, int $targetId, array $options = []) : RequestConfig { + protected function getRouteRequest(int $sourceId, int $targetId, array $options = []) : RequestConfig { $query = []; if( !empty($options['avoid']) ){ $query['avoid'] = $options['avoid']; From 8ad916729580b96af5a33cb1c48d93ffb8fa1323 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 3 Feb 2020 23:20:45 +0100 Subject: [PATCH 38/58] - New "batch" request (parallel async) --- app/Client/Ccp/Esi/Esi.php | 72 ++++++++--------------------- app/Client/Ccp/Esi/EsiInterface.php | 13 ------ 2 files changed, 18 insertions(+), 67 deletions(-) diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index a728d98..46a15ed 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -68,22 +68,23 @@ public function getVersion() : string { } /** - * @return array + * @return RequestConfig */ - public function getServerStatus() : array { - $uri = $this->getEndpointURI(['status', 'GET']); - $serverStatus = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $serverStatus['status'] = (new Mapper\Status\Status($response))->getData(); - }else{ - $serverStatus['error'] = $response->error; - } + protected function getServerStatusRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['status', 'GET'])), + $this->getRequestOptions(), + function($body) : array { + $serverStatus = []; + if(!$body->error){ + $serverStatus['status'] = (new Mapper\Status\Status($body))->getData(); + }else{ + $serverStatus['error'] = $body->error; + } - return $serverStatus; + return $serverStatus; + } + ); } /** @@ -788,47 +789,11 @@ public function getFactionWarSystems() : array { } /** - * @param int $sourceId - * @param int $targetId + * @param int $sourceId + * @param int $targetId * @param array $options - * @return array + * @return RequestConfig */ - public function getRouteData(int $sourceId, int $targetId, array $options = []) : array { - $uri = $this->getEndpointURI(['routes', 'GET'], [$sourceId, $targetId]); - $routeData = []; - - $query = []; - if( !empty($options['avoid']) ){ - $query['avoid'] = $options['avoid']; - } - if( !empty($options['connections']) ){ - $query['connections'] = $options['connections']; - } - if( !empty($options['flag']) ){ - $query['flag'] = $options['flag']; - } - - $query = $this->formatUrlParams($query, [ - 'connections' => [',', '|'], - 'avoid' => [','] - ]); - - $requestOptions = $this->getRequestOptions('', null, $query); - - // 404 'No route found' error -> should not be logged - $requestOptions['log_off_status'] = [404]; - - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $routeData['route'] = array_unique( array_map('intval', (array)$response) ); - }else{ - $routeData['error'] = $response->error; - } - - return $routeData; - } - protected function getRouteRequest(int $sourceId, int $targetId, array $options = []) : RequestConfig { $query = []; if( !empty($options['avoid']) ){ @@ -851,7 +816,6 @@ protected function getRouteRequest(int $sourceId, int $targetId, array $options // 404 'No route found' error -> should not be logged $requestOptions['log_off_status'] = [404]; - return new RequestConfig( WebClient::newRequest('GET', $this->getEndpointURI(['routes', 'GET'], [$sourceId, $targetId])), $requestOptions, diff --git a/app/Client/Ccp/Esi/EsiInterface.php b/app/Client/Ccp/Esi/EsiInterface.php index 33c987b..9099276 100644 --- a/app/Client/Ccp/Esi/EsiInterface.php +++ b/app/Client/Ccp/Esi/EsiInterface.php @@ -10,11 +10,6 @@ interface EsiInterface { - /** - * @return array - */ - public function getServerStatus() : array; - /** * get corporation/alliance ids by characterIds * @param array $characterIds @@ -216,14 +211,6 @@ public function getDogmaAttributeData(int $attributeId) : array; */ public function getFactionWarSystems() : array; - /** - * @param int $sourceId - * @param int $targetId - * @param array $options - * @return array - */ - public function getRouteData(int $sourceId, int $targetId, array $options = []) : array; - /** * @param int $destinationId * @param string $accessToken From 23e1d83fdd3fa2a85c9b0fdd09008071cd8374f4 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 3 Feb 2020 23:32:40 +0100 Subject: [PATCH 39/58] - New "batch" request (parallel async) --- app/Client/AbstractApi.php | 19 +++++++++++-------- app/Client/ApiInterface.php | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index b321400..485362a 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -361,17 +361,17 @@ public function setConnectTimeout(float $connectTimeout = self::DEFAULT_CONNECT_ } /** - * @param int $batchConcurrency + * @param float $readTimeout */ - public function setBatchConcurrency(int $batchConcurrency = self::DEFAULT_BATCH_CONCURRENCY){ - $this->batchConcurrency = $batchConcurrency; + public function setReadTimeout(float $readTimeout = self::DEFAULT_READ_TIMEOUT){ + $this->readTimeout = $readTimeout; } /** - * @param float $readTimeout + * @param int $batchConcurrency */ - public function setReadTimeout(float $readTimeout = self::DEFAULT_READ_TIMEOUT){ - $this->readTimeout = $readTimeout; + public function setBatchConcurrency(int $batchConcurrency = self::DEFAULT_BATCH_CONCURRENCY){ + $this->batchConcurrency = $batchConcurrency; } /** @@ -841,6 +841,11 @@ protected function request(string $method, string $uri, array $options = []) : ? return $body; } + /** + * @param string $requestHandler + * @param mixed ...$handlerParams + * @return string|null + */ public function send(string $requestHandler, ...$handlerParams){ $bodyContent = null; @@ -866,8 +871,6 @@ public function send(string $requestHandler, ...$handlerParams){ return $bodyContent; } - - /** * send batch requests (parallel async requests) * @param array $configs diff --git a/app/Client/ApiInterface.php b/app/Client/ApiInterface.php index e6caa59..7d60bb1 100644 --- a/app/Client/ApiInterface.php +++ b/app/Client/ApiInterface.php @@ -46,6 +46,11 @@ public function setConnectTimeout(float $connectTimeout); */ public function setReadTimeout(float $readTimeout); + /** + * @param int $batchConcurrency + */ + public function setBatchConcurrency(int $batchConcurrency = self::DEFAULT_BATCH_CONCURRENCY); + /** * @param $decodeContent * @return mixed @@ -191,6 +196,11 @@ public function getConnectTimeout() : float; */ public function getReadTimeout() : float; + /** + * @return int + */ + public function getBatchConcurrency() : int; + /** * @return mixed */ @@ -231,4 +241,17 @@ public function getCachePool() : ?\Closure; */ public function getNewLog() : ?\Closure; + /** + * @param string $requestHandler + * @param mixed ...$handlerParams + * @return string|null + */ + public function send(string $requestHandler, ...$handlerParams); + + + /** + * @param array $configs + * @return array + */ + public function sendBatch(array $configs) : array; } \ No newline at end of file From 1f770873971bc0b7c8418b36497b5255f4455cfa Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Mon, 3 Feb 2020 23:43:41 +0100 Subject: [PATCH 40/58] - New "batch" request (parallel async) --- app/Client/AbstractApi.php | 5 ++++- app/Client/ApiInterface.php | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index 485362a..0516ff9 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -844,7 +844,7 @@ protected function request(string $method, string $uri, array $options = []) : ? /** * @param string $requestHandler * @param mixed ...$handlerParams - * @return string|null + * @return mixed|null */ public function send(string $requestHandler, ...$handlerParams){ $bodyContent = null; @@ -866,6 +866,9 @@ public function send(string $requestHandler, ...$handlerParams){ $body = $response->getBody(); $bodyContent = $body->getContents(); + + // call custom formatter for current $result (same $key) + $bodyContent = is_callable($formatter = $requestConfig->getFormatter()) ? $formatter($bodyContent) : $bodyContent; } return $bodyContent; diff --git a/app/Client/ApiInterface.php b/app/Client/ApiInterface.php index 7d60bb1..9841efe 100644 --- a/app/Client/ApiInterface.php +++ b/app/Client/ApiInterface.php @@ -244,11 +244,10 @@ public function getNewLog() : ?\Closure; /** * @param string $requestHandler * @param mixed ...$handlerParams - * @return string|null + * @return mixed|null */ public function send(string $requestHandler, ...$handlerParams); - /** * @param array $configs * @return array From 70ae3bcfb4f723a504a954725dd9ed482364582d Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Tue, 4 Feb 2020 18:22:55 +0100 Subject: [PATCH 41/58] - New "batch" request (parallel async) --- app/Client/Ccp/Esi/Esi.php | 56 +++++++++++++++-------------- app/Client/Ccp/Esi/EsiInterface.php | 13 ------- 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index 46a15ed..4f1cd2d 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -89,43 +89,45 @@ function($body) : array { /** * @param array $characterIds - * @return array + * @return RequestConfig */ - public function getCharacterAffiliationData(array $characterIds) : array { - $uri = $this->getEndpointURI(['characters', 'affiliation', 'POST']); - $characterAffiliationData = []; - - $requestOptions = $this->getRequestOptions('', $characterIds); - $response = $this->request('POST', $uri, $requestOptions)->getContents(); + protected function getCharacterAffiliationRequest(array $characterIds) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('POST', $this->getEndpointURI(['characters', 'affiliation', 'POST'])), + $this->getRequestOptions('', $characterIds), + function($body) : array { + $characterAffiliationData = []; + if(!$body->error){ + foreach((array)$body as $affiliationData){ + $characterAffiliationData[] = (new Mapper\Character\Affiliation($affiliationData))->getData(); + } + } - if(!$response->error){ - foreach((array)$response as $affiliationData){ - $characterAffiliationData[] = (new Mapper\Character\Affiliation($affiliationData))->getData(); + return $characterAffiliationData; } - } - - return $characterAffiliationData; + ); } /** * @param int $characterId - * @return array + * @return RequestConfig */ - public function getCharacterData(int $characterId) : array { - $uri = $this->getEndpointURI(['characters', 'GET'], [$characterId]); - $characterData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + protected function getCharacterRequest(int $characterId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['characters', 'GET'], [$characterId])), + $this->getRequestOptions(), + function($body) use ($characterId) : array { + $characterData = []; + if(!$body->error){ + $characterData = (new Mapper\Character\Character($body))->getData(); + if( !empty($characterData) ){ + $characterData['id'] = $characterId; + } + } - if(!$response->error){ - $characterData = (new Mapper\Character\Character($response))->getData(); - if( !empty($characterData) ){ - $characterData['id'] = $characterId; + return $characterData; } - } - - return $characterData; + ); } /** diff --git a/app/Client/Ccp/Esi/EsiInterface.php b/app/Client/Ccp/Esi/EsiInterface.php index 9099276..9580b63 100644 --- a/app/Client/Ccp/Esi/EsiInterface.php +++ b/app/Client/Ccp/Esi/EsiInterface.php @@ -10,19 +10,6 @@ interface EsiInterface { - /** - * get corporation/alliance ids by characterIds - * @param array $characterIds - * @return array - */ - public function getCharacterAffiliationData(array $characterIds) : array; - - /** - * @param int $characterId - * @return array - */ - public function getCharacterData(int $characterId) : array; - /** * @param int $characterId * @param string $accessToken From efd4d717115e8ea7aa471b66e8f691f56f5e61d2 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Tue, 4 Feb 2020 18:47:44 +0100 Subject: [PATCH 42/58] - New "batch" request (parallel async) --- app/Client/Ccp/Esi/Esi.php | 170 ++++++++++++++-------------- app/Client/Ccp/Esi/EsiInterface.php | 40 ------- 2 files changed, 88 insertions(+), 122 deletions(-) diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index 4f1cd2d..648e2f2 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -133,125 +133,131 @@ function($body) use ($characterId) : array { /** * @param int $characterId * @param string $accessToken - * @return array + * @return RequestConfig */ - public function getCharacterClonesData(int $characterId, string $accessToken) : array { - $uri = $this->getEndpointURI(['characters', 'clones', 'GET'], [$characterId]); - $clonesData = []; - - $requestOptions = $this->getRequestOptions($accessToken); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $clonesData['home'] = (new Mapper\Character\CharacterClone($response->home_location))->getData(); - }else{ - $clonesData['error'] = $response->error; - } + protected function getCharacterClonesRequest(int $characterId, string $accessToken) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['characters', 'clones', 'GET'], [$characterId])), + $this->getRequestOptions($accessToken), + function($body) : array { + $clonesData = []; + if(!$body->error){ + $clonesData['home'] = (new Mapper\Character\CharacterClone($body->home_location))->getData(); + }else{ + $clonesData['error'] = $body->error; + } - return $clonesData; + return $clonesData; + } + ); } /** * @param int $characterId * @param string $accessToken - * @return array + * @return RequestConfig */ - public function getCharacterLocationData(int $characterId, string $accessToken) : array { - $uri = $this->getEndpointURI(['characters', 'location', 'GET'], [$characterId]); - $locationData = []; - - $requestOptions = $this->getRequestOptions($accessToken); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $locationData = (new Mapper\Character\Location($response))->getData(); - } + protected function getCharacterLocationRequest(int $characterId, string $accessToken) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['characters', 'location', 'GET'], [$characterId])), + $this->getRequestOptions($accessToken), + function($body) : array { + $locationData = []; + if(!$body->error){ + $locationData = (new Mapper\Character\Location($body))->getData(); + } - return $locationData; + return $locationData; + } + ); } /** * @param int $characterId * @param string $accessToken - * @return array + * @return RequestConfig */ - public function getCharacterShipData(int $characterId, string $accessToken) : array { - $uri = $this->getEndpointURI(['characters', 'ship', 'GET'], [$characterId]); - $shipData = []; - - $requestOptions = $this->getRequestOptions($accessToken); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $shipData = (new Mapper\Character\Ship($response))->getData(); - } + protected function getCharacterShipRequest(int $characterId, string $accessToken) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['characters', 'ship', 'GET'], [$characterId])), + $this->getRequestOptions($accessToken), + function($body) : array { + $shipData = []; + if(!$body->error){ + $shipData = (new Mapper\Character\Ship($body))->getData(); + } - return $shipData; + return $shipData; + } + ); } /** * @param int $characterId * @param string $accessToken - * @return array + * @return RequestConfig */ - public function getCharacterOnlineData(int $characterId, string $accessToken) : array { - $uri = $this->getEndpointURI(['characters', 'online', 'GET'], [$characterId]); - $onlineData = []; - - $requestOptions = $this->getRequestOptions($accessToken); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $onlineData = (new Mapper\Character\Online($response))->getData(); - } + protected function getCharacterOnlineRequest(int $characterId, string $accessToken) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['characters', 'online', 'GET'], [$characterId])), + $this->getRequestOptions($accessToken), + function($body) : array { + $onlineData = []; + if(!$body->error){ + $onlineData = (new Mapper\Character\Online($body))->getData(); + } - return $onlineData; + return $onlineData; + } + ); } /** * @param int $corporationId - * @return array + * @return RequestConfig */ - public function getCorporationData(int $corporationId) : array { - $uri = $this->getEndpointURI(['corporations', 'GET'], [$corporationId]); - $corporationData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + protected function getCorporationRequest(int $corporationId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['corporations', 'GET'], [$corporationId])), + $this->getRequestOptions(), + function($body) use ($corporationId) : array { + $corporationData = []; + if(!$body->error){ + $corporationData = (new Mapper\Corporation\Corporation($body))->getData(); + if( !empty($corporationData) ){ + $corporationData['id'] = $corporationId; + } + }else{ + $corporationData['error'] = $body->error; + } - if(!$response->error){ - $corporationData = (new Mapper\Corporation\Corporation($response))->getData(); - if( !empty($corporationData) ){ - $corporationData['id'] = $corporationId; + return $corporationData; } - }else{ - $corporationData['error'] = $response->error; - } - - return $corporationData; + ); } /** * @param int $allianceId - * @return array + * @return RequestConfig */ - public function getAllianceData(int $allianceId) : array { - $uri = $this->getEndpointURI(['alliances', 'GET'], [$allianceId]); - $allianceData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + protected function getAllianceRequest(int $allianceId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['alliances', 'GET'], [$allianceId])), + $this->getRequestOptions(), + function($body) use ($allianceId) : array { + $allianceData = []; + if(!$body->error){ + $allianceData = (new Mapper\Alliance\Alliance($body))->getData(); + if( !empty($allianceData) ){ + $allianceData['id'] = $allianceId; + } + }else{ + $allianceData['error'] = $body->error; + } - if(!$response->error){ - $allianceData = (new Mapper\Alliance\Alliance($response))->getData(); - if( !empty($allianceData) ){ - $allianceData['id'] = $allianceId; + return $allianceData; } - }else{ - $allianceData['error'] = $response->error; - } - - return $allianceData; + ); } /** diff --git a/app/Client/Ccp/Esi/EsiInterface.php b/app/Client/Ccp/Esi/EsiInterface.php index 9580b63..6fbe14f 100644 --- a/app/Client/Ccp/Esi/EsiInterface.php +++ b/app/Client/Ccp/Esi/EsiInterface.php @@ -10,46 +10,6 @@ interface EsiInterface { - /** - * @param int $characterId - * @param string $accessToken - * @return array - */ - public function getCharacterClonesData(int $characterId, string $accessToken) : array; - - /** - * @param int $characterId - * @param string $accessToken - * @return array - */ - public function getCharacterLocationData(int $characterId, string $accessToken) : array; - - /** - * @param int $characterId - * @param string $accessToken - * @return array - */ - public function getCharacterShipData(int $characterId, string $accessToken) : array; - - /** - * @param int $characterId - * @param string $accessToken - * @return array - */ - public function getCharacterOnlineData(int $characterId, string $accessToken) : array; - - /** - * @param int $corporationId - * @return array - */ - public function getCorporationData(int $corporationId) : array; - - /** - * @param int $allianceId - * @return array - */ - public function getAllianceData(int $allianceId) : array; - /** * @param int $corporationId * @param string $accessToken From fbaee8651bd393e3f17be48eceb3f164fc87319a Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Tue, 4 Feb 2020 19:29:44 +0100 Subject: [PATCH 43/58] - New "batch" request (parallel async) --- app/Client/Ccp/Esi/Esi.php | 232 +++++++++++++--------------- app/Client/Ccp/Esi/EsiInterface.php | 51 ------ 2 files changed, 108 insertions(+), 175 deletions(-) diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index 648e2f2..051c903 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -263,174 +263,158 @@ function($body) use ($allianceId) : array { /** * @param int $corporationId * @param string $accessToken - * @return array + * @return RequestConfig */ - public function getCorporationRoles(int $corporationId, string $accessToken) : array { - $uri = $this->getEndpointURI(['corporations', 'roles', 'GET'], [$corporationId]); - $rolesData = []; - + protected function getCorporationRolesRequest(int $corporationId, string $accessToken) : RequestConfig { $requestOptions = $this->getRequestOptions($accessToken); // 403 'Character cannot grant roles' error $requestOptions['log_off_status'] = [403]; - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - foreach((array)$response as $characterRoleData){ - $rolesData['roles'][(int)$characterRoleData->character_id] = array_map('strtolower', (array)$characterRoleData->roles); - } - }else{ - $rolesData['error'] = $response->error; - } - - return $rolesData; - } - - /** - * @return array - */ - public function getUniverseFactions() : array { - $uri = $this->getEndpointURI(['universe', 'factions', 'list', 'GET']); - $factionData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['corporations', 'roles', 'GET'], [$corporationId])), + $requestOptions, + function($body) : array { + $rolesData = []; + if(!$body->error){ + foreach((array)$body as $characterRoleData){ + $rolesData['roles'][(int)$characterRoleData->character_id] = array_map('strtolower', (array)$characterRoleData->roles); + } + }else{ + $rolesData['error'] = $body->error; + } - if($response->error){ - $factionData['error'] = $response->error; - }else{ - foreach((array)$response as $data){ - $factionData['factions'][(int)$data->faction_id] = (new Mapper\Universe\Faction($data))->getData(); + return $rolesData; } - } - - return $factionData; + ); } /** * @param int $factionId - * @return array - */ - public function getUniverseFactionData(int $factionId) : array { - $factionDataAll = $this->getUniverseFactions(); - $factionData = []; - - if(isset($factionDataAll['error'])){ - $factionData = $factionDataAll; - }elseif(is_array($factionDataAll['factions']) && array_key_exists($factionId, $factionDataAll['factions'])){ - $factionData = $factionDataAll['factions'][$factionId]; - } - - return $factionData; - } - - /** - * @return array + * @return RequestConfig */ - public function getUniverseRaces() : array { - $uri = $this->getEndpointURI(['universe', 'races', 'list', 'GET']); - $raceData = []; + protected function getUniverseFactionRequest(int $factionId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'factions', 'list', 'GET'])), + $this->getRequestOptions(), + function($body) use ($factionId) : array { + $factionData = []; + if($body->error){ + $factionData['error'] = $body->error; + }else{ + foreach((array)$body as $data){ + $factionData['factions'][(int)$data->faction_id] = (new Mapper\Universe\Faction($data))->getData(); + } - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + if($factionId && array_key_exists($factionId, $factionData['factions'])){ + $factionData = $factionData['factions'][$factionId]; + } + } - if($response->error){ - $raceData['error'] = $response->error; - }else{ - foreach((array)$response as $data){ - $raceData['races'][(int)$data->race_id] = (new Mapper\Universe\Race($data))->getData(); + return $factionData; } - } - - return $raceData; + ); } /** * @param int $raceId - * @return array + * @return RequestConfig */ - public function getUniverseRaceData(int $raceId) : array { - $raceDataAll = $this->getUniverseRaces(); - $raceData = []; - - if(isset($raceDataAll['error'])){ - $raceData = $raceDataAll; - }elseif(is_array($raceDataAll['races']) && array_key_exists($raceId, $raceDataAll['races'])){ - $raceData = $raceDataAll['races'][$raceId]; - } + protected function getUniverseRaceRequest(int $raceId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'races', 'list', 'GET'])), + $this->getRequestOptions(), + function($body) use ($raceId) : array { + $raceData = []; + if($body->error){ + $raceData['error'] = $body->error; + }else{ + foreach((array)$body as $data){ + $raceData['races'][(int)$data->race_id] = (new Mapper\Universe\Race($data))->getData(); + } + + if($raceId && array_key_exists($raceId, $raceData['races'])){ + $raceData = $raceData['races'][$raceId]; + } + } - return $raceData; + return $raceData; + } + ); } /** - * @return array + * @return RequestConfig */ - public function getUniverseRegions() : array { - $uri = $this->getEndpointURI(['universe', 'regions', 'list', 'GET']); - $regionData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $regionData = array_unique( array_map('intval', (array)$response) ); - } + protected function getUniverseRegionsRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'regions', 'list', 'GET'])), + $this->getRequestOptions(), + function($body) : array { + $regionData = []; + if(!$body->error){ + $regionData = array_unique( array_map('intval', (array)$body) ); + } - return $regionData; + return $regionData; + } + ); } /** * @param int $regionId - * @return array + * @return RequestConfig */ - public function getUniverseRegionData(int $regionId) : array { - $uri = $this->getEndpointURI(['universe', 'regions', 'GET'], [$regionId]); - $regionData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $regionData = (new Mapper\Universe\Region($response))->getData(); - } + protected function getUniverseRegionRequest(int $regionId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'regions', 'GET'], [$regionId])), + $this->getRequestOptions(), + function($body) : array { + $regionData = []; + if(!$body->error){ + $regionData = (new Mapper\Universe\Region($body))->getData(); + } - return $regionData; + return $regionData; + } + ); } /** - * @return array + * @return RequestConfig */ - public function getUniverseConstellations() : array { - $uri = $this->getEndpointURI(['universe', 'constellations', 'list', 'GET']); - $constellationData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $constellationData = array_unique( array_map('intval', (array)$response) ); - } + protected function getUniverseConstellationsRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'constellations', 'list', 'GET'])), + $this->getRequestOptions(), + function($body) : array { + $constellationData = []; + if(!$body->error){ + $constellationData = array_unique( array_map('intval', (array)$body) ); + } - return $constellationData; + return $constellationData; + } + ); } /** * @param int $constellationId - * @return array + * @return RequestConfig */ - public function getUniverseConstellationData(int $constellationId) : array { - $uri = $this->getEndpointURI(['universe', 'constellations', 'GET'], [$constellationId]); - $constellationData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $constellationData = (new Mapper\Universe\Constellation($response))->getData(); - } + protected function getUniverseConstellationRequest(int $constellationId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'constellations', 'GET'], [$constellationId])), + $this->getRequestOptions(), + function($body) : array { + $constellationData = []; + if(!$body->error){ + $constellationData = (new Mapper\Universe\Constellation($body))->getData(); + } - return $constellationData; + return $constellationData; + } + ); } /** diff --git a/app/Client/Ccp/Esi/EsiInterface.php b/app/Client/Ccp/Esi/EsiInterface.php index 6fbe14f..4594c50 100644 --- a/app/Client/Ccp/Esi/EsiInterface.php +++ b/app/Client/Ccp/Esi/EsiInterface.php @@ -10,57 +10,6 @@ interface EsiInterface { - /** - * @param int $corporationId - * @param string $accessToken - * @return array - */ - public function getCorporationRoles(int $corporationId, string $accessToken) : array; - - /** - * @return array - */ - public function getUniverseFactions() : array; - - /** - * @param int $factionId - * @return array - */ - public function getUniverseFactionData(int $factionId) : array; - - /** - * @return array - */ - public function getUniverseRaces() : array; - - /** - * @param int $raceId - * @return array - */ - public function getUniverseRaceData(int $raceId) : array; - - /** - * @return array - */ - public function getUniverseRegions() : array; - - /** - * @param int $regionId - * @return array - */ - public function getUniverseRegionData(int $regionId) : array; - - /** - * @return array - */ - public function getUniverseConstellations() : array; - - /** - * @param int $constellationId - * @return array - */ - public function getUniverseConstellationData(int $constellationId) : array; - /** * @return array */ From fab23a3f5a1aa30d6e0235de873f6038cd87b8df Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Tue, 4 Feb 2020 19:47:17 +0100 Subject: [PATCH 44/58] - New "batch" request (parallel async) --- app/Client/Ccp/Esi/Esi.php | 216 ++++++++++++++-------------- app/Client/Ccp/Esi/EsiInterface.php | 35 ----- 2 files changed, 111 insertions(+), 140 deletions(-) diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index 051c903..9936682 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -418,145 +418,151 @@ function($body) : array { } /** - * @return array + * @return RequestConfig */ - public function getUniverseSystems() : array { - $uri = $this->getEndpointURI(['universe', 'systems', 'list', 'GET']); - $systemData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $systemData = array_unique( array_map('intval', (array)$response) ); - } + protected function getUniverseSystemsRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'systems', 'list', 'GET'])), + $this->getRequestOptions(), + function($body) : array { + $systemData = []; + if(!$body->error){ + $systemData = array_unique( array_map('intval', (array)$body) ); + } - return $systemData; + return $systemData; + } + ); } /** * @param int $systemId - * @return array + * @return RequestConfig */ - public function getUniverseSystemData(int $systemId) : array { - $uri = $this->getEndpointURI(['universe', 'systems', 'GET'], [$systemId]); - $systemData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $systemData = (new Mapper\Universe\System($response))->getData(); - } + protected function getUniverseSystemRequest(int $systemId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'systems', 'GET'], [$systemId])), + $this->getRequestOptions(), + function($body) : array { + $systemData = []; + if(!$body->error){ + $systemData = (new Mapper\Universe\System($body))->getData(); + } - return $systemData; + return $systemData; + } + ); } /** * @param int $starId - * @return array + * @return RequestConfig */ - public function getUniverseStarData(int $starId) : array { - $uri = $this->getEndpointURI(['universe', 'stars', 'GET'], [$starId]); - $starData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + protected function getUniverseStarRequest(int $starId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'stars', 'GET'], [$starId])), + $this->getRequestOptions(), + function($body) use ($starId) : array { + $starData = []; + if(!$body->error){ + $starData = (new Mapper\Universe\Star($body))->getData(); + if( !empty($starData) ){ + $starData['id'] = $starId; + } + } - if(!$response->error){ - $starData = (new Mapper\Universe\Star($response))->getData(); - if( !empty($starData) ){ - $starData['id'] = $starId; + return $starData; } - } - - return $starData; + ); } /** * @param int $planetId - * @return array + * @return RequestConfig */ - public function getUniversePlanetData(int $planetId) : array { - $uri = $this->getEndpointURI(['universe', 'planets', 'GET'], [$planetId]); - $planetData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $planetData = (new Mapper\Universe\Planet($response))->getData(); - } + protected function getUniversePlanetRequest(int $planetId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'planets', 'GET'], [$planetId])), + $this->getRequestOptions(), + function($body) : array { + $planetData = []; + if(!$body->error){ + $planetData = (new Mapper\Universe\Planet($body))->getData(); + } - return $planetData; + return $planetData; + } + ); } /** * @param int $stargateId - * @return array + * @return RequestConfig */ - public function getUniverseStargateData(int $stargateId) : array { - $uri = $this->getEndpointURI(['universe', 'stargates', 'GET'], [$stargateId]); - $stargateData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $stargateData = (new Mapper\Universe\Stargate($response))->getData(); - } + protected function getUniverseStargateRequest(int $stargateId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'stargates', 'GET'], [$stargateId])), + $this->getRequestOptions(), + function($body) : array { + $stargateData = []; + if(!$body->error){ + $stargateData = (new Mapper\Universe\Stargate($body))->getData(); + } - return $stargateData; + return $stargateData; + } + ); } /** * @param array $universeIds - * @return array + * @return RequestConfig */ - public function getUniverseNamesData(array $universeIds) : array { - $uri = $this->getEndpointURI(['universe', 'names', 'POST']); - $universeData = []; - - $requestOptions = $this->getRequestOptions('', $universeIds); - $response = $this->request('POST', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - foreach((array)$response as $data){ - // store category because $data get changed in Mappers - $category = $data->category; - switch($category){ - case 'character': - $categoryData = (new Mapper\Character\Character($data))->getData(); - break; - case 'alliance': - $categoryData = (new Mapper\Alliance\Alliance($data))->getData(); - break; - case 'corporation': - $categoryData = (new Mapper\Corporation\Corporation($data))->getData(); - break; - case 'station': - $categoryData = (new Mapper\Universe\Station($data))->getData(); - break; - case 'solar_system': - $category = 'system'; - $categoryData = (new Mapper\Universe\System($data))->getData(); - break; - case 'inventory_type': - $category = 'inventoryType'; - $categoryData = (new Mapper\InventoryType($data))->getData(); - break; - default: - $categoryData = []; - } - if( !empty($categoryData) ){ - $universeData[$category][] = $categoryData; + protected function getUniverseNamesRequest(array $universeIds) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('POST', $this->getEndpointURI(['universe', 'names', 'POST'])), + $this->getRequestOptions('', $universeIds), + function($body) : array { + $universeData = []; + if(!$body->error){ + foreach((array)$body as $data){ + // store category because $data get changed in Mappers + $category = $data->category; + switch($category){ + case 'character': + $categoryData = (new Mapper\Character\Character($data))->getData(); + break; + case 'alliance': + $categoryData = (new Mapper\Alliance\Alliance($data))->getData(); + break; + case 'corporation': + $categoryData = (new Mapper\Corporation\Corporation($data))->getData(); + break; + case 'station': + $categoryData = (new Mapper\Universe\Station($data))->getData(); + break; + case 'solar_system': + $category = 'system'; + $categoryData = (new Mapper\Universe\System($data))->getData(); + break; + case 'inventory_type': + $category = 'inventoryType'; + $categoryData = (new Mapper\InventoryType($data))->getData(); + break; + default: + $categoryData = []; + } + if( !empty($categoryData) ){ + $universeData[$category][] = $categoryData; + } + } + }else{ + $universeData['error'] = $body->error; } - } - }else{ - $universeData['error'] = $response->error; - } - return $universeData; + return $universeData; + } + ); } /** diff --git a/app/Client/Ccp/Esi/EsiInterface.php b/app/Client/Ccp/Esi/EsiInterface.php index 4594c50..23dd5b0 100644 --- a/app/Client/Ccp/Esi/EsiInterface.php +++ b/app/Client/Ccp/Esi/EsiInterface.php @@ -10,41 +10,6 @@ interface EsiInterface { - /** - * @return array - */ - public function getUniverseSystems() : array; - - /** - * @param int $systemId - * @return array - */ - public function getUniverseSystemData(int $systemId) : array; - - /** - * @param int $starId - * @return array - */ - public function getUniverseStarData(int $starId) : array; - - /** - * @param int $planetId - * @return array - */ - public function getUniversePlanetData(int $planetId) : array; - - /** - * @param int $stargateId - * @return array - */ - public function getUniverseStargateData(int $stargateId) : array; - - /** - * @param array $universeIds - * @return array - */ - public function getUniverseNamesData(array $universeIds) : array; - /** * @return array */ From a2b6c8f58bc7167404c29607d1793e837adef476 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Tue, 4 Feb 2020 20:24:38 +0100 Subject: [PATCH 45/58] - New "batch" request (parallel async) --- app/Client/Ccp/Esi/Esi.php | 232 ++++++++++++++-------------- app/Client/Ccp/Esi/EsiInterface.php | 45 ------ 2 files changed, 120 insertions(+), 157 deletions(-) diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index 9936682..0581047 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -566,165 +566,173 @@ function($body) : array { } /** - * @return array + * @return RequestConfig */ - public function getUniverseJumps() : array { - $uri = $this->getEndpointURI(['universe', 'system_jumps', 'GET']); - $systemJumps = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + protected function getUniverseJumpsRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'system_jumps', 'GET'])), + $this->getRequestOptions(), + function($body) : array { + $systemJumps = []; + if(!$body->error){ + foreach((array)$body as $jumpData){ + $systemJumps[$jumpData->system_id]['jumps'] = (int)$jumpData->ship_jumps; + } + } - if(!$response->error){ - foreach((array)$response as $jumpData){ - $systemJumps[$jumpData->system_id]['jumps'] = (int)$jumpData->ship_jumps; + return $systemJumps; } - } - - return $systemJumps; + ); } /** - * @return array + * @return RequestConfig */ - public function getUniverseKills() : array { - $uri = $this->getEndpointURI(['universe', 'system_kills', 'GET']); - $systemKills = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + protected function getUniverseKillsRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'system_kills', 'GET'])), + $this->getRequestOptions(), + function($body) : array { + $systemKills = []; + if(!$body->error){ + foreach((array)$body as $killData){ + $systemKills[$killData->system_id] = [ + 'npc_kills' => (int)$killData->npc_kills, + 'pod_kills' => (int)$killData->pod_kills, + 'ship_kills' => (int)$killData->ship_kills + ]; + } + } - if(!$response->error){ - foreach((array)$response as $killData){ - $systemKills[$killData->system_id] = [ - 'npc_kills' => (int)$killData->npc_kills, - 'pod_kills' => (int)$killData->pod_kills, - 'ship_kills' => (int)$killData->ship_kills - ]; + return $systemKills; } - } - - return $systemKills; + ); } /** - * @return array + * @return RequestConfig */ - public function getUniverseCategories() : array { - $uri = $this->getEndpointURI(['universe', 'categories', 'list', 'GET']); - $categoryData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $categoryData = array_unique( array_map('intval', (array)$response) ); - } + protected function getUniverseCategoriesRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'categories', 'list', 'GET'])), + $this->getRequestOptions(), + function($body) : array { + $categoryData = []; + if(!$body->error){ + $categoryData = array_unique( array_map('intval', (array)$body) ); + } - return $categoryData; + return $categoryData; + } + ); } /** * @param int $categoryId - * @return array + * @return RequestConfig */ - public function getUniverseCategoryData(int $categoryId) : array { - $uri = $this->getEndpointURI(['universe', 'categories', 'GET'], [$categoryId]); - $categoryData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + protected function getUniverseCategoryRequest(int $categoryId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'categories', 'GET'], [$categoryId])), + $this->getRequestOptions(), + function($body) use ($categoryId) : array { + $categoryData = []; + if(!$body->error){ + $categoryData = (new Mapper\Universe\Category($body))->getData(); + if( !empty($categoryData) ){ + $categoryData['id'] = $categoryId; + } + } - if(!$response->error){ - $categoryData = (new Mapper\Universe\Category($response))->getData(); - if( !empty($categoryData) ){ - $categoryData['id'] = $categoryId; + return $categoryData; } - } - - return $categoryData; + ); } /** - * @return array + * @return RequestConfig */ - public function getUniverseGroups() : array { - $uri = $this->getEndpointURI(['universe', 'groups', 'list', 'GET']); - $groupData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $groupData = array_unique( array_map('intval', (array)$response) ); - } + protected function getUniverseGroupsRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'groups', 'list', 'GET'])), + $this->getRequestOptions(), + function($body) : array { + $groupData = []; + if(!$body->error){ + $groupData = array_unique( array_map('intval', (array)$body) ); + } - return $groupData; + return $groupData; + } + ); } /** * @param int $groupId - * @return array + * @return RequestConfig */ - public function getUniverseGroupData(int $groupId) : array { - $uri = $this->getEndpointURI(['universe', 'groups', 'GET'], [$groupId]); - $groupData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + protected function getUniverseGroupRequest(int $groupId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'groups', 'GET'], [$groupId])), + $this->getRequestOptions(), + function($body) use ($groupId) : array { + $groupData = []; + if(!$body->error){ + $groupData = (new Mapper\Universe\Group($body))->getData(); + if( !empty($groupData) ){ + $groupData['id'] = $groupId; + } + } - if(!$response->error){ - $groupData = (new Mapper\Universe\Group($response))->getData(); - if( !empty($groupData) ){ - $groupData['id'] = $groupId; + return $groupData; } - } - - return $groupData; + ); } /** * @param int $structureId * @param string $accessToken - * @return array + * @return RequestConfig */ - public function getUniverseStructureData(int $structureId, string $accessToken) : array { - $uri = $this->getEndpointURI(['universe', 'structures', 'GET'], [$structureId]); - $structureData = []; - - $requestOptions = $this->getRequestOptions($accessToken); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + protected function getUniverseStructureRequest(int $structureId, string $accessToken) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'structures', 'GET'], [$structureId])), + $this->getRequestOptions($accessToken), + function($body) use ($structureId) : array { + $structureData = []; + if(!$body->error){ + $structureData = (new Mapper\Universe\Structure($body))->getData(); + if( !empty($structureData) ){ + $structureData['id'] = $structureId; + } + }else{ + $structureData['error'] = $body->error; + } - if($response->error){ - $structureData['error'] = $response->error; - }else{ - $structureData = (new Mapper\Universe\Structure($response))->getData(); - if( !empty($structureData) ){ - $structureData['id'] = $structureId; + return $structureData; } - } - - return $structureData; + ); } /** * @param int $stationId - * @return array + * @return RequestConfig */ - public function getUniverseStationData(int $stationId) : array { - $uri = $this->getEndpointURI(['universe', 'stations', 'GET'], [$stationId]); - $stationData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if($response->error){ - $stationData['error'] = $response->error; - }else{ - $stationData = (new Mapper\Universe\Station($response))->getData(); - } + protected function getUniverseStationRequest(int $stationId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'stations', 'GET'], [$stationId])), + $this->getRequestOptions(), + function($body) : array { + $stationData = []; + if(!$body->error){ + $stationData = (new Mapper\Universe\Station($body))->getData(); + }else{ + $stationData['error'] = $body->error; + } - return $stationData; + return $stationData; + } + ); } /** diff --git a/app/Client/Ccp/Esi/EsiInterface.php b/app/Client/Ccp/Esi/EsiInterface.php index 23dd5b0..993c3e2 100644 --- a/app/Client/Ccp/Esi/EsiInterface.php +++ b/app/Client/Ccp/Esi/EsiInterface.php @@ -10,51 +10,6 @@ interface EsiInterface { - /** - * @return array - */ - public function getUniverseJumps() : array; - - /** - * @return array - */ - public function getUniverseKills() : array; - - /** - * @return array - */ - public function getUniverseCategories() : array; - - /** - * @param int $categoryId - * @return array - */ - public function getUniverseCategoryData(int $categoryId) : array; - - /** - * @return array - */ - public function getUniverseGroups() : array; - - /** - * @param int $groupId - * @return array - */ - public function getUniverseGroupData(int $groupId) : array; - - /** - * @param int $structureId - * @param string $accessToken - * @return array - */ - public function getUniverseStructureData(int $structureId, string $accessToken) : array; - - /** - * @param int $stationId - * @return array - */ - public function getUniverseStationData(int $stationId) : array; - /** * @param int $typeId * @return array From 9c2e797c616a44b831cda58db4d8fb789979065a Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Tue, 4 Feb 2020 21:29:52 +0100 Subject: [PATCH 46/58] - New "batch" request (parallel async) --- app/Client/Ccp/Esi/Esi.php | 327 ++++++++++++++-------------- app/Client/Ccp/Esi/EsiInterface.php | 62 ------ 2 files changed, 158 insertions(+), 231 deletions(-) diff --git a/app/Client/Ccp/Esi/Esi.php b/app/Client/Ccp/Esi/Esi.php index 0581047..cb3ca02 100644 --- a/app/Client/Ccp/Esi/Esi.php +++ b/app/Client/Ccp/Esi/Esi.php @@ -737,61 +737,64 @@ function($body) : array { /** * @param int $typeId - * @return array + * @return RequestConfig */ - public function getUniverseTypesData(int $typeId) : array { - $uri = $this->getEndpointURI(['universe', 'types', 'GET'], [$typeId]); - $typesData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $typesData = (new Mapper\Universe\Type($response))->getData(); - } + protected function getUniverseTypeRequest(int $typeId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['universe', 'types', 'GET'], [$typeId])), + $this->getRequestOptions(), + function($body) : array { + $typeData = []; + if(!$body->error){ + $typeData = (new Mapper\Universe\Type($body))->getData(); + } - return $typesData; + return $typeData; + } + ); } /** * @param int $attributeId - * @return array + * @return RequestConfig */ - public function getDogmaAttributeData(int $attributeId) : array { - $uri = $this->getEndpointURI(['dogma', 'attributes', 'GET'], [$attributeId]); - $attributeData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if($response->error){ - $attributeData['error'] = $response->error; - }else{ - $attributeData = (new Mapper\Dogma\Attribute($response))->getData(); - } + protected function getDogmaAttributeRequest(int $attributeId) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['dogma', 'attributes', 'GET'], [$attributeId])), + $this->getRequestOptions(), + function($body) : array { + $attributeData = []; + if(!$body->error){ + $attributeData = (new Mapper\Dogma\Attribute($body))->getData(); + }else{ + $attributeData['error'] = $body->error; + } - return $attributeData; + return $attributeData; + } + ); } /** - * @return array + * @return RequestConfig */ - public function getFactionWarSystems() : array { - $uri = $this->getEndpointURI(['fw', 'systems', 'GET']); - $systemsData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if($response->error){ - $systemsData['error'] = $response->error; - }else{ - foreach((array)$response as $data){ - $systemsData['systems'][(int)$data->solar_system_id] = (new Mapper\FactionWarfare\System($data))->getData(); - } - } + protected function getFactionWarSystemsRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['fw', 'systems', 'GET'])), + $this->getRequestOptions(), + function($body) : array { + $systemsData = []; + if(!$body->error){ + foreach((array)$body as $data){ + $systemsData['systems'][(int)$data->solar_system_id] = (new Mapper\FactionWarfare\System($data))->getData(); + } + }else{ + $systemsData['error'] = $body->error; + } - return $systemsData; + return $systemsData; + } + ); } /** @@ -841,84 +844,80 @@ function($body) : array { * @param int $destinationId * @param string $accessToken * @param array $options - * @return array + * @return RequestConfig */ - public function setWaypoint(int $destinationId, string $accessToken, array $options = []) : array { - $uri = $this->getEndpointURI(['ui', 'autopilot', 'waypoint', 'POST']); - $waypointData = []; - - $query = [ - 'add_to_beginning' => var_export( (bool)$options['addToBeginning'], true), - 'clear_other_waypoints' => var_export( (bool)$options['clearOtherWaypoints'], true), - 'destination_id' => $destinationId - ]; - - $requestOptions = $this->getRequestOptions($accessToken, null, $query); - $response = $this->request('POST', $uri, $requestOptions)->getContents(); - - // "null" === success => There is no response body send... - if($response->error){ - $waypointData['error'] = self::ERROR_ESI_WAYPOINT; - } + protected function setWaypointRequest(int $destinationId, string $accessToken, array $options = []) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('POST', $this->getEndpointURI(['ui', 'autopilot', 'waypoint', 'POST'])), + $this->getRequestOptions($accessToken, null, [ + 'add_to_beginning' => var_export( (bool)$options['addToBeginning'], true), + 'clear_other_waypoints' => var_export( (bool)$options['clearOtherWaypoints'], true), + 'destination_id' => $destinationId + ]), + function($body) : array { + $return = []; + // "null" === success => There is no response body send... + if($body->error){ + $return['error'] = self::ERROR_ESI_WAYPOINT; + } - return $waypointData; + return $return; + } + ); } /** * @param int $targetId * @param string $accessToken - * @return array + * @return RequestConfig */ - public function openWindow(int $targetId, string $accessToken) : array { - $uri = $this->getEndpointURI(['ui', 'openwindow', 'information', 'POST']); - $return = []; - - $query = [ - 'target_id' => $targetId - ]; - - $requestOptions = $this->getRequestOptions($accessToken, null, $query); - $response = $this->request('POST', $uri, $requestOptions)->getContents(); - - // "null" === success => There is no response body send... - if( $response->error ){ - $return['error'] = self::ERROR_ESI_WINDOW; - } + protected function openWindowRequest(int $targetId, string $accessToken) : RequestConfig { + return new RequestConfig( + WebClient::newRequest('POST', $this->getEndpointURI(['ui', 'openwindow', 'information', 'POST'])), + $this->getRequestOptions($accessToken, null, [ + 'target_id' => $targetId + ]), + function($body) : array { + $return = []; + // "null" === success => There is no response body send... + if($body->error){ + $return['error'] = self::ERROR_ESI_WINDOW; + } - return $return; + return $return; + } + ); } /** - * @return array + * @return RequestConfig */ - public function getSovereigntyMap() : array { - $uri = $this->getEndpointURI(['sovereignty', 'map', 'GET']); - $sovData = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + protected function getSovereigntyMapRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['sovereignty', 'map', 'GET'])), + $this->getRequestOptions(), + function($body) : array { + $sovData = []; + if(!$body->error){ + foreach((array)$body as $data){ + $sovData['map'][(int)$data->system_id] = (new Mapper\Sovereignty\Map($data))->getData(); + } + }else{ + $sovData['error'] = $body->error; + } - if(!$response->error){ - foreach((array)$response as $data){ - $sovData['map'][(int)$data->system_id] = (new Mapper\Sovereignty\Map($data))->getData(); + return $sovData; } - }else{ - $sovData['error'] = $response->error; - } - - return $sovData; + ); } /** * @param array $categories * @param string $search * @param bool $strict - * @return array + * @return RequestConfig */ - public function search(array $categories, string $search, bool $strict = false) : array { - $uri = $this->getEndpointURI(['search', 'GET']); - $searchData = []; - + protected function searchRequest(array $categories, string $search, bool $strict = false) : RequestConfig { $query = [ 'categories' => $categories, 'search' => $search, @@ -929,100 +928,90 @@ public function search(array $categories, string $search, bool $strict = false) 'categories' => [','] ]); - $requestOptions = $this->getRequestOptions('', null, $query); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if($response->error){ - $searchData['error'] = $response->error; - }else{ - $searchData = (new Mapper\Search\Search($response))->getData(); - } + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['search', 'GET'])), + $this->getRequestOptions('', null, $query), + function($body) : array { + $searchData = []; + if(!$body->error){ + $searchData = (new Mapper\Search\Search($body))->getData(); + }else{ + $searchData['error'] = $body->error; + } - return $searchData; + return $searchData; + } + ); } /** * @param string $version - * @return array + * @param bool $forRoutes + * @return RequestConfig */ - public function getStatus(string $version = 'last') : array { - $uri = $this->getEndpointURI(['meta', 'status', 'GET']); - $statusData = []; - + protected function getStatusRequest(string $version = 'last', bool $forRoutes = false) : RequestConfig { $requestOptions = [ 'query' => [ 'version' => $version ] ]; - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - foreach((array)$response as $status){ - $statusData['status'][] = (new Mapper\Status($status))->getData(); - } - }else{ - $statusData['error'] = $response->error; - } + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['meta', 'status', 'GET'])), + $requestOptions, + function($body) use ($forRoutes) : array { + $statusData = []; + if(!$body->error){ + foreach((array)$body as $status){ + $statusData['status'][] = (new Mapper\Status($status))->getData(); + } - return $statusData; - } + if($forRoutes){ + // data for all configured ESI endpoints + $statusDataRoutes = [ + 'status' => $this->getConfig()->getEndpointsData() + ]; - /** - * @param string $version - * @return array - */ - public function getStatusForRoutes(string $version = 'last') : array { - // data for all configured ESI endpoints - $statusData = [ - 'status' => $this->getConfig()->getEndpointsData() - ]; + foreach((array)$statusDataRoutes['status'] as $key => $data){ + foreach((array)$statusData['status'] as $status){ + if( + $status['route'] == $data['route'] && + $status['method'] == $data['method'] + ){ + $statusDataRoutes['status'][$key]['status'] = $status['status']; + $statusDataRoutes['status'][$key]['tags'] = $status['tags']; + break; + } + } + } - $statusDataAll = $this->getStatus($version); - if(!isset($statusDataAll['error'])){ - foreach((array)$statusData['status'] as $key => $data){ - foreach((array)$statusDataAll['status'] as $status){ - if( - $status['route'] == $data['route'] && - $status['method'] == $data['method'] - ){ - $statusData['status'][$key]['status'] = $status['status']; - $statusData['status'][$key]['tags'] = $status['tags']; - break; + $statusData = $statusDataRoutes; } + }else{ + $statusData['error'] = $body->error; } - } - }else{ - $statusData['error'] = $statusDataAll['error']; - } - - return $statusData; - } - /** - * @param int $corporationId - * @return bool - */ - public function isNpcCorporation(int $corporationId) : bool { - $npcCorporations = $this->getNpcCorporations(); - return in_array($corporationId, $npcCorporations); + return $statusData; + } + ); } /** - * @return array + * @return RequestConfig */ - protected function getNpcCorporations() : array { - $uri = $this->getEndpointURI(['corporations', 'npccorps', 'GET']); - $npcCorporations = []; - - $requestOptions = $this->getRequestOptions(); - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $npcCorporations = $response; - } + protected function getNpcCorporationsRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getEndpointURI(['corporations', 'npccorps', 'GET'])), + $this->getRequestOptions(), + function($body) : array { + $npcCorporations = []; + if(!$body->error){ + $npcCorporations = array_unique(array_map('intval', (array)$body)); + } - return $npcCorporations; + return $npcCorporations; + } + ); } /** diff --git a/app/Client/Ccp/Esi/EsiInterface.php b/app/Client/Ccp/Esi/EsiInterface.php index 993c3e2..003a6ad 100644 --- a/app/Client/Ccp/Esi/EsiInterface.php +++ b/app/Client/Ccp/Esi/EsiInterface.php @@ -10,66 +10,4 @@ interface EsiInterface { - /** - * @param int $typeId - * @return array - */ - public function getUniverseTypesData(int $typeId) : array; - - /** - * @param int $attributeId - * @return array - */ - public function getDogmaAttributeData(int $attributeId) : array; - - /** - * @return array - */ - public function getFactionWarSystems() : array; - - /** - * @param int $destinationId - * @param string $accessToken - * @param array $options - * @return array - */ - public function setWaypoint(int $destinationId, string $accessToken, array $options = []) : array; - - /** - * @param int $targetId - * @param string $accessToken - * @return array - */ - public function openWindow(int $targetId, string $accessToken) : array; - - /** - * @return array - */ - public function getSovereigntyMap() : array; - - /** - * @param array $categories - * @param string $search - * @param bool $strict - * @return array - */ - public function search(array $categories, string $search, bool $strict = false) : array; - - /** - * @param string $version - * @return array - */ - public function getStatus(string $version) : array; - - /** - * @param string $version - * @return array - */ - public function getStatusForRoutes(string $version) : array; - - /** - * @param int $corporationId - * @return bool - */ - public function isNpcCorporation(int $corporationId) : bool; } \ No newline at end of file From 021b57a644efe65dfb1123c89a65f6d926c1f10c Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Tue, 4 Feb 2020 21:41:40 +0100 Subject: [PATCH 47/58] - New "batch" request (parallel async) --- app/Client/Ccp/Sso/Sso.php | 54 ++++++++++++++++------------- app/Client/Ccp/Sso/SsoInterface.php | 13 ------- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/app/Client/Ccp/Sso/Sso.php b/app/Client/Ccp/Sso/Sso.php index a26d08f..2a43626 100644 --- a/app/Client/Ccp/Sso/Sso.php +++ b/app/Client/Ccp/Sso/Sso.php @@ -11,6 +11,8 @@ use Exodus4D\ESI\Client\Ccp; use Exodus4D\ESI\Config\ConfigInterface; use Exodus4D\ESI\Config\Ccp\Sso\Config; +use Exodus4D\ESI\Lib\RequestConfig; +use Exodus4D\ESI\Lib\WebClient; use Exodus4D\ESI\Mapper; class Sso extends Ccp\AbstractCcp implements SsoInterface { @@ -20,23 +22,25 @@ class Sso extends Ccp\AbstractCcp implements SsoInterface { * -> get some basic information (like character id) * -> if more character information is required, use ESI "characters" endpoints request instead * @param string $accessToken - * @return array + * @return RequestConfig */ - public function getVerifyCharacterData(string $accessToken) : array { - $uri = $this->getVerifyUserEndpointURI(); - $characterData = []; - + protected function getVerifyCharacterRequest(string $accessToken) : RequestConfig { $requestOptions = [ 'headers' => $this->getAuthHeader($accessToken, 'Bearer') ]; - $response = $this->request('GET', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $characterData = (new Mapper\Sso\Character($response))->getData(); - } - - return $characterData; + return new RequestConfig( + WebClient::newRequest('GET', $this->getVerifyUserEndpointURI()), + $requestOptions, + function($body) : array { + $characterData = []; + if(!$body->error){ + $characterData = (new Mapper\Sso\Character($body))->getData(); + } + + return $characterData; + } + ); } /** @@ -49,24 +53,26 @@ public function getVerifyCharacterData(string $accessToken) : array { * $requestParams['refresh_token] = 'XXXX' * @param array $credentials * @param array $requestParams - * @return array + * @return RequestConfig */ - public function getAccessData(array $credentials, array $requestParams = []) : array { - $uri = $this->getVerifyAuthorizationCodeEndpointURI(); - $accessData = []; - + protected function getAccessRequest(array $credentials, array $requestParams = []) : RequestConfig { $requestOptions = [ 'json' => $requestParams, 'auth' => $credentials ]; - $response = $this->request('POST', $uri, $requestOptions)->getContents(); - - if(!$response->error){ - $accessData = (new Mapper\Sso\Access($response))->getData(); - } - - return $accessData; + return new RequestConfig( + WebClient::newRequest('POST', $this->getVerifyAuthorizationCodeEndpointURI()), + $requestOptions, + function($body) : array { + $accessData = []; + if(!$body->error){ + $accessData = (new Mapper\Sso\Access($body))->getData(); + } + + return $accessData; + } + ); } /** diff --git a/app/Client/Ccp/Sso/SsoInterface.php b/app/Client/Ccp/Sso/SsoInterface.php index d464e79..7c6565b 100644 --- a/app/Client/Ccp/Sso/SsoInterface.php +++ b/app/Client/Ccp/Sso/SsoInterface.php @@ -10,19 +10,6 @@ interface SsoInterface { - /** - * @param string $accessToken - * @return array - */ - public function getVerifyCharacterData(string $accessToken) : array; - - /** - * @param array $credentials - * @param array $requestParams - * @return array - */ - public function getAccessData(array $credentials, array $requestParams = []) : array; - /** * @return string */ From 2fa83a0898e3816226446625fdc4a65f690e24cf Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Tue, 4 Feb 2020 22:10:38 +0100 Subject: [PATCH 48/58] - New "batch" request (parallel async) --- app/Client/EveScout/EveScout.php | 34 ++++++++------- app/Client/EveScout/EveScoutInterface.php | 4 -- app/Client/GitHub/GitHub.php | 52 +++++++++++++---------- app/Client/GitHub/GitHubInterface.php | 14 ------ 4 files changed, 48 insertions(+), 56 deletions(-) diff --git a/app/Client/EveScout/EveScout.php b/app/Client/EveScout/EveScout.php index dd3d078..7823772 100644 --- a/app/Client/EveScout/EveScout.php +++ b/app/Client/EveScout/EveScout.php @@ -6,28 +6,32 @@ use Exodus4D\ESI\Client; use Exodus4D\ESI\Config\ConfigInterface; use Exodus4D\ESI\Config\EveScout\Config; +use Exodus4D\ESI\Lib\RequestConfig; +use Exodus4D\ESI\Lib\WebClient; use Exodus4D\ESI\Mapper\EveScout as Mapper; class EveScout extends Client\AbstractApi implements EveScoutInterface { /** - * @return array + * @return RequestConfig */ - public function getTheraConnections() : array { - $uri = $this->getConfig()->getEndpoint(['wormholes', 'GET']); - $connectionsData = []; - - $response = $this->request('GET', $uri)->getContents(); - - if($response->error){ - $connectionsData['error'] = $response->error; - }else{ - foreach((array)$response as $data){ - $connectionsData['connections'][(int)$data->id] = (new Mapper\Connection($data))->getData(); + protected function getTheraConnectionsRequest() : RequestConfig { + return new RequestConfig( + WebClient::newRequest('GET', $this->getConfig()->getEndpoint(['wormholes', 'GET'])), + [], + function($body) : array { + $connectionsData = []; + if(!$body->error){ + foreach((array)$body as $data){ + $connectionsData['connections'][(int)$data->id] = (new Mapper\Connection($data))->getData(); + } + }else{ + $connectionsData['error'] = $body->error; + } + + return $connectionsData; } - } - - return $connectionsData; + ); } /** diff --git a/app/Client/EveScout/EveScoutInterface.php b/app/Client/EveScout/EveScoutInterface.php index b2440fa..f58cdbe 100644 --- a/app/Client/EveScout/EveScoutInterface.php +++ b/app/Client/EveScout/EveScoutInterface.php @@ -5,8 +5,4 @@ interface EveScoutInterface { - /** - * @return array - */ - public function getTheraConnections() : array; } \ No newline at end of file diff --git a/app/Client/GitHub/GitHub.php b/app/Client/GitHub/GitHub.php index 044d135..3671d45 100644 --- a/app/Client/GitHub/GitHub.php +++ b/app/Client/GitHub/GitHub.php @@ -11,6 +11,8 @@ use Exodus4D\ESI\Client; use Exodus4D\ESI\Config\ConfigInterface; use Exodus4D\ESI\Config\GitHub\Config; +use Exodus4D\ESI\Lib\RequestConfig; +use Exodus4D\ESI\Lib\WebClient; use Exodus4D\ESI\Mapper; class GitHub extends Client\AbstractApi implements GitHubInterface { @@ -18,12 +20,9 @@ class GitHub extends Client\AbstractApi implements GitHubInterface { /** * @param string $projectName e.g. "exodus4d/pathfinder" * @param int $count - * @return array + * @return RequestConfig */ - public function getProjectReleases(string $projectName, int $count = 1) : array { - $uri = $this->getConfig()->getEndpoint(['releases', 'GET'], [$projectName]); - $releasesData = []; - + protected function getProjectReleasesRequest(string $projectName, int $count = 1) : RequestConfig { $requestOptions = [ 'query' => [ 'page' => 1, @@ -31,26 +30,28 @@ public function getProjectReleases(string $projectName, int $count = 1) : array ] ]; - $response = $this->request('GET', $uri, $requestOptions)->getContents(); + return new RequestConfig( + WebClient::newRequest('GET', $this->getConfig()->getEndpoint(['releases', 'GET'], [$projectName])), + $requestOptions, + function($body) : array { + $releasesData = []; + if(!$body->error){ + foreach((array)$body as $data){ + $releasesData[] = (new Mapper\GitHub\Release($data))->getData(); + } + } - if(!$response->error){ - foreach((array)$response as $data){ - $releasesData[] = (new Mapper\GitHub\Release($data))->getData(); + return $releasesData; } - } - - return $releasesData; + ); } /** * @param string $context * @param string $markdown - * @return string + * @return RequestConfig */ - public function markdownToHtml(string $context, string $markdown) : string { - $uri = $this->getConfig()->getEndpoint(['markdown', 'POST']); - $html = ''; - + protected function markdownToHtmlRequest(string $context, string $markdown) : RequestConfig { $requestOptions = [ 'json_enabled' => false, // disable JSON Middleware 'json' => [ @@ -60,13 +61,18 @@ public function markdownToHtml(string $context, string $markdown) : string { ] ]; - $response = $this->request('POST', $uri, $requestOptions)->getContents(); + return new RequestConfig( + WebClient::newRequest('POST', $this->getConfig()->getEndpoint(['markdown', 'POST'])), + $requestOptions, + function($body) : string { + $html = ''; + if(!$body->error){ + $html = (string)$body; + } - if(!$response->error){ - $html = (string)$response; - } - - return $html; + return $html; + } + ); } /** diff --git a/app/Client/GitHub/GitHubInterface.php b/app/Client/GitHub/GitHubInterface.php index 7ba0fa2..1bfb647 100644 --- a/app/Client/GitHub/GitHubInterface.php +++ b/app/Client/GitHub/GitHubInterface.php @@ -10,18 +10,4 @@ interface GitHubInterface { - /** - * @param string $projectName - * @param int $count - * @return array - */ - public function getProjectReleases(string $projectName, int $count) : array; - - /** - * @param string $context - * @param string $markdown - * @return string - */ - public function markdownToHtml(string $context, string $markdown) : string; - } \ No newline at end of file From 53e4f61db125e92873e15d2349eff4cc3ded148c Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Tue, 4 Feb 2020 22:29:13 +0100 Subject: [PATCH 49/58] - New "batch" request (parallel async) --- app/Client/AbstractApi.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index 0516ff9..ee1e7cc 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -807,6 +807,7 @@ protected function getRetryMiddlewareConfig() : array { * @return RequestConfig|null */ protected function getRequestConfig(string $requestHandler, ...$handlerParams) : ?RequestConfig { + $requestHandler .= 'Request'; if(is_callable([$this, $requestHandler])){ return call_user_func_array([$this, $requestHandler], $handlerParams); } From 633c6ff2e578f8d1d478f67804c5c62a6391d015 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 8 Feb 2020 22:34:16 +0100 Subject: [PATCH 50/58] - New "batch" request (parallel async) --- app/Mapper/EveScout/Connection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index ab12e52..c3bfeed 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -28,6 +28,7 @@ class Connection extends AbstractIterator { 'wormholeMass' => ['wormhole' => 'mass'], 'wormholeEol' => ['wormhole' => 'eol'], + 'wormholeEstimatedEol' => ['wormhole' => 'estimatedEol'], 'createdAt' => ['created' => 'created'], 'updatedAt' => ['updated' => 'updated'] From ccb0363ee7e5d7e06cd37cde41d24abb4eb771e5 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sun, 9 Feb 2020 10:04:10 +0100 Subject: [PATCH 51/58] - New "batch" request (parallel async) --- app/Mapper/EveScout/Connection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index c3bfeed..cbab446 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -31,6 +31,7 @@ class Connection extends AbstractIterator { 'wormholeEstimatedEol' => ['wormhole' => 'estimatedEol'], 'createdAt' => ['created' => 'created'], + 'createdById' => ['created' => ['character' => 'id']], 'updatedAt' => ['updated' => 'updated'] ]; } \ No newline at end of file From 5a936c42d558d5917b5122bc0c83825f8a58f2ea Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sun, 9 Feb 2020 10:07:36 +0100 Subject: [PATCH 52/58] - New "batch" request (parallel async) --- app/Mapper/EveScout/Connection.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index cbab446..0a0838b 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -31,7 +31,9 @@ class Connection extends AbstractIterator { 'wormholeEstimatedEol' => ['wormhole' => 'estimatedEol'], 'createdAt' => ['created' => 'created'], - 'createdById' => ['created' => ['character' => 'id']], - 'updatedAt' => ['updated' => 'updated'] + 'updatedAt' => ['updated' => 'updated'], + + 'createdById' => ['createdCharacter' => 'id'], + 'createdBy' => ['createdCharacter' => 'name'] ]; } \ No newline at end of file From f6be92e1c15a21f2e3795c180cf644fb5b6f09c0 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sun, 9 Feb 2020 10:17:16 +0100 Subject: [PATCH 53/58] - New "batch" request (parallel async) --- app/Mapper/EveScout/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index 0a0838b..2a0d8cb 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -33,7 +33,7 @@ class Connection extends AbstractIterator { 'createdAt' => ['created' => 'created'], 'updatedAt' => ['updated' => 'updated'], - 'createdById' => ['createdCharacter' => 'id'], - 'createdBy' => ['createdCharacter' => 'name'] + 'createdById' => ['character' => 'id'], + 'createdBy' => ['character' => 'name'] ]; } \ No newline at end of file From 1fe374d0c2faf85522e49d1c81d753463493e463 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 15 Feb 2020 14:07:06 +0100 Subject: [PATCH 54/58] - New "batch" request (parallel async) --- app/Lib/Middleware/GuzzleLogMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Lib/Middleware/GuzzleLogMiddleware.php b/app/Lib/Middleware/GuzzleLogMiddleware.php index 1294b60..d52ea3b 100644 --- a/app/Lib/Middleware/GuzzleLogMiddleware.php +++ b/app/Lib/Middleware/GuzzleLogMiddleware.php @@ -367,7 +367,7 @@ protected function logCache(ResponseInterface $response, array $options) : array } return [ - 'status' => $cacheStatusHeader + 'status' => $response->getHeaders() //$cacheStatusHeader ]; } From 5f19a2e3b7336a434042acb2f7ff3f32c1d5a8ee Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 15 Feb 2020 15:06:29 +0100 Subject: [PATCH 55/58] - Improved "GuzzleLogMiddleware" new public methods to en/disable logging for req/res HTTP headers (raw format) `setLogRequestHeaders()` `setLogResponseHeaders` --- app/Client/AbstractApi.php | 26 ++++++++++++++ app/Lib/Middleware/GuzzleLogMiddleware.php | 40 ++++++++++++++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/app/Client/AbstractApi.php b/app/Client/AbstractApi.php index ee1e7cc..b822e44 100644 --- a/app/Client/AbstractApi.php +++ b/app/Client/AbstractApi.php @@ -227,6 +227,16 @@ abstract class AbstractApi extends \Prefab implements ApiInterface { */ private $logCacheHeader = GuzzleLogMiddleware::DEFAULT_LOG_CACHE_HEADER; + /** + * @var GuzzleLogMiddleware::DEFAULT_LOG_REQUEST_HEADERS + */ + private $logRequestHeaders = GuzzleLogMiddleware::DEFAULT_LOG_REQUEST_HEADERS; + + /** + * @var GuzzleLogMiddleware::DEFAULT_LOG_RESPONSE_HEADERS + */ + private $logResponseHeaders = GuzzleLogMiddleware::DEFAULT_LOG_RESPONSE_HEADERS; + /** * @see GuzzleLogMiddleware::DEFAULT_LOG_ALL_STATUS * @var bool @@ -480,6 +490,20 @@ public function setLogAllStatus(bool $logAllStatus = GuzzleLogMiddleware::DEFAUL $this->logAllStatus = $logAllStatus; } + /** + * @param bool $logRequestHeaders + */ + public function setLogRequestHeaders(bool $logRequestHeaders = GuzzleLogMiddleware::DEFAULT_LOG_REQUEST_HEADERS){ + $this->logRequestHeaders = $logRequestHeaders; + } + + /** + * @param bool $logResponseHeaders + */ + public function setLogResponseHeaders(bool $logResponseHeaders = GuzzleLogMiddleware::DEFAULT_LOG_RESPONSE_HEADERS){ + $this->logResponseHeaders = $logResponseHeaders; + } + /** * GuzzleLogMiddleware config * @param string $logFile @@ -736,6 +760,8 @@ protected function getLogMiddlewareConfig() : array { 'log_stats' => $this->logStats, 'log_cache' => $this->logCache, 'log_cache_header' => $this->logCacheHeader, + 'log_request_headers' => $this->logRequestHeaders, + 'log_response_headers' => $this->logResponseHeaders, 'log_5xx' => true, 'log_4xx' => true, 'log_all_status' => $this->logAllStatus, diff --git a/app/Lib/Middleware/GuzzleLogMiddleware.php b/app/Lib/Middleware/GuzzleLogMiddleware.php index d52ea3b..8e78aa0 100644 --- a/app/Lib/Middleware/GuzzleLogMiddleware.php +++ b/app/Lib/Middleware/GuzzleLogMiddleware.php @@ -47,6 +47,16 @@ class GuzzleLogMiddleware { */ const DEFAULT_LOG_CACHE_HEADER = 'X-Guzzle-Cache'; + /** + * default for: log all requests HTTP headers + */ + const DEFAULT_LOG_REQUEST_HEADERS = false; + + /** + * default for: log all response HTTP headers + */ + const DEFAULT_LOG_RESPONSE_HEADERS = false; + /** * default for: log requests with HTTP 5xx response */ @@ -115,6 +125,8 @@ class GuzzleLogMiddleware { 'log_stats' => self::DEFAULT_LOG_STATS, 'log_cache' => self::DEFAULT_LOG_CACHE, 'log_cache_header' => self::DEFAULT_LOG_CACHE_HEADER, + 'log_request_headers' => self::DEFAULT_LOG_REQUEST_HEADERS, + 'log_response_headers' => self::DEFAULT_LOG_RESPONSE_HEADERS, 'log_5xx' => self::DEFAULT_LOG_5XX, 'log_4xx' => self::DEFAULT_LOG_4XX, 'log_3xx' => self::DEFAULT_LOG_3XX, @@ -255,7 +267,7 @@ protected function log(array $options, RequestInterface $request, ?ResponseInter if(!is_null($response)){ $statusCode = $response->getStatusCode(); if($logError || $this->checkStatusCode($options, $statusCode)){ - $logData['response'] = $this->logResponse($response); + $logData['response'] = $this->logResponse($response, $options); if($options['log_cache']){ $logData['cache'] = $this->logCache($response, $options); @@ -280,7 +292,7 @@ protected function log(array $options, RequestInterface $request, ?ResponseInter } if($logRequestData){ - $logData['request'] = $this->logRequest($request); + $logData['request'] = $this->logRequest($request, $options); } // log stats in case other logData should be logged @@ -296,10 +308,11 @@ protected function log(array $options, RequestInterface $request, ?ResponseInter /** * log request * @param RequestInterface $request + * @param array $options * @return array */ - protected function logRequest(RequestInterface $request) : array { - return [ + protected function logRequest(RequestInterface $request, array $options) : array { + $logData = [ 'method' => $request->getMethod(), 'url' => $request->getUri()->__toString(), 'host' => $request->getUri()->getHost(), @@ -307,24 +320,37 @@ protected function logRequest(RequestInterface $request) : array { 'target' => $request->getRequestTarget(), 'version' => $request->getProtocolVersion() ]; + + if($options['log_request_headers']){ + $logData['requestHeaders'] = $request->getHeaders(); + } + + return $logData; } /** * log response -> this might be a HTTP 1xx up to 5xx response * @param ResponseInterface $response + * @param array $options * @return array */ - protected function logResponse(ResponseInterface $response) : array { + protected function logResponse(ResponseInterface $response, array $options) : array { // response body might contain additional error message $errorMessage = $this->getErrorMessageFromResponseBody($response); - return [ + $logData = [ 'code' => $response->getStatusCode(), 'phrase' => $response->getReasonPhrase(), 'version' => $response->getProtocolVersion(), 'res_header_content-length' => $response->getHeaderLine('content-length'), 'error_msg' => $errorMessage ]; + + if($options['log_response_headers']){ + $logData['responseHeaders'] = $response->getHeaders(); + } + + return $logData; } /** @@ -367,7 +393,7 @@ protected function logCache(ResponseInterface $response, array $options) : array } return [ - 'status' => $response->getHeaders() //$cacheStatusHeader + 'status' => $cacheStatusHeader ]; } From ddacd9477d43500c1785f85542c6c7d3b27a2b54 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Fri, 28 Feb 2020 19:48:33 +0100 Subject: [PATCH 56/58] - added endpoint "getTheraConnections()" --- app/Mapper/EveScout/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Mapper/EveScout/Connection.php b/app/Mapper/EveScout/Connection.php index 2a0d8cb..c6c0170 100644 --- a/app/Mapper/EveScout/Connection.php +++ b/app/Mapper/EveScout/Connection.php @@ -30,8 +30,8 @@ class Connection extends AbstractIterator { 'wormholeEol' => ['wormhole' => 'eol'], 'wormholeEstimatedEol' => ['wormhole' => 'estimatedEol'], - 'createdAt' => ['created' => 'created'], - 'updatedAt' => ['updated' => 'updated'], + 'createdAt' => 'created', + 'updatedAt' => 'updated', 'createdById' => ['character' => 'id'], 'createdBy' => ['character' => 'name'] From 0f70cfa560779725d07dffb2bf67312ef00a40e4 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Fri, 20 Mar 2020 13:51:44 +0100 Subject: [PATCH 57/58] Update README.md --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6dfabb5..70ee5ba 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,10 @@ This Web API client library is used by [_Pathfinder_](https://github.com/exodus4d/pathfinder) and handles all _ESI_ API requests.
Additional APIs can easily be added and can be used side by side with their own configuration. Included clients: -- _CCP ESI_ API client: [ESI.php](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Client/ESI.php) -- _CCP SSO_ API client: [SSO.php](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Client/SSO.php) -- _GitHub_ basic API client: [Github.php](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Client/Github.php) +- _CCP ESI_ API client: [Esi.php](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Client/Ccp/Esi/Esi.php) +- _CCP SSO_ API client: [Sso.php](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Client/Ccp/Sso/Sso.php) +- _GitHub_ basic API client: [GitHub.php](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Client/GitHub/GitHub.php) +- _eve-scout_ _"Thera"_ API client: [EveScout.php](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Client/EveScout/EveScout.php) This Web client is build on [_Guzzle_](http://guzzlephp.org) and makes much use of the build in [_Middleware_](http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#middleware) concept in _Guzzle_. @@ -14,8 +15,8 @@ Use [_Composer_](https://getcomposer.org/) for installation. In `composer.json` ```json { "require": { - "php-64bit": ">=7.1", - "exodus4d/pathfinder_esi": "dev-master#v1.2.5" + "php-64bit": ">=7.2", + "exodus4d/pathfinder_esi": "v2.0.0" } } ``` @@ -90,7 +91,7 @@ _Middlewares_ classes are _small_ functions that _hook_ into the "request → re - The **order** in the `HandlerStack()` is essential! ### _Guzzle_ [_HandlerStack_](http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#handlerstack) : -This flowchart shows all _Middlewares_ used by [ESI.php](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Client/ESI.php) API client. +This flowchart shows all _Middlewares_ used by [ESI.php](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Client/Ccp/Esi/Esi.php) API client. Each request to _ESI_ API invokes all _Middlewares_ in the following **order**: ##### Before request [GuzzleJsonMiddleware](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Lib/Middleware/GuzzleJsonMiddleware.php) → From 06ebb9e2718b41282374cff23e5eaa500d224d6a Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Fri, 20 Mar 2020 14:03:37 +0100 Subject: [PATCH 58/58] Update README.md --- README.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 70ee5ba..fc51bdc 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Check _Pathfinder_ [release](https://github.com/exodus4d/pathfinder/releases) n ```php // New web client instance for GitHub API [→ Github() implements ApiInterface()] -$client = new \Exodus4D\ESI\Client\Github('https://api.github.com'); +$client = new \Exodus4D\ESI\Client\GitHub\GitHub('https://api.github.com'); // configure client [→ check ApiInterface() for methods] $client->setTimeout(3); // Timeout of the request (seconds) @@ -52,20 +52,22 @@ $client->setIsLoggable(function() : \Closure { }; }); -$client->setLogStats(true); // Add some cURL status information (e.g. transferTime) to logged responses +$client->setLogStats(true); // add some cURL status information (e.g. transferTime) to logged responses -$client->setLogCache(true); // Add (local) cache info (e.g. response data cached) to logged requests -// $client->setLogAllStatus(true); // Log all requests regardless of response HTTP status code -$client->setLogFile('requests'); // Log file name for request/response errors -$client->setRetryLogFile('retry_requests'); // Log file for requests errors due to max request retry exceeds +$client->setLogCache(true); // add (local) cache info (e.g. response data cached) to logged requests +$client->setLogAllStatus(false); // log all requests regardless of response HTTP status code +$client->setLogRequestHeaders(false); // add request HTTP headers to loggable requests +$client->setLogResponseHeaders(false); // add response HTTP headers to loggable requests +$client->setLogFile('requests'); // log file name for request/response errors +$client->setRetryLogFile('retry_requests'); // log file for requests errors due to max request retry exceeds -$client->setCacheDebug(true); // Add debug HTTP Header with local cache status information (HIT/MISS) +$client->setCacheDebug(true); // add debug HTTP Header with local cache status information (HIT/MISS) $client->setCachePool(function() : \Closure { return function() : ?CacheItemPoolInterface { $client = new \Redis(); // Cache backend used accross the web client $client->connect('localhost', 6379); - // → more PSR-6 compatible adapters at www.php-cache.com (e.g. Filesystem, Array,..) + // → more PSR-6 compatible adapters at www.php-cache.com (e.g. Filesystem, Array,…) $poolRedis = new RedisCachePool($client); $cachePool = new NamespacedCachePool($poolRedis, 'myCachePoolName'); return $cachePool; // This can be any PSR-6 compatible instance of CacheItemPoolInterface() @@ -76,8 +78,8 @@ $client->setCachePool(function() : \Closure { #### 2. Send requests ```php // get all releases from GitHub for a repo -$releases = $client->getProjectReleases('exodus4d/pathfinder'); -// .. more requests here ... +$releases = $client->send('getProjectReleases', 'exodus4d/pathfinder'); +// … more requests here ``` ## Concept @@ -85,7 +87,7 @@ $releases = $client->getProjectReleases('exodus4d/pathfinder'); _Middlewares_ classes are _small_ functions that _hook_ into the "request → response" chain in _Guzzle_. - A _Middleware_ can _manipulate_ the `request` and `response` objects - Each _Middleware_ is dedicated to handles its own task. -- There are _Middlewares_ for "logging", "caching",... pre-configured. +- There are _Middlewares_ for "logging", "caching",… pre-configured. - Each _Middleware_ has its own set of config options that can be set through the `$client->`. - All configured _Middlewares_ are pushed into a [_HandlerStack()_](http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#handlerstack) that gets _resolved_ for **each** request. - The **order** in the `HandlerStack()` is essential! @@ -121,7 +123,7 @@ A client instance _should_ be set up with a [_PSR-6_](https://www.php-fig.org/ps Valid `response` data can be cached by its `Cache-Expire` HTTP Header. [GuzzleCacheMiddleware](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Lib/Middleware/GuzzleCacheMiddleware.php) also handle `Etag` Headers. Other _Middlewares_ can also access the cache pool for their needs. -E.g. [GuzzleLogMiddleware](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Lib/Middleware/GuzzleLogMiddleware.php) can _throttle_ error logging by using the cache pool for error counts,.. +E.g. [GuzzleLogMiddleware](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Lib/Middleware/GuzzleLogMiddleware.php) can _throttle_ error logging by using the cache pool for error counts,… → See: `$client->setCachePool();` > **Hint:** Check out [www.php-cache.com](http://www.php-cache.com) for _PSR-6_ compatible cache pools. @@ -134,7 +136,7 @@ Other _Middlewares_ also have access to the _global_ new log callback and implem `$client->setNewLog();` #### Retry -Requests result in an _expected_ error (timeouts, _cURL_ connect errors,.. ) will be retried [default: 2 times → configurable!]. +Requests result in an _expected_ error (timeouts, _cURL_ connect errors,… ) will be retried [default: 2 times → configurable!]. Check out [GuzzleRetryMiddleware](https://github.com/exodus4d/pathfinder_esi/blob/master/app/Lib/Middleware/GuzzleRetryMiddleware.php) for more information. ### _CCP ESI_ exclusive _Middlewares_: