diff --git a/app/ApiInterface.php b/app/ApiInterface.php index 63ac054..756ccf6 100644 --- a/app/ApiInterface.php +++ b/app/ApiInterface.php @@ -26,20 +26,20 @@ public function getUserAgent(); /** * @return array */ - public function getServerStatus(): array; + public function getServerStatus() : array; /** * get corporation/alliance ids by characterIds * @param array $characterIds * @return array */ - public function getCharacterAffiliationData(array $characterIds): array; + public function getCharacterAffiliationData(array $characterIds) : array; /** * @param int $characterId * @return array */ - public function getCharacterData(int $characterId): array; + public function getCharacterData(int $characterId) : array; /** * @param int $characterId @@ -47,7 +47,7 @@ public function getCharacterData(int $characterId): array; * @param array $additionalOptions * @return array */ - public function getCharacterLocationData(int $characterId, string $accessToken, array $additionalOptions = []): array; + public function getCharacterLocationData(int $characterId, string $accessToken, array $additionalOptions = []) : array; /** * @param int $characterId @@ -55,7 +55,7 @@ public function getCharacterLocationData(int $characterId, string $accessToken, * @param array $additionalOptions * @return array */ - public function getCharacterShipData(int $characterId, string $accessToken, array $additionalOptions = []): array; + public function getCharacterShipData(int $characterId, string $accessToken, array $additionalOptions = []) : array; /** * @param int $characterId @@ -63,73 +63,116 @@ public function getCharacterShipData(int $characterId, string $accessToken, arra * @param array $additionalOptions * @return array */ - public function getCharacterOnlineData(int $characterId, string $accessToken, array $additionalOptions = []): array; + public function getCharacterOnlineData(int $characterId, string $accessToken, array $additionalOptions = []) : array; /** * @param int $corporationId * @return array */ - public function getCorporationData(int $corporationId): array; + public function getCorporationData(int $corporationId) : array; /** * @param int $allianceId * @return array */ - public function getAllianceData(int $allianceId): array; + public function getAllianceData(int $allianceId) : array; /** - * @param int $systemId + * @param int $corporationId * @param string $accessToken - * @param array $options * @return array */ - public function setWaypoint(int $systemId, string $accessToken, array $options = []): array; + public function getCorporationRoles(int $corporationId, string $accessToken) : array; /** - * @param int $corporationId - * @param string $accessToken * @return array */ - public function getCorporationRoles(int $corporationId, string $accessToken): array; + public function getUniverseRegions() : array; /** + * @param int $regionId * @return array */ - public function getRegions(): array; + public function getUniverseRegionData(int $regionId) : array; /** - * @param int $regionId * @return array */ - public function getRegionData(int $regionId): array; + public function getUniverseConstellations() : array; /** + * @param int $constellationId * @return array */ - public function getConstellations(): array; + public function getUniverseConstellationData(int $constellationId) : array; /** - * @param int $constellationId * @return array */ - public function getConstellationData(int $constellationId): 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 * @param array $additionalOptions * @return array */ - public function getUniverseNamesData(array $universeIds, array $additionalOptions = []): array; + public function getUniverseNamesData(array $universeIds, array $additionalOptions = []) : array; + + /** + * @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 getUniverseJumps(): array; + public function getUniverseGroups() : array; /** + * @param int $groupId * @return array */ - public function getUniverseKills(): array; + public function getUniverseGroupData(int $groupId) : array; /** * @param int $structureId @@ -137,33 +180,49 @@ public function getUniverseKills(): array; * @param array $additionalOptions * @return array */ - public function getUniverseStructureData(int $structureId, string $accessToken, array $additionalOptions = []): array; + public function getUniverseStructureData(int $structureId, string $accessToken, array $additionalOptions = []) : array; /** * @param int $typeId * @param array $additionalOptions * @return array */ - public function getUniverseTypesData(int $typeId, array $additionalOptions = []): array; + public function getUniverseTypesData(int $typeId, array $additionalOptions = []) : array; /** + * @param int $sourceId * @param int $targetId + * @param array $options + * @return array + */ + public function getRouteData(int $sourceId, int $targetId, array $options = []) : array; + + /** + * @param int $systemId * @param string $accessToken + * @param array $options * @return array */ - public function openWindow(int $targetId, string $accessToken): array; - + public function setWaypoint(int $systemId, string $accessToken, array $options = []) : array; + /** - * @param int $sourceId * @param int $targetId - * @param array $options + * @param string $accessToken * @return array */ - public function getRouteData(int $sourceId, int $targetId, array $options = []): array; + public function openWindow(int $targetId, string $accessToken) : array; /** + * @param array $categories + * @param string $search + * @param bool $strict + * @return array + */ + public function search(array $categories, string $search, bool $strict = false) : array; + + /** * @param int $corporationId * @return bool */ - public function isNpcCorporation(int $corporationId): bool; + public function isNpcCorporation(int $corporationId) : bool; } \ No newline at end of file diff --git a/app/Config/ESIConf.php b/app/Config/ESIConf.php index babebd2..c774294 100644 --- a/app/Config/ESIConf.php +++ b/app/Config/ESIConf.php @@ -64,8 +64,35 @@ class ESIConf extends \Prefab { 'GET' => '/v1/universe/constellations/' ] ], + 'systems' => [ + 'GET' => '/v4/universe/systems/{x}/', + 'list' => [ + 'GET' => '/v1/universe/systems/' + ] + ], + 'stars' => [ + 'GET' => '/v1/universe/stars/{x}/' + ], + 'planets' => [ + 'GET' => '/v1/universe/planets/{x}/' + ], + 'stargates' => [ + 'GET' => '/v1/universe/stargates/{x}/' + ], 'structures' => [ - 'GET' => '/v1/universe/structures/{x}/', + 'GET' => '/v2/universe/structures/{x}/' + ], + 'categories' => [ + 'GET' => '/v1/universe/categories/{x}/', + 'list' => [ + 'GET' => '/v1/universe/categories/' + ] + ], + 'groups' => [ + 'GET' => '/v1/universe/groups/{x}/', + 'list' => [ + 'GET' => '/v1/universe/groups/' + ] ], 'types' => [ 'GET' => '/v3/universe/types/{x}/' @@ -85,6 +112,9 @@ class ESIConf extends \Prefab { 'POST' => '/v1/ui/openwindow/information/' ] ] + ], + 'search' => [ + 'GET' => '/v2/search/' ] ]; diff --git a/app/ESI.php b/app/ESI.php index b737bd5..24f4561 100644 --- a/app/ESI.php +++ b/app/ESI.php @@ -19,6 +19,16 @@ class ESI implements ApiInterface { const ERROR_ESI_WAYPOINT = 'Could not set waypoint.'; const ERROR_ESI_WINDOW = 'Could not open client window.'; + /** + * default debug level + */ + const DEFAULT_DEBUG_LEVEL = 0; + + /** + * default for: log any ESI request to log file + */ + const DEFAULT_DEBUG_LOG_REQUESTS = false; + /** * @var string $esiUrl Base ESI Domain (required) * @var string $esiUserAgent User-Agent Header (required) @@ -31,7 +41,13 @@ class ESI implements ApiInterface { * debugLevel * @var int */ - private $debugLevel = 0; + private $debugLevel = self::DEFAULT_DEBUG_LEVEL; + + /** + * log requests + * @var bool + */ + private $debugLogRequests = self::DEFAULT_DEBUG_LOG_REQUESTS; /** * ESI constructor. @@ -63,10 +79,18 @@ public function setDatasource(string $datasource){ /** * @param int $debug */ - public function setDebugLevel(int $debug){ + public function setDebugLevel(int $debug = self::DEFAULT_DEBUG_LEVEL){ $this->debugLevel = $debug; } + /** + * log any requests to log file + * @param bool $logRequests + */ + public function setDebugLogRequests(bool $logRequests = self::DEFAULT_DEBUG_LOG_REQUESTS){ + $this->debugLogRequests = $logRequests; + } + /** * @param string $version */ @@ -77,42 +101,49 @@ public function setVersion(string $version){ /** * @return string */ - public function getUrl(): string{ + public function getUrl() : string{ return $this->esiUrl; } /** * @return string */ - public function getUserAgent(): string{ + public function getUserAgent() : string{ return $this->esiUserAgent; } /** * @return string */ - public function getDatasource(): string{ + public function getDatasource() : string{ return $this->esiDatasource; } /** * @return int */ - public function getDebugLevel(): int { + public function getDebugLevel() : int { return $this->debugLevel; } + /** + * @return bool + */ + public function getDebugLogRequests() : bool { + return $this->debugLogRequests; + } + /** * @return string */ - public function getVersion(): string{ + public function getVersion() : string{ return $this->endpointVersion; } /** * @return array */ - public function getServerStatus(): array{ + public function getServerStatus() : array { $url = $this->getEndpointURL(['status', 'GET']); $serverStatus = []; $response = $this->request($url, 'GET'); @@ -128,7 +159,7 @@ public function getServerStatus(): array{ * @param array $characterIds * @return array */ - public function getCharacterAffiliationData(array $characterIds): array{ + public function getCharacterAffiliationData(array $characterIds) : array { $url = $this->getEndpointURL(['characters', 'affiliation', 'POST']); $characterAffiliationData = []; @@ -150,7 +181,7 @@ public function getCharacterAffiliationData(array $characterIds): array{ * @param int $characterId * @return array */ - public function getCharacterData(int $characterId): array{ + public function getCharacterData(int $characterId) : array { $url = $this->getEndpointURL(['characters', 'GET'], [$characterId]); $characterData = []; $response = $this->request($url, 'GET'); @@ -171,7 +202,7 @@ public function getCharacterData(int $characterId): array{ * @param array $additionalOptions * @return array */ - public function getCharacterLocationData(int $characterId, string $accessToken, array $additionalOptions = []): array{ + public function getCharacterLocationData(int $characterId, string $accessToken, array $additionalOptions = []) : array { $url = $this->getEndpointURL(['characters', 'location', 'GET'], [$characterId]); $locationData = []; $response = $this->request($url, 'GET', $accessToken, $additionalOptions); @@ -189,7 +220,7 @@ public function getCharacterLocationData(int $characterId, string $accessToken, * @param array $additionalOptions * @return array */ - public function getCharacterShipData(int $characterId, string $accessToken, array $additionalOptions = []): array{ + public function getCharacterShipData(int $characterId, string $accessToken, array $additionalOptions = []) : array { $url = $this->getEndpointURL(['characters', 'ship', 'GET'], [$characterId]); $shipData = []; $response = $this->request($url, 'GET', $accessToken, $additionalOptions); @@ -207,7 +238,7 @@ public function getCharacterShipData(int $characterId, string $accessToken, arra * @param array $additionalOptions * @return array */ - public function getCharacterOnlineData(int $characterId, string $accessToken, array $additionalOptions = []): array{ + public function getCharacterOnlineData(int $characterId, string $accessToken, array $additionalOptions = []) : array { $url = $this->getEndpointURL(['characters', 'online', 'GET'], [$characterId]); $onlineData = []; $response = $this->request($url, 'GET', $accessToken, $additionalOptions); @@ -223,7 +254,7 @@ public function getCharacterOnlineData(int $characterId, string $accessToken, ar * @param int $corporationId * @return array */ - public function getCorporationData(int $corporationId): array{ + public function getCorporationData(int $corporationId) : array { $url = $this->getEndpointURL(['corporations', 'GET'], [$corporationId]); $corporationData = []; $response = $this->request($url, 'GET'); @@ -242,7 +273,7 @@ public function getCorporationData(int $corporationId): array{ * @param int $allianceId * @return array */ - public function getAllianceData(int $allianceId): array{ + public function getAllianceData(int $allianceId) : array { $url = $this->getEndpointURL(['alliances', 'GET'], [$allianceId]); $allianceData = []; $response = $this->request($url, 'GET'); @@ -257,43 +288,12 @@ public function getAllianceData(int $allianceId): array{ return $allianceData; } - /** - * @param int $systemId - * @param string $accessToken - * @param array $options - * @return array - */ - public function setWaypoint(int $systemId, string $accessToken, array $options = []): array{ - $urlParams = [ - 'add_to_beginning' => var_export( (bool)$options['addToBeginning'], true), - 'clear_other_waypoints' => var_export( (bool)$options['clearOtherWaypoints'], true), - 'destination_id' => $systemId - ]; - - $url = $this->getEndpointURL(['ui', 'autopilot', 'waypoint', 'POST'], [], $urlParams); - $waypointData = []; - - // need to be send in "content" vars as well! Otherwise "Content-Length" header is not send - $additionalOptions = [ - 'content' => $urlParams - ]; - - $response = $this->request($url, 'POST', $accessToken, $additionalOptions); - - // "null" === success => There is no response body send... - if( !is_null($response) ){ - $waypointData['error'] = self::ERROR_ESI_WAYPOINT; - } - - return $waypointData; - } - /** * @param int $corporationId * @param string $accessToken * @return array */ - public function getCorporationRoles(int $corporationId, string $accessToken): array{ + public function getCorporationRoles(int $corporationId, string $accessToken) : array { $url = $this->getEndpointURL(['corporations', 'roles', 'GET'], [$corporationId]); $rolesData = []; $response = $this->request($url, 'GET', $accessToken); @@ -310,7 +310,7 @@ public function getCorporationRoles(int $corporationId, string $accessToken): ar /** * @return array */ - public function getRegions(): array{ + public function getUniverseRegions() : array { $url = $this->getEndpointURL(['universe', 'regions', 'list', 'GET']); $regionData = []; $response = $this->request($url, 'GET'); @@ -326,7 +326,7 @@ public function getRegions(): array{ * @param int $regionId * @return array */ - public function getRegionData(int $regionId): array{ + public function getUniverseRegionData(int $regionId) : array { $url = $this->getEndpointURL(['universe', 'regions', 'GET'], [$regionId]); $regionData = []; $response = $this->request($url, 'GET'); @@ -341,7 +341,7 @@ public function getRegionData(int $regionId): array{ /** * @return array */ - public function getConstellations(): array{ + public function getUniverseConstellations() : array{ $url = $this->getEndpointURL(['universe', 'constellations', 'list', 'GET']); $constellationData = []; $response = $this->request($url, 'GET'); @@ -357,7 +357,7 @@ public function getConstellations(): array{ * @param int $constellationId * @return array */ - public function getConstellationData(int $constellationId): array{ + public function getUniverseConstellationData(int $constellationId) : array { $url = $this->getEndpointURL(['universe', 'constellations', 'GET'], [$constellationId]); $constellationData = []; $response = $this->request($url, 'GET'); @@ -369,12 +369,94 @@ public function getConstellationData(int $constellationId): array{ return $constellationData; } + /** + * @return array + */ + public function getUniverseSystems() : array{ + $url = $this->getEndpointURL(['universe', 'systems', 'list', 'GET']); + $systemData = []; + $response = $this->request($url, 'GET'); + + if( !empty($response) ){ + $systemData = array_unique( array_map('intval', $response) ); + } + + return $systemData; + } + + /** + * @param int $systemId + * @return array + */ + public function getUniverseSystemData(int $systemId) : array { + $url = $this->getEndpointURL(['universe', 'systems', 'GET'], [$systemId]); + $systemData = []; + $response = $this->request($url, 'GET'); + + if( !empty($response) ){ + $systemData = (new namespace\Mapper\System($response))->getData(); + } + + return $systemData; + } + + /** + * @param int $starId + * @return array + */ + public function getUniverseStarData(int $starId) : array { + $url = $this->getEndpointURL(['universe', 'stars', 'GET'], [$starId]); + $starData = []; + $response = $this->request($url, 'GET'); + + if( !empty($response) ){ + $starData = (new namespace\Mapper\Universe\Star($response))->getData(); + if( !empty($starData) ){ + $starData['id'] = $starId; + } + } + + return $starData; + } + + /** + * @param int $planetId + * @return array + */ + public function getUniversePlanetData(int $planetId) : array { + $url = $this->getEndpointURL(['universe', 'planets', 'GET'], [$planetId]); + $planetData = []; + $response = $this->request($url, 'GET'); + + if( !empty($response) ){ + $planetData = (new namespace\Mapper\Universe\Planet($response))->getData(); + } + + return $planetData; + } + + /** + * @param int $stargateId + * @return array + */ + public function getUniverseStargateData(int $stargateId) : array { + $url = $this->getEndpointURL(['universe', 'stargates', 'GET'], [$stargateId]); + $stargateData = []; + $response = $this->request($url, 'GET'); + + if( !empty($response) ){ + $stargateData = (new namespace\Mapper\Universe\Stargate($response))->getData(); + } + + return $stargateData; + } + /** * @param array $universeIds * @param array $additionalOptions * @return array */ - public function getUniverseNamesData(array $universeIds, array $additionalOptions = []): array{ + public function getUniverseNamesData(array $universeIds, array $additionalOptions = []) : array { $url = $this->getEndpointURL(['universe', 'names', 'POST']); $universeData = []; @@ -382,22 +464,39 @@ public function getUniverseNamesData(array $universeIds, array $additionalOption $response = $this->request($url, 'POST', '', $additionalOptions); - if( !empty($response) ){ + if($response->error){ + $universeData['error'] = $response->error; + }elseif( !empty($response) ){ foreach((array)$response as $data){ - switch($data->category){ + // store category because $data get changed in Mappers + $category = $data->category; + switch($category){ + case 'character': + $categoryData = (new namespace\Mapper\Character($data))->getData(); + break; + case 'alliance': + $categoryData = (new namespace\Mapper\Alliance($data))->getData(); + break; + case 'corporation': + $categoryData = (new namespace\Mapper\Corporation($data))->getData(); + break; case 'station': $categoryData = (new namespace\Mapper\Station($data))->getData(); break; case 'solar_system': + $category = 'system'; $categoryData = (new namespace\Mapper\System($data))->getData(); break; case 'inventory_type': + $category = 'inventoryType'; $categoryData = (new namespace\Mapper\InventoryType($data))->getData(); break; default: $categoryData = []; } - $universeData += $categoryData; + if( !empty($categoryData) ){ + $universeData[$category][] = $categoryData; + } } } @@ -407,7 +506,7 @@ public function getUniverseNamesData(array $universeIds, array $additionalOption /** * @return array */ - public function getUniverseJumps(): array{ + public function getUniverseJumps() : array { $url = $this->getEndpointURL(['universe', 'system_jumps', 'GET']); $systemJumps = []; @@ -425,7 +524,7 @@ public function getUniverseJumps(): array{ /** * @return array */ - public function getUniverseKills(): array{ + public function getUniverseKills() : array { $url = $this->getEndpointURL(['universe', 'system_kills', 'GET']); $systemKills = []; @@ -444,13 +543,83 @@ public function getUniverseKills(): array{ return $systemKills; } + /** + * @return array + */ + public function getUniverseCategories() : array { + $url = $this->getEndpointURL(['universe', 'categories', 'list', 'GET']); + $categoryData = []; + $response = $this->request($url, 'GET'); + + if( !empty($response) ){ + $categoryData = array_unique( array_map('intval', $response) ); + } + + return $categoryData; + } + + /** + * @param int $categoryId + * @return array + */ + public function getUniverseCategoryData(int $categoryId) : array { + $url = $this->getEndpointURL(['universe', 'categories', 'GET'], [$categoryId]); + $categoryData = []; + + $response = $this->request($url, 'GET'); + + if( !empty($response) ){ + $categoryData = (new namespace\Mapper\Universe\Category($response))->getData(); + if( !empty($categoryData) ){ + $categoryData['id'] = $categoryId; + } + } + + return $categoryData; + } + + /** + * @return array + */ + public function getUniverseGroups() : array { + $url = $this->getEndpointURL(['universe', 'groups', 'list', 'GET']); + $groupData = []; + $response = $this->request($url, 'GET'); + + if( !empty($response) ){ + $groupData = array_unique( array_map('intval', $response) ); + } + + return $groupData; + } + + /** + * @param int $groupId + * @return array + */ + public function getUniverseGroupData(int $groupId) : array { + $url = $this->getEndpointURL(['universe', 'groups', 'GET'], [$groupId]); + $groupData = []; + + $response = $this->request($url, 'GET'); + + if( !empty($response) ){ + $groupData = (new namespace\Mapper\Universe\Group($response))->getData(); + if( !empty($groupData) ){ + $groupData['id'] = $groupId; + } + } + + return $groupData; + } + /** * @param int $structureId * @param string $accessToken * @param array $additionalOptions * @return array */ - public function getUniverseStructureData(int $structureId, string $accessToken, array $additionalOptions = []): array { + public function getUniverseStructureData(int $structureId, string $accessToken, array $additionalOptions = []) : array { $url = $this->getEndpointURL(['universe', 'structures', 'GET'], [$structureId]); $structureData = []; @@ -471,7 +640,7 @@ public function getUniverseStructureData(int $structureId, string $accessToken, * @param array $additionalOptions * @return array */ - public function getUniverseTypesData(int $typeId, array $additionalOptions = []): array { + public function getUniverseTypesData(int $typeId, array $additionalOptions = []) : array { $url = $this->getEndpointURL(['universe', 'types', 'GET'], [$typeId]); $typesData = []; $response = $this->request($url, 'GET', '', $additionalOptions); @@ -484,11 +653,78 @@ public function getUniverseTypesData(int $typeId, array $additionalOptions = []) } /** + * @param int $sourceId * @param int $targetId + * @param array $options + * @return array + */ + public function getRouteData(int $sourceId, int $targetId, array $options = []) : array { + $urlParams = []; + if( !empty($options['avoid']) ){ + $urlParams['avoid'] = $options['avoid']; + } + if( !empty($options['connections']) ){ + $urlParams['connections'] = $options['connections']; + } + if( !empty($options['flag']) ){ + $urlParams['flag'] = $options['flag']; + } + + $urlParams = $this->formatUrlParams($urlParams, [ + 'connections' => [',', '|'], + 'avoid' => [','] + ]); + + $url = $this->getEndpointURL(['routes', 'GET'], [$sourceId, $targetId], $urlParams); + $routeData = []; + $response = $this->request($url, 'GET'); + + if($response->error){ + $routeData['error'] = $response->error; + }else{ + $routeData['route'] = array_unique( array_map('intval', $response) ); + } + + return $routeData; + } + + /** + * @param int $systemId * @param string $accessToken + * @param array $options * @return array */ - public function openWindow(int $targetId, string $accessToken): array{ + public function setWaypoint(int $systemId, string $accessToken, array $options = []) : array { + $urlParams = [ + 'add_to_beginning' => var_export( (bool)$options['addToBeginning'], true), + 'clear_other_waypoints' => var_export( (bool)$options['clearOtherWaypoints'], true), + 'destination_id' => $systemId + ]; + + $url = $this->getEndpointURL(['ui', 'autopilot', 'waypoint', 'POST'], [], $urlParams); + $waypointData = []; + + // need to be send in "content" vars as well! Otherwise "Content-Length" header is not send + $additionalOptions = [ + 'content' => $urlParams + ]; + + $response = $this->request($url, 'POST', $accessToken, $additionalOptions); + + // "null" === success => There is no response body send... + if( !is_null($response) ){ + $waypointData['error'] = self::ERROR_ESI_WAYPOINT; + } + + return $waypointData; + } + + /** + * @param int $targetId + * @param string $accessToken + * @return array + */ + public function openWindow(int $targetId, string $accessToken) : array { $urlParams = [ 'target_id' => $targetId ]; @@ -512,46 +748,41 @@ public function openWindow(int $targetId, string $accessToken): array{ } /** - * @param int $sourceId - * @param int $targetId - * @param array $options + * @param array $categories + * @param string $search + * @param bool $strict * @return array */ - public function getRouteData(int $sourceId, int $targetId, array $options = []): array { - $urlParams = []; - if( !empty($options['avoid']) ){ - $urlParams['avoid'] = $options['avoid']; - } - if( !empty($options['connections']) ){ - $urlParams['connections'] = $options['connections']; - } - if( !empty($options['flag']) ){ - $urlParams['flag'] = $options['flag']; - } + public function search(array $categories, string $search, bool $strict = false) : array { + $urlParams = [ + 'categories' => $categories, + 'search' => $search, + 'strict' => var_export( (bool)$strict, true), + ]; $urlParams = $this->formatUrlParams($urlParams, [ - 'connections' => [',', '|'], - 'avoid' => [','] + 'categories' => [','] ]); - $url = $this->getEndpointURL(['routes', 'GET'], [$sourceId, $targetId], $urlParams); - $routeData = []; + $url = $this->getEndpointURL(['search', 'GET'], [], $urlParams); + + $searchData = []; $response = $this->request($url, 'GET'); if($response->error){ - $routeData['error'] = $response->error; - }else{ - $routeData['route'] = array_unique( array_map('intval', $response) ); + $searchData['error'] = $response->error; + }elseif( !empty($response) ){ + $searchData = (new namespace\Mapper\Search($response))->getData(); } - return $routeData; + return $searchData; } /** * @param int $corporationId * @return bool */ - public function isNpcCorporation(int $corporationId): bool{ + public function isNpcCorporation(int $corporationId) : bool { $npcCorporations = $this->getNpcCorporations(); return in_array($corporationId, $npcCorporations); } @@ -559,7 +790,7 @@ public function isNpcCorporation(int $corporationId): bool{ /** * @return array */ - protected function getNpcCorporations(): array{ + protected function getNpcCorporations() : array { $url = $this->getEndpointURL(['corporations', 'npccorps', 'GET']); $npcCorporations = []; $response = $this->request($url, 'GET'); @@ -597,7 +828,7 @@ protected function formatUrlParams(array $urlParams = [], array $format = []) : * @param array $params * @return string */ - protected function getEndpointURL(array $path = [], array $placeholders = [], array $params = []): string{ + protected function getEndpointURL(array $path = [], array $placeholders = [], array $params = []) : string { $url = $this->getUrl() . Config\ESIConf::getEndpoint($path, $placeholders); // add "datasource" parameter (SISI, TQ) (optional) @@ -628,7 +859,7 @@ protected function request(string $url, string $method = 'GET', string $accessTo $responseBody = null; $method = strtoupper($method); - $webClient = namespace\Lib\WebClient::instance($this->getDebugLevel()); + $webClient = namespace\Lib\WebClient::instance($this->getDebugLevel(), $this->getDebugLogRequests()); if( \Audit::instance()->url($url) ){ // check if url is blocked (error limit exceeded) @@ -639,7 +870,8 @@ protected function request(string $url, string $method = 'GET', string $accessTo 'method' => $method, 'user_agent' => $this->getUserAgent(), 'header' => [ - 'Accept: application/json' + 'Accept: application/json', + 'Expect:' ] ]; diff --git a/app/Lib/WebClient.php b/app/Lib/WebClient.php index 2241e87..46de4f2 100644 --- a/app/Lib/WebClient.php +++ b/app/Lib/WebClient.php @@ -9,6 +9,8 @@ namespace Exodus4D\ESI\Lib; +use Exodus4D\ESI\ESI; + class WebClient extends \Web { const CACHE_KEY_ERROR_LIMIT = 'CACHED_ERROR_LIMIT'; @@ -20,6 +22,7 @@ class WebClient extends \Web { const ERROR_LIMIT_CRITICAL = 'Error rate reached critical amount. url: \'%s\' | errorCount: %s | errorRemainCount: %s'; const ERROR_LIMIT_EXCEEDED = 'Error rate limit exceeded! We are blocked for (%s seconds)'; const DEBUG_URI_BLOCKED = 'Debug request blocked. Error limit exceeded. url: \'%s\' blocked for %2ss'; + const DEBUG_REQUEST = 'Debug request. url: \'%s\' data: %s'; const REQUEST_METHODS = ['GET', 'POST', 'PUT', 'DELETE']; @@ -51,10 +54,17 @@ class WebClient extends \Web { * debugLevel used for internal error/warning logging * @var int */ - protected $debugLevel = 0; + protected $debugLevel = ESI::DEFAULT_DEBUG_LEVEL; + + /** + * if true any ESI requests gets logged in log file + * @var bool + */ + protected $debugLogRequests = ESI::DEFAULT_DEBUG_LOG_REQUESTS; - public function __construct(int $debugLevel = 0){ + public function __construct(int $debugLevel = ESI::DEFAULT_DEBUG_LEVEL, bool $debugLogRequests = ESI::DEFAULT_DEBUG_LOG_REQUESTS){ $this->debugLevel = $debugLevel; + $this->debugLogRequests = $debugLogRequests; } /** @@ -149,6 +159,9 @@ public function getLogger(string $statusType): \Log{ case 'resource_deprecated': $logfile = 'esi_resource_deprecated'; break; + case 'debug_request': + $logfile = 'esi_debug_request'; + break; default: $logfile = 'esi_error_unknown'; } @@ -320,6 +333,17 @@ public function isBlockedUrl(string $url): bool { return $isBlocked; } + /** + * write request information into logfile + * @param string $url + * @param $response + */ + protected function logRequest(string $url, $response){ + if($this->debugLogRequests){ + $this->getLogger('debug_request')->write(sprintf(self::DEBUG_REQUEST, $url, print_r($response, true))); + } + } + /** * @param string $url * @param array|null $options @@ -333,6 +357,8 @@ public function request( $url, array $options = null, $additionalOptions = [], $ $response = parent::request($url, $options); + $this->logRequest($url, $response); + $responseHeaders = (array)$response['headers']; $responseBody = json_decode($response['body']); diff --git a/app/Mapper/Alliance.php b/app/Mapper/Alliance.php index 653bf1d..7def7e5 100644 --- a/app/Mapper/Alliance.php +++ b/app/Mapper/Alliance.php @@ -13,6 +13,8 @@ class Alliance extends mapper\AbstractIterator { protected static $map = [ - 'name' => 'name' + 'id' => 'id', + 'name' => 'name', + 'ticker' => 'ticker' ]; } \ No newline at end of file diff --git a/app/Mapper/Character.php b/app/Mapper/Character.php index a343e42..3a666ba 100644 --- a/app/Mapper/Character.php +++ b/app/Mapper/Character.php @@ -14,6 +14,7 @@ class Character extends mapper\AbstractIterator { protected static $map = [ + 'id' => 'id', 'name' => 'name', 'birthday' => 'birthday', 'gender' => 'gender', diff --git a/app/Mapper/Corporation.php b/app/Mapper/Corporation.php index 9f17d03..943f38c 100644 --- a/app/Mapper/Corporation.php +++ b/app/Mapper/Corporation.php @@ -13,6 +13,9 @@ class Corporation extends mapper\AbstractIterator { protected static $map = [ - 'name' => 'name' + 'id' => 'id', + 'name' => 'name', + 'member_count' => 'memberCount', + 'ticker' => 'ticker' ]; } \ No newline at end of file diff --git a/app/Mapper/InventoryType.php b/app/Mapper/InventoryType.php index 114fb68..97196c4 100644 --- a/app/Mapper/InventoryType.php +++ b/app/Mapper/InventoryType.php @@ -13,7 +13,7 @@ class InventoryType extends mapper\AbstractIterator { protected static $map = [ - 'id' => ['ship' => 'typeId'], - 'name' => ['ship' => 'typeName'] + 'id' => 'id', + 'name' => 'name' ]; } \ No newline at end of file diff --git a/app/Mapper/Search.php b/app/Mapper/Search.php new file mode 100644 index 0000000..4a41de9 --- /dev/null +++ b/app/Mapper/Search.php @@ -0,0 +1,27 @@ + 'agent', + 'alliance' => 'alliance', + 'character' => 'character', + 'constellation' => 'constellation', + 'corporation' => 'corporation', + 'faction' => 'faction', + 'inventory_type' => 'inventoryType', + 'region' => 'region', + 'solar_system' => 'solarSystem', + 'station' => 'station' + ]; +} \ No newline at end of file diff --git a/app/Mapper/Station.php b/app/Mapper/Station.php index 13c4fee..a3580e3 100644 --- a/app/Mapper/Station.php +++ b/app/Mapper/Station.php @@ -13,7 +13,7 @@ class Station extends mapper\AbstractIterator { protected static $map = [ - 'id' => ['station' => 'id'], - 'name' => ['station' => 'name'] + 'id' => 'id', + 'name' => 'name' ]; } \ No newline at end of file diff --git a/app/Mapper/System.php b/app/Mapper/System.php index 716dc3c..b77d6ea 100644 --- a/app/Mapper/System.php +++ b/app/Mapper/System.php @@ -13,8 +13,21 @@ class System extends mapper\AbstractIterator { protected static $map = [ - 'id' => ['system' => 'id'], - - 'name' => ['system' => 'name'] + 'id' => 'id', + 'system_id' => 'id', + 'name' => 'name', + 'constellation_id' => 'constellationId', + 'security_class' => 'securityClass', + 'security_status' => 'securityStatus', + 'star_id' => 'starId', + 'planets' => 'planets', + 'planet_id' => 'planetId', + 'moons' => 'moons', + 'asteroid_belts' => 'asteroidBelts', + 'stargates' => 'stargates', + 'position' => 'position', + 'x' => 'x', + 'y' => 'y', + 'z' => 'z' ]; } \ No newline at end of file diff --git a/app/Mapper/Universe/Category.php b/app/Mapper/Universe/Category.php new file mode 100644 index 0000000..00bd141 --- /dev/null +++ b/app/Mapper/Universe/Category.php @@ -0,0 +1,20 @@ + 'name', + 'published' => 'published', + 'groups' => 'groups' + ]; +} \ No newline at end of file diff --git a/app/Mapper/Universe/Group.php b/app/Mapper/Universe/Group.php new file mode 100644 index 0000000..9bbd021 --- /dev/null +++ b/app/Mapper/Universe/Group.php @@ -0,0 +1,21 @@ + 'name', + 'published' => 'published', + 'category_id' => 'categoryId', + 'types' => 'types' + ]; +} \ No newline at end of file diff --git a/app/Mapper/Universe/Planet.php b/app/Mapper/Universe/Planet.php new file mode 100644 index 0000000..ea1366e --- /dev/null +++ b/app/Mapper/Universe/Planet.php @@ -0,0 +1,25 @@ + 'id', + 'name' => 'name', + 'system_id' => 'systemId', + 'type_id' => 'typeId', + 'position' => 'position', + 'x' => 'x', + 'y' => 'y', + 'z' => 'z' + ]; +} \ No newline at end of file diff --git a/app/Mapper/Universe/Star.php b/app/Mapper/Universe/Star.php new file mode 100644 index 0000000..df25658 --- /dev/null +++ b/app/Mapper/Universe/Star.php @@ -0,0 +1,24 @@ + 'name', + 'type_id' => 'typeId', + 'age' => 'age', + 'luminosity' => 'luminosity', + 'radius' => 'radius', + 'spectral_class' => 'spectralClass', + 'temperature' => 'temperature' + ]; +} \ No newline at end of file diff --git a/app/Mapper/Universe/Stargate.php b/app/Mapper/Universe/Stargate.php new file mode 100644 index 0000000..b2a4938 --- /dev/null +++ b/app/Mapper/Universe/Stargate.php @@ -0,0 +1,26 @@ + 'id', + 'name' => 'name', + 'system_id' => 'systemId', + 'type_id' => 'typeId', + 'destination' => 'destination', + 'position' => 'position', + 'x' => 'x', + 'y' => 'y', + 'z' => 'z' + ]; +} \ No newline at end of file diff --git a/app/Mapper/Universe/Structure.php b/app/Mapper/Universe/Structure.php index 0476fe0..85cd59b 100644 --- a/app/Mapper/Universe/Structure.php +++ b/app/Mapper/Universe/Structure.php @@ -16,6 +16,7 @@ class Structure extends mapper\AbstractIterator { 'name' => 'name', 'solar_system_id' => 'systemId', 'type_id' => 'typeId', + 'owner_id' => 'ownerId', 'position' => 'position', 'x' => 'x', 'y' => 'y',